nsd-ble 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Data as L, DataType as z, Button as N } from "./enums.js";
2
- let F = !1, V = [], D, re, T = /* @__PURE__ */ new Map();
2
+ let F = !1, B = [], D, re, T = /* @__PURE__ */ new Map();
3
3
  async function le(a) {
4
4
  try {
5
5
  if (D = await navigator.bluetooth.requestDevice(a), D.gatt === void 0)
@@ -10,13 +10,13 @@ async function le(a) {
10
10
  }
11
11
  }
12
12
  function fe() {
13
- T.clear(), F = !1, V.forEach((a) => a());
13
+ T.clear(), F = !1, B.forEach((a) => a());
14
14
  }
15
15
  function ve(a) {
16
- V.push(a);
16
+ B.push(a);
17
17
  }
18
18
  function de(a) {
19
- V = V.filter((h) => h !== a);
19
+ B = B.filter((h) => h !== a);
20
20
  }
21
21
  async function H(a, h) {
22
22
  if (T.has(h)) {
@@ -71,7 +71,7 @@ function Ce() {
71
71
  };
72
72
  }
73
73
  var m = {}, q = {}, J;
74
- function B() {
74
+ function V() {
75
75
  if (J) return q;
76
76
  J = 1, Object.defineProperty(q, "__esModule", { value: !0 }), q.BaseEvent = void 0;
77
77
  var a = (
@@ -156,7 +156,7 @@ function j() {
156
156
  };
157
157
  })();
158
158
  Object.defineProperty(E, "__esModule", { value: !0 }), E.ErrorSyncEvent = E.VoidSyncEvent = E.SyncEvent = void 0;
159
- var h = B(), r = (
159
+ var h = V(), r = (
160
160
  /** @class */
161
161
  (function(l) {
162
162
  a(u, l);
@@ -294,7 +294,7 @@ function ie() {
294
294
  };
295
295
  })();
296
296
  Object.defineProperty(w, "__esModule", { value: !0 }), w.ErrorQueuedEvent = w.VoidQueuedEvent = w.QueuedEvent = void 0;
297
- var h = B(), r = I(), c = j(), d = (
297
+ var h = V(), r = I(), c = j(), d = (
298
298
  /** @class */
299
299
  (function(i) {
300
300
  a(s, i);
@@ -399,7 +399,7 @@ function oe() {
399
399
  };
400
400
  })();
401
401
  Object.defineProperty(b, "__esModule", { value: !0 }), b.ErrorAsyncEvent = b.VoidAsyncEvent = b.AsyncEvent = void 0;
402
- var h = B(), r = j(), c = (
402
+ var h = V(), r = j(), c = (
403
403
  /** @class */
404
404
  (function(u) {
405
405
  a(i, u);
@@ -714,7 +714,7 @@ function Se() {
714
714
  })), r = m && m.__exportStar || function(s, o) {
715
715
  for (var t in s) t !== "default" && !o.hasOwnProperty(t) && h(o, s, t);
716
716
  };
717
- Object.defineProperty(a, "__esModule", { value: !0 }), a.flush = a.flushOnce = a.queue = void 0, r(B(), a), r(j(), a), r(ie(), a), r(oe(), a), r(Ae(), a);
717
+ Object.defineProperty(a, "__esModule", { value: !0 }), a.flush = a.flushOnce = a.queue = void 0, r(V(), a), r(j(), a), r(ie(), a), r(oe(), a), r(Ae(), a);
718
718
  var c = I(), d = I();
719
719
  Object.defineProperty(a, "EventQueue", { enumerable: !0, get: function() {
720
720
  return d.default;
@@ -761,10 +761,16 @@ function Qe(a) {
761
761
  const h = a.buffer, r = 7, c = a.byteLength - 7;
762
762
  return Array.from(new Uint8Array(h, r, c)).map((d) => String.fromCharCode(d)).join("").replace(/\0/g, "").trim();
763
763
  }
764
- function Ve() {
765
- return { subscribe: Le, onPlus: ue, onMin: ae, onEither: ce, onMessageDone: he };
764
+ function Be() {
765
+ return {
766
+ subscribe: Le,
767
+ onPlusButton: ue,
768
+ onMinButton: ae,
769
+ onEitherButton: ce,
770
+ onMessageDone: he
771
+ };
766
772
  }
767
- class Be {
773
+ class Ve {
768
774
  id;
769
775
  elements = [];
770
776
  onPlus = new A.SyncEvent();
@@ -778,9 +784,9 @@ class Be {
778
784
  }
779
785
  export {
780
786
  qe as B,
781
- Be as S,
787
+ Ve as S,
782
788
  Ce as a,
783
- Ve as b,
789
+ Be as b,
784
790
  A as l,
785
791
  _e as u
786
792
  };
@@ -1 +1 @@
1
- "use strict";const m=require("./enums.cjs");let I=!1,B=[],j,te,T=new Map;async function fe(a){try{if(j=await navigator.bluetooth.requestDevice(a),j.gatt===void 0)throw new Error("Device does not support GATT");te=await j.gatt.connect(),j.addEventListener("gattserverdisconnected",ve),I=!0}catch(h){throw h}}function ve(){T.clear(),I=!1,B.forEach(a=>a())}function de(a){B.push(a)}function ye(a){B=B.filter(h=>h!==a)}async function F(a,h){if(T.has(h)){const d=T.get(h);if(d===void 0)throw new Error("Characteristic not found");return d}const c=await(await te.getPrimaryService(a)).getCharacteristic(h);return T.set(h,c),c}async function pe(a,h){return await(await F(a,h)).readValue()}async function ge(a,h,r){const c=new DataView(new ArrayBuffer(r.length));for(let l=0;l<r.length;l++)c.setUint8(l,r[l]);await(await F(a,h)).writeValue(c)}async function _e(a,h,r){const c=await F(a,h);c.addEventListener("characteristicvaluechanged",d=>{let l=d.target.value;l===void 0&&(l=new DataView(new ArrayBuffer(0))),r(l)}),await c.startNotifications()}function ne(){return{connected:I,connect:fe,readCharacteristic:pe,writeCharacteristic:ge,subscribe:_e,setDisconnectCallback:de,removeDisconnectCallback:ye}}const re="19b10000-e8f2-537e-4f6c-d104768a1214",Ee="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",we="998ff920-81af-42a9-a915-f88025f9647d",be={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[re]};function se(){return{serviceUuid:re,messageCharUuid:Ee,handshakeCharUuid:we,options:be}}var S={},O={},Y;function V(){if(Y)return O;Y=1,Object.defineProperty(O,"__esModule",{value:!0}),O.BaseEvent=void 0;var a=(function(){function h(){}return h.prototype.attach=function(r,c){return this._attach(r,c,!1)},h.prototype.once=function(r,c){return this._attach(r,c,!0)},h.prototype._attach=function(r,c,d){var l=this,u,i,s,o;if(typeof r=="function")i=r,o=function(){return l.detach(i)};else if(!c&&typeof r.post=="function")s=r,o=function(){return l.detach(s)};else{if(typeof r!="object"||r===void 0)throw new Error("Expect a function or object as first argument");if(typeof c!="function")throw new Error("Expect a function as second argument");u=r,i=c,o=function(){return l.detach(u,i)}}return this._listeners?this._listeners=this._listeners.slice():this._listeners=[],this._listeners.push({deleted:!1,boundTo:u,handler:i,event:s,once:d}),o},h.prototype.detach=function(){for(var r=[],c=0;c<arguments.length;c++)r[c]=arguments[c];this._detach.apply(this,r)},h.prototype._detach=function(){for(var r=[],c=0;c<arguments.length;c++)r[c]=arguments[c];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(i){return(typeof l>"u"||i.handler===l)&&(typeof u>"u"||i.event===u)&&(typeof d>"u"||i.boundTo===d)?(i.deleted=!0,!1):!0}),this._listeners.length===0&&delete this._listeners}},h.prototype.post=function(r){throw new Error("abstract")},h.prototype.listenerCount=function(){return this._listeners?this._listeners.length:0},h.prototype._call=function(r,c){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,c):r.handler&&r.handler.apply(typeof r.boundTo=="object"?r.boundTo:this,c)))},h})();return O.BaseEvent=a,O}var E={},z;function L(){if(z)return E;z=1;var a=E&&E.__extends||(function(){var l=function(u,i){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,o){s.__proto__=o}||function(s,o){for(var t in o)o.hasOwnProperty(t)&&(s[t]=o[t])},l(u,i)};return function(u,i){l(u,i);function s(){this.constructor=u}u.prototype=i===null?Object.create(i):(s.prototype=i.prototype,new s)}})();Object.defineProperty(E,"__esModule",{value:!0}),E.ErrorSyncEvent=E.VoidSyncEvent=E.SyncEvent=void 0;var h=V(),r=(function(l){a(u,l);function u(){var i=l!==null&&l.apply(this,arguments)||this;return i._recursion=0,i}return Object.defineProperty(u.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new c),this._listenersChanged},enumerable:!1,configurable:!0}),u.prototype.post=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];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 o=this._listeners,t=0;t<o.length;++t){var e=o[t];this._call(e,i)}this._recursion--}},u.prototype._attach=function(i,s,o){var t,e,n,f,v=(e=(t=this._listeners)===null||t===void 0?void 0:t.length)!==null&&e!==void 0?e:0,y=l.prototype._attach.call(this,i,s,o);return this.evtListenersChanged&&v!==((f=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&f!==void 0?f:0)&&this.evtListenersChanged.post(),y},u.prototype._detach=function(){for(var i,s,o,t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var f=(s=(i=this._listeners)===null||i===void 0?void 0:i.length)!==null&&s!==void 0?s:0,v=l.prototype._detach.apply(this,e);return this.evtListenersChanged&&f!==((t=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&t!==void 0?t:0)&&this.evtListenersChanged.post(),v},u.MAX_RECURSION_DEPTH=10,u})(h.BaseEvent);E.SyncEvent=r;var c=(function(l){a(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=c;var d=(function(l){a(u,l);function u(){return l!==null&&l.apply(this,arguments)||this}return u.prototype.post=function(i){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+i.message);l.prototype.post.call(this,i)},u})(r);return E.ErrorSyncEvent=d,E}var w={},Q={},J;function N(){if(J)return Q;J=1,Object.defineProperty(Q,"__esModule",{value:!0});var a=L(),h=(function(){function r(){this.evtFilled=new a.SyncEvent,this.evtDrained=new a.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(c){this._queue.push(c),this._queue.length===1&&!this._flushing&&this.evtFilled.post(this)},r.prototype.flushOnce=function(){var c=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,!c&&!d&&this._queue.length===0&&this.evtDrained.post(this)}},r.prototype.flush=function(c){c===void 0&&(c=10);var d=this._queue.length===0,l=this._flushing;this._flushing=!0;try{for(var u=0;this._queue.length>0;){if(typeof c=="number"&&u>=c)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 Q.default=h,Q}var K;function ie(){if(K)return w;K=1;var a=w&&w.__extends||(function(){var i=function(s,o){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},i(s,o)};return function(s,o){i(s,o);function t(){this.constructor=s}s.prototype=o===null?Object.create(o):(t.prototype=o.prototype,new t)}})();Object.defineProperty(w,"__esModule",{value:!0}),w.ErrorQueuedEvent=w.VoidQueuedEvent=w.QueuedEvent=void 0;var h=V(),r=N(),c=L(),d=(function(i){a(s,i);function s(o){o===void 0&&(o={});var t=i.call(this)||this;return t._queued=!1,t.options=o,typeof o.condensed=="boolean"?t._condensed=o.condensed:t._condensed=!1,typeof o.queue=="object"&&o.queue!==null&&(t._queue=o.queue),t}return Object.defineProperty(s.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new c.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),s.prototype.post=function(){for(var o=this,t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!(!this._listeners||this._listeners.length===0)){var n=this._queue?this._queue:r.default.global();if(this._condensed){if(this._queuedData=t,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,n.add(function(){o._queued=!1;for(var v=o._queuedData,y=o._queuedListeners,p=0;p<y.length;++p){var g=y[p];o._call(g,v)}})}else{var f=this._listeners;n.add(function(){for(var v=0;v<f.length;++v){var y=f[v];o._call(y,t)}})}}},s.prototype._attach=function(o,t,e){var n,f,v,y,p=(f=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&f!==void 0?f:0,g=i.prototype._attach.call(this,o,t,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},s.prototype._detach=function(){for(var o,t,e,n,f=[],v=0;v<arguments.length;v++)f[v]=arguments[v];var y=(t=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&t!==void 0?t:0,p=i.prototype._detach.apply(this,f);return this.evtListenersChanged&&y!==((n=(e=this._listeners)===null||e===void 0?void 0:e.length)!==null&&n!==void 0?n:0)&&this.evtListenersChanged.post(),p},s})(h.BaseEvent);w.QueuedEvent=d;var l=(function(i){a(s,i);function s(){return i!==null&&i.apply(this,arguments)||this}return s.prototype.post=function(){i.prototype.post.call(this,void 0)},s})(d);w.VoidQueuedEvent=l;var u=(function(i){a(s,i);function s(){return i!==null&&i.apply(this,arguments)||this}return s.prototype.post=function(o){if(!this._listeners||this._listeners.length===0)throw new Error("error event posted while no listeners attached. Error: "+o.message);i.prototype.post.call(this,o)},s})(d);return w.ErrorQueuedEvent=u,w}var b={},W;function oe(){if(W)return b;W=1;var a=b&&b.__extends||(function(){var u=function(i,s){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,t){o.__proto__=t}||function(o,t){for(var e in t)t.hasOwnProperty(e)&&(o[e]=t[e])},u(i,s)};return function(i,s){u(i,s);function o(){this.constructor=i}i.prototype=s===null?Object.create(s):(o.prototype=s.prototype,new o)}})();Object.defineProperty(b,"__esModule",{value:!0}),b.ErrorAsyncEvent=b.VoidAsyncEvent=b.AsyncEvent=void 0;var h=V(),r=L(),c=(function(u){a(i,u);function i(s){s===void 0&&(s={});var o=u.call(this)||this;return o._queued=!1,o.options=s,typeof s.condensed=="boolean"?o._condensed=s.condensed:o._condensed=!1,o}return Object.defineProperty(i.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new r.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),i.defaultScheduler=function(s){typeof window<"u"?setTimeout(s,0):setImmediate(s)},i.setScheduler=function(s){i._scheduler=s},i.prototype.post=function(){for(var s=this,o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];if(!(!this._listeners||this._listeners.length===0))if(this._condensed){if(this._queuedData=o,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,i._scheduler(function(){s._queued=!1;for(var n=s._queuedData,f=s._queuedListeners,v=0;v<f.length;++v){var y=f[v];s._call(y,n)}})}else{var e=this._listeners;i._scheduler(function(){for(var n=0;n<e.length;++n){var f=e[n];s._call(f,o)}})}},i.prototype._call=function(s,o){s.event&&s.event instanceof i?s.event._postDirect(o):u.prototype._call.call(this,s,o)},i.prototype._postDirect=function(s){if(!(!this._listeners||this._listeners.length===0))for(var o=this._listeners,t=0;t<o.length;++t){var e=o[t];this._call(e,s)}},i.prototype._attach=function(s,o,t){var e,n,f,v,y=(n=(e=this._listeners)===null||e===void 0?void 0:e.length)!==null&&n!==void 0?n:0,p=u.prototype._attach.call(this,s,o,t);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},i.prototype._detach=function(){for(var s,o,t,e,n=[],f=0;f<arguments.length;f++)n[f]=arguments[f];var v=(o=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&o!==void 0?o:0,y=u.prototype._detach.apply(this,n);return this.evtListenersChanged&&v!==((e=(t=this._listeners)===null||t===void 0?void 0:t.length)!==null&&e!==void 0?e:0)&&this.evtListenersChanged.post(),y},i._scheduler=i.defaultScheduler,i})(h.BaseEvent);b.AsyncEvent=c;var d=(function(u){a(i,u);function i(){return u!==null&&u.apply(this,arguments)||this}return i.prototype.post=function(){u.prototype.post.call(this,void 0)},i})(c);b.VoidAsyncEvent=d;var l=(function(u){a(i,u);function i(){return u!==null&&u.apply(this,arguments)||this}return i.prototype.post=function(s){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+s.message);u.prototype.post.call(this,s)},i})(c);return b.ErrorAsyncEvent=l,b}var D={},P={},Z;function Ce(){if(Z)return P;Z=1,Object.defineProperty(P,"__esModule",{value:!0}),P.shallowEquals=void 0;function a(h,r){if(h===r)return!0;if(typeof h!=typeof r)return!1;switch(typeof h){case"boolean":case"number":case"string":case"function":case"symbol":case"undefined":return!1;case"object":if(h===null||r===null)return!1;if(Array.isArray(h)||Array.isArray(r)){if(!Array.isArray(h)||!Array.isArray(r)||h.length!==r.length)return!1;for(var c=0;c<h.length;++c)if(h[c]!==r[c])return!1;return!0}var d=[],l=[];for(var u in h)h.hasOwnProperty(u)&&d.push(u);for(var i in r)r.hasOwnProperty(i)&&l.push(i);if(d.sort(),l.sort(),d.join(",")!==l.join(","))return!1;for(var c=0;c<d.length;++c)if(h[d[c]]!==r[d[c]])return!1;return!0;default:return!1}}return P.shallowEquals=a,P}var x;function me(){return x||(x=1,(function(a){var h=D&&D.__extends||(function(){var t=function(e,n){return t=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])},t(e,n)};return function(e,n){t(e,n);function f(){this.constructor=e}e.prototype=n===null?Object.create(n):(f.prototype=n.prototype,new f)}})();Object.defineProperty(a,"__esModule",{value:!0}),a.ErrorAnyEvent=a.VoidAnyEvent=a.AnyEvent=a.EventType=void 0;var r=Ce(),c=L(),d=oe(),l=ie(),u;(function(t){t[t.Sync=0]="Sync",t[t.Async=1]="Async",t[t.Queued=2]="Queued"})(u=a.EventType||(a.EventType={}));var i=(function(){function t(e){this._events=[],e&&e.monitorAttach&&(this.evtFirstAttached=new s,this.evtLastDetached=new s)}return Object.defineProperty(t.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new c.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),t.prototype.attach=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];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)},t.prototype.once=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];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)},t.prototype._attach=function(e,n,f,v,y,p){var g=this,H=this.evtFirstAttached?this.listenerCount():0,_;switch(e){case u.Sync:{for(var M=0,X=this._events;M<X.length;M++){var C=X[M];C instanceof c.SyncEvent&&(_=C)}_||(_=new c.SyncEvent,this._events.push(_))}break;case u.Async:{for(var U=0,G=this._events;U<G.length;U++){var C=G[U];C instanceof d.AsyncEvent&&r.shallowEquals(C.options,y)&&(_=C)}_||(_=new d.AsyncEvent(y),this._events.push(_))}break;case u.Queued:{for(var R=0,$=this._events;R<$.length;R++){var C=$[R];C instanceof l.QueuedEvent&&r.shallowEquals(C.options,y)&&(_=C)}_||(_=new l.QueuedEvent(y),this._events.push(_))}break;default:throw new Error("unknown EventType")}var q;return p?v?q=_.once(v):q=_.once(n,f):v?q=_.attach(v):q=_.attach(n,f),this.evtFirstAttached&&H===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&H!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var k=g.evtLastDetached?g.listenerCount():0;q(),g.evtLastDetached&&k>0&&g.listenerCount()===0&&g.evtLastDetached.post(),g.evtListenersChanged&&k!==g.listenerCount()&&g.evtListenersChanged.post()}},t.prototype.attachSync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Sync),this.attach.apply(this,e)},t.prototype.onceSync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Sync),this.once.apply(this,e)},t.prototype.attachAsync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Async),this.attach.apply(this,e)},t.prototype.onceAsync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Async),this.once.apply(this,e)},t.prototype.attachQueued=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Queued),this.attach.apply(this,e)},t.prototype.onceQueued=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Queued),this.once.apply(this,e)},t.prototype.detach=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];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()},t.prototype.post=function(e){for(var n=[],f=0;f<this._events.length;++f)n.push(this._events[f]);for(var f=0;f<n.length;++f)n[f].post(e)},t.prototype.listenerCount=function(){for(var e=0,n=0;n<this._events.length;++n)e+=this._events[n].listenerCount();return e},t})();a.AnyEvent=i;var s=(function(t){h(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e.prototype.post=function(){t.prototype.post.call(this,void 0)},e})(i);a.VoidAnyEvent=s;var o=(function(t){h(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e.prototype.post=function(n){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+n.message);t.prototype.post.call(this,n)},e})(i);a.ErrorAnyEvent=o})(D)),D}var ee;function Se(){return ee||(ee=1,(function(a){var h=S&&S.__createBinding||(Object.create?(function(s,o,t,e){e===void 0&&(e=t),Object.defineProperty(s,e,{enumerable:!0,get:function(){return o[t]}})}):(function(s,o,t,e){e===void 0&&(e=t),s[e]=o[t]})),r=S&&S.__exportStar||function(s,o){for(var t in s)t!=="default"&&!o.hasOwnProperty(t)&&h(o,s,t)};Object.defineProperty(a,"__esModule",{value:!0}),a.flush=a.flushOnce=a.queue=void 0,r(V(),a),r(L(),a),r(ie(),a),r(oe(),a),r(me(),a);var c=N(),d=N();Object.defineProperty(a,"EventQueue",{enumerable:!0,get:function(){return d.default}});function l(){return c.default.global()}a.queue=l;function u(){c.default.global().flushOnce()}a.flushOnce=u;function i(s){s===void 0&&(s=10),c.default.global().flush(s)}a.flush=i})(S)),S}var A=Se();class ue{id;data;constructor(h,r){this.id=h,this.data=r}}const{serviceUuid:Ae,messageCharUuid:qe}=se(),ae=new A.SyncEvent,ce=new A.SyncEvent,he=new A.SyncEvent,le=new A.SyncEvent;function Oe(){return new Promise((a,h)=>{ne().subscribe(Ae,qe,De).then(()=>a()).catch(r=>h(r))})}function De(a){a!==void 0&&(a.getUint8(m.Data.TYPE)===m.DataType.BUTTON_PRESS&&Pe(a),a.getUint8(m.Data.TYPE)===m.DataType.MESSAGE_DONE&&le.post(a.getUint8(m.Data.DATA)))}function Pe(a){const h=a.getUint8(m.Data.DATA),r=new ue(a.getUint8(m.Data.ID),Le(a));h===m.Button.MINUS&&ce.post(r),h===m.Button.PLUS&&ae.post(r),h===m.Button.EITHER&&he.post(r)}function Le(a){const h=a.buffer,r=7,c=a.byteLength-7;return Array.from(new Uint8Array(h,r,c)).map(d=>String.fromCharCode(d)).join("").replace(/\0/g,"").trim()}function je(){return{subscribe:Oe,onPlus:ae,onMin:ce,onEither:he,onMessageDone:le}}class Qe{id;elements=[];onPlus=new A.SyncEvent;onMin=new A.SyncEvent;constructor(h){this.id=h}name(){return this.id.toString(16).padStart(2,"0")}}exports.ButtonResult=ue;exports.Standee=Qe;exports.libExports=A;exports.useBluetooth=ne;exports.useBluetoothSettings=se;exports.useMessageCharacteristic=je;
1
+ "use strict";const m=require("./enums.cjs");let I=!1,T=[],j,te,B=new Map;async function fe(a){try{if(j=await navigator.bluetooth.requestDevice(a),j.gatt===void 0)throw new Error("Device does not support GATT");te=await j.gatt.connect(),j.addEventListener("gattserverdisconnected",ve),I=!0}catch(h){throw h}}function ve(){B.clear(),I=!1,T.forEach(a=>a())}function de(a){T.push(a)}function ye(a){T=T.filter(h=>h!==a)}async function F(a,h){if(B.has(h)){const d=B.get(h);if(d===void 0)throw new Error("Characteristic not found");return d}const c=await(await te.getPrimaryService(a)).getCharacteristic(h);return B.set(h,c),c}async function pe(a,h){return await(await F(a,h)).readValue()}async function ge(a,h,r){const c=new DataView(new ArrayBuffer(r.length));for(let l=0;l<r.length;l++)c.setUint8(l,r[l]);await(await F(a,h)).writeValue(c)}async function _e(a,h,r){const c=await F(a,h);c.addEventListener("characteristicvaluechanged",d=>{let l=d.target.value;l===void 0&&(l=new DataView(new ArrayBuffer(0))),r(l)}),await c.startNotifications()}function ne(){return{connected:I,connect:fe,readCharacteristic:pe,writeCharacteristic:ge,subscribe:_e,setDisconnectCallback:de,removeDisconnectCallback:ye}}const re="19b10000-e8f2-537e-4f6c-d104768a1214",Ee="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",we="998ff920-81af-42a9-a915-f88025f9647d",be={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[re]};function se(){return{serviceUuid:re,messageCharUuid:Ee,handshakeCharUuid:we,options:be}}var S={},O={},Y;function V(){if(Y)return O;Y=1,Object.defineProperty(O,"__esModule",{value:!0}),O.BaseEvent=void 0;var a=(function(){function h(){}return h.prototype.attach=function(r,c){return this._attach(r,c,!1)},h.prototype.once=function(r,c){return this._attach(r,c,!0)},h.prototype._attach=function(r,c,d){var l=this,u,i,s,o;if(typeof r=="function")i=r,o=function(){return l.detach(i)};else if(!c&&typeof r.post=="function")s=r,o=function(){return l.detach(s)};else{if(typeof r!="object"||r===void 0)throw new Error("Expect a function or object as first argument");if(typeof c!="function")throw new Error("Expect a function as second argument");u=r,i=c,o=function(){return l.detach(u,i)}}return this._listeners?this._listeners=this._listeners.slice():this._listeners=[],this._listeners.push({deleted:!1,boundTo:u,handler:i,event:s,once:d}),o},h.prototype.detach=function(){for(var r=[],c=0;c<arguments.length;c++)r[c]=arguments[c];this._detach.apply(this,r)},h.prototype._detach=function(){for(var r=[],c=0;c<arguments.length;c++)r[c]=arguments[c];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(i){return(typeof l>"u"||i.handler===l)&&(typeof u>"u"||i.event===u)&&(typeof d>"u"||i.boundTo===d)?(i.deleted=!0,!1):!0}),this._listeners.length===0&&delete this._listeners}},h.prototype.post=function(r){throw new Error("abstract")},h.prototype.listenerCount=function(){return this._listeners?this._listeners.length:0},h.prototype._call=function(r,c){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,c):r.handler&&r.handler.apply(typeof r.boundTo=="object"?r.boundTo:this,c)))},h})();return O.BaseEvent=a,O}var E={},z;function L(){if(z)return E;z=1;var a=E&&E.__extends||(function(){var l=function(u,i){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(s,o){s.__proto__=o}||function(s,o){for(var t in o)o.hasOwnProperty(t)&&(s[t]=o[t])},l(u,i)};return function(u,i){l(u,i);function s(){this.constructor=u}u.prototype=i===null?Object.create(i):(s.prototype=i.prototype,new s)}})();Object.defineProperty(E,"__esModule",{value:!0}),E.ErrorSyncEvent=E.VoidSyncEvent=E.SyncEvent=void 0;var h=V(),r=(function(l){a(u,l);function u(){var i=l!==null&&l.apply(this,arguments)||this;return i._recursion=0,i}return Object.defineProperty(u.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new c),this._listenersChanged},enumerable:!1,configurable:!0}),u.prototype.post=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];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 o=this._listeners,t=0;t<o.length;++t){var e=o[t];this._call(e,i)}this._recursion--}},u.prototype._attach=function(i,s,o){var t,e,n,f,v=(e=(t=this._listeners)===null||t===void 0?void 0:t.length)!==null&&e!==void 0?e:0,y=l.prototype._attach.call(this,i,s,o);return this.evtListenersChanged&&v!==((f=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&f!==void 0?f:0)&&this.evtListenersChanged.post(),y},u.prototype._detach=function(){for(var i,s,o,t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var f=(s=(i=this._listeners)===null||i===void 0?void 0:i.length)!==null&&s!==void 0?s:0,v=l.prototype._detach.apply(this,e);return this.evtListenersChanged&&f!==((t=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&t!==void 0?t:0)&&this.evtListenersChanged.post(),v},u.MAX_RECURSION_DEPTH=10,u})(h.BaseEvent);E.SyncEvent=r;var c=(function(l){a(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=c;var d=(function(l){a(u,l);function u(){return l!==null&&l.apply(this,arguments)||this}return u.prototype.post=function(i){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+i.message);l.prototype.post.call(this,i)},u})(r);return E.ErrorSyncEvent=d,E}var w={},Q={},J;function N(){if(J)return Q;J=1,Object.defineProperty(Q,"__esModule",{value:!0});var a=L(),h=(function(){function r(){this.evtFilled=new a.SyncEvent,this.evtDrained=new a.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(c){this._queue.push(c),this._queue.length===1&&!this._flushing&&this.evtFilled.post(this)},r.prototype.flushOnce=function(){var c=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,!c&&!d&&this._queue.length===0&&this.evtDrained.post(this)}},r.prototype.flush=function(c){c===void 0&&(c=10);var d=this._queue.length===0,l=this._flushing;this._flushing=!0;try{for(var u=0;this._queue.length>0;){if(typeof c=="number"&&u>=c)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 Q.default=h,Q}var K;function ie(){if(K)return w;K=1;var a=w&&w.__extends||(function(){var i=function(s,o){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},i(s,o)};return function(s,o){i(s,o);function t(){this.constructor=s}s.prototype=o===null?Object.create(o):(t.prototype=o.prototype,new t)}})();Object.defineProperty(w,"__esModule",{value:!0}),w.ErrorQueuedEvent=w.VoidQueuedEvent=w.QueuedEvent=void 0;var h=V(),r=N(),c=L(),d=(function(i){a(s,i);function s(o){o===void 0&&(o={});var t=i.call(this)||this;return t._queued=!1,t.options=o,typeof o.condensed=="boolean"?t._condensed=o.condensed:t._condensed=!1,typeof o.queue=="object"&&o.queue!==null&&(t._queue=o.queue),t}return Object.defineProperty(s.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new c.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),s.prototype.post=function(){for(var o=this,t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!(!this._listeners||this._listeners.length===0)){var n=this._queue?this._queue:r.default.global();if(this._condensed){if(this._queuedData=t,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,n.add(function(){o._queued=!1;for(var v=o._queuedData,y=o._queuedListeners,p=0;p<y.length;++p){var g=y[p];o._call(g,v)}})}else{var f=this._listeners;n.add(function(){for(var v=0;v<f.length;++v){var y=f[v];o._call(y,t)}})}}},s.prototype._attach=function(o,t,e){var n,f,v,y,p=(f=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&f!==void 0?f:0,g=i.prototype._attach.call(this,o,t,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},s.prototype._detach=function(){for(var o,t,e,n,f=[],v=0;v<arguments.length;v++)f[v]=arguments[v];var y=(t=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&t!==void 0?t:0,p=i.prototype._detach.apply(this,f);return this.evtListenersChanged&&y!==((n=(e=this._listeners)===null||e===void 0?void 0:e.length)!==null&&n!==void 0?n:0)&&this.evtListenersChanged.post(),p},s})(h.BaseEvent);w.QueuedEvent=d;var l=(function(i){a(s,i);function s(){return i!==null&&i.apply(this,arguments)||this}return s.prototype.post=function(){i.prototype.post.call(this,void 0)},s})(d);w.VoidQueuedEvent=l;var u=(function(i){a(s,i);function s(){return i!==null&&i.apply(this,arguments)||this}return s.prototype.post=function(o){if(!this._listeners||this._listeners.length===0)throw new Error("error event posted while no listeners attached. Error: "+o.message);i.prototype.post.call(this,o)},s})(d);return w.ErrorQueuedEvent=u,w}var b={},W;function oe(){if(W)return b;W=1;var a=b&&b.__extends||(function(){var u=function(i,s){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,t){o.__proto__=t}||function(o,t){for(var e in t)t.hasOwnProperty(e)&&(o[e]=t[e])},u(i,s)};return function(i,s){u(i,s);function o(){this.constructor=i}i.prototype=s===null?Object.create(s):(o.prototype=s.prototype,new o)}})();Object.defineProperty(b,"__esModule",{value:!0}),b.ErrorAsyncEvent=b.VoidAsyncEvent=b.AsyncEvent=void 0;var h=V(),r=L(),c=(function(u){a(i,u);function i(s){s===void 0&&(s={});var o=u.call(this)||this;return o._queued=!1,o.options=s,typeof s.condensed=="boolean"?o._condensed=s.condensed:o._condensed=!1,o}return Object.defineProperty(i.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new r.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),i.defaultScheduler=function(s){typeof window<"u"?setTimeout(s,0):setImmediate(s)},i.setScheduler=function(s){i._scheduler=s},i.prototype.post=function(){for(var s=this,o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];if(!(!this._listeners||this._listeners.length===0))if(this._condensed){if(this._queuedData=o,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,i._scheduler(function(){s._queued=!1;for(var n=s._queuedData,f=s._queuedListeners,v=0;v<f.length;++v){var y=f[v];s._call(y,n)}})}else{var e=this._listeners;i._scheduler(function(){for(var n=0;n<e.length;++n){var f=e[n];s._call(f,o)}})}},i.prototype._call=function(s,o){s.event&&s.event instanceof i?s.event._postDirect(o):u.prototype._call.call(this,s,o)},i.prototype._postDirect=function(s){if(!(!this._listeners||this._listeners.length===0))for(var o=this._listeners,t=0;t<o.length;++t){var e=o[t];this._call(e,s)}},i.prototype._attach=function(s,o,t){var e,n,f,v,y=(n=(e=this._listeners)===null||e===void 0?void 0:e.length)!==null&&n!==void 0?n:0,p=u.prototype._attach.call(this,s,o,t);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},i.prototype._detach=function(){for(var s,o,t,e,n=[],f=0;f<arguments.length;f++)n[f]=arguments[f];var v=(o=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&o!==void 0?o:0,y=u.prototype._detach.apply(this,n);return this.evtListenersChanged&&v!==((e=(t=this._listeners)===null||t===void 0?void 0:t.length)!==null&&e!==void 0?e:0)&&this.evtListenersChanged.post(),y},i._scheduler=i.defaultScheduler,i})(h.BaseEvent);b.AsyncEvent=c;var d=(function(u){a(i,u);function i(){return u!==null&&u.apply(this,arguments)||this}return i.prototype.post=function(){u.prototype.post.call(this,void 0)},i})(c);b.VoidAsyncEvent=d;var l=(function(u){a(i,u);function i(){return u!==null&&u.apply(this,arguments)||this}return i.prototype.post=function(s){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+s.message);u.prototype.post.call(this,s)},i})(c);return b.ErrorAsyncEvent=l,b}var D={},P={},Z;function Ce(){if(Z)return P;Z=1,Object.defineProperty(P,"__esModule",{value:!0}),P.shallowEquals=void 0;function a(h,r){if(h===r)return!0;if(typeof h!=typeof r)return!1;switch(typeof h){case"boolean":case"number":case"string":case"function":case"symbol":case"undefined":return!1;case"object":if(h===null||r===null)return!1;if(Array.isArray(h)||Array.isArray(r)){if(!Array.isArray(h)||!Array.isArray(r)||h.length!==r.length)return!1;for(var c=0;c<h.length;++c)if(h[c]!==r[c])return!1;return!0}var d=[],l=[];for(var u in h)h.hasOwnProperty(u)&&d.push(u);for(var i in r)r.hasOwnProperty(i)&&l.push(i);if(d.sort(),l.sort(),d.join(",")!==l.join(","))return!1;for(var c=0;c<d.length;++c)if(h[d[c]]!==r[d[c]])return!1;return!0;default:return!1}}return P.shallowEquals=a,P}var x;function me(){return x||(x=1,(function(a){var h=D&&D.__extends||(function(){var t=function(e,n){return t=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])},t(e,n)};return function(e,n){t(e,n);function f(){this.constructor=e}e.prototype=n===null?Object.create(n):(f.prototype=n.prototype,new f)}})();Object.defineProperty(a,"__esModule",{value:!0}),a.ErrorAnyEvent=a.VoidAnyEvent=a.AnyEvent=a.EventType=void 0;var r=Ce(),c=L(),d=oe(),l=ie(),u;(function(t){t[t.Sync=0]="Sync",t[t.Async=1]="Async",t[t.Queued=2]="Queued"})(u=a.EventType||(a.EventType={}));var i=(function(){function t(e){this._events=[],e&&e.monitorAttach&&(this.evtFirstAttached=new s,this.evtLastDetached=new s)}return Object.defineProperty(t.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new c.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),t.prototype.attach=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];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)},t.prototype.once=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];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)},t.prototype._attach=function(e,n,f,v,y,p){var g=this,H=this.evtFirstAttached?this.listenerCount():0,_;switch(e){case u.Sync:{for(var M=0,X=this._events;M<X.length;M++){var C=X[M];C instanceof c.SyncEvent&&(_=C)}_||(_=new c.SyncEvent,this._events.push(_))}break;case u.Async:{for(var U=0,G=this._events;U<G.length;U++){var C=G[U];C instanceof d.AsyncEvent&&r.shallowEquals(C.options,y)&&(_=C)}_||(_=new d.AsyncEvent(y),this._events.push(_))}break;case u.Queued:{for(var R=0,$=this._events;R<$.length;R++){var C=$[R];C instanceof l.QueuedEvent&&r.shallowEquals(C.options,y)&&(_=C)}_||(_=new l.QueuedEvent(y),this._events.push(_))}break;default:throw new Error("unknown EventType")}var q;return p?v?q=_.once(v):q=_.once(n,f):v?q=_.attach(v):q=_.attach(n,f),this.evtFirstAttached&&H===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&H!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var k=g.evtLastDetached?g.listenerCount():0;q(),g.evtLastDetached&&k>0&&g.listenerCount()===0&&g.evtLastDetached.post(),g.evtListenersChanged&&k!==g.listenerCount()&&g.evtListenersChanged.post()}},t.prototype.attachSync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Sync),this.attach.apply(this,e)},t.prototype.onceSync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Sync),this.once.apply(this,e)},t.prototype.attachAsync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Async),this.attach.apply(this,e)},t.prototype.onceAsync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Async),this.once.apply(this,e)},t.prototype.attachQueued=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Queued),this.attach.apply(this,e)},t.prototype.onceQueued=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.unshift(u.Queued),this.once.apply(this,e)},t.prototype.detach=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];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()},t.prototype.post=function(e){for(var n=[],f=0;f<this._events.length;++f)n.push(this._events[f]);for(var f=0;f<n.length;++f)n[f].post(e)},t.prototype.listenerCount=function(){for(var e=0,n=0;n<this._events.length;++n)e+=this._events[n].listenerCount();return e},t})();a.AnyEvent=i;var s=(function(t){h(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e.prototype.post=function(){t.prototype.post.call(this,void 0)},e})(i);a.VoidAnyEvent=s;var o=(function(t){h(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e.prototype.post=function(n){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+n.message);t.prototype.post.call(this,n)},e})(i);a.ErrorAnyEvent=o})(D)),D}var ee;function Se(){return ee||(ee=1,(function(a){var h=S&&S.__createBinding||(Object.create?(function(s,o,t,e){e===void 0&&(e=t),Object.defineProperty(s,e,{enumerable:!0,get:function(){return o[t]}})}):(function(s,o,t,e){e===void 0&&(e=t),s[e]=o[t]})),r=S&&S.__exportStar||function(s,o){for(var t in s)t!=="default"&&!o.hasOwnProperty(t)&&h(o,s,t)};Object.defineProperty(a,"__esModule",{value:!0}),a.flush=a.flushOnce=a.queue=void 0,r(V(),a),r(L(),a),r(ie(),a),r(oe(),a),r(me(),a);var c=N(),d=N();Object.defineProperty(a,"EventQueue",{enumerable:!0,get:function(){return d.default}});function l(){return c.default.global()}a.queue=l;function u(){c.default.global().flushOnce()}a.flushOnce=u;function i(s){s===void 0&&(s=10),c.default.global().flush(s)}a.flush=i})(S)),S}var A=Se();class ue{id;data;constructor(h,r){this.id=h,this.data=r}}const{serviceUuid:Ae,messageCharUuid:qe}=se(),ae=new A.SyncEvent,ce=new A.SyncEvent,he=new A.SyncEvent,le=new A.SyncEvent;function Oe(){return new Promise((a,h)=>{ne().subscribe(Ae,qe,De).then(()=>a()).catch(r=>h(r))})}function De(a){a!==void 0&&(a.getUint8(m.Data.TYPE)===m.DataType.BUTTON_PRESS&&Pe(a),a.getUint8(m.Data.TYPE)===m.DataType.MESSAGE_DONE&&le.post(a.getUint8(m.Data.DATA)))}function Pe(a){const h=a.getUint8(m.Data.DATA),r=new ue(a.getUint8(m.Data.ID),Le(a));h===m.Button.MINUS&&ce.post(r),h===m.Button.PLUS&&ae.post(r),h===m.Button.EITHER&&he.post(r)}function Le(a){const h=a.buffer,r=7,c=a.byteLength-7;return Array.from(new Uint8Array(h,r,c)).map(d=>String.fromCharCode(d)).join("").replace(/\0/g,"").trim()}function je(){return{subscribe:Oe,onPlusButton:ae,onMinButton:ce,onEitherButton:he,onMessageDone:le}}class Qe{id;elements=[];onPlus=new A.SyncEvent;onMin=new A.SyncEvent;constructor(h){this.id=h}name(){return this.id.toString(16).padStart(2,"0")}}exports.ButtonResult=ue;exports.Standee=Qe;exports.libExports=A;exports.useBluetooth=ne;exports.useBluetoothSettings=se;exports.useMessageCharacteristic=je;
package/dist/enums.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class a{static CONNECT=0;static DISCONNECT=1}class s{static UPLOAD=0;static DRAW_IMAGE=1;static DRAW_RECTANGLE=2;static BUTTON_PRESS=3;static DRAW_TEXT=4;static ALL=5;static CLEAR_GRAPHICS=6;static ACTIONS=7;static CLEAR_SCREEN=8;static MESSAGE_DONE=9}class c{static ID=0;static CACHE=1;static TTL=2;static POSITION=3;static DATA_SIZE=4;static TYPE=5;static DATA=6}class i{static u8g2_font_5x7_mf=0;static u8g2_font_inr33_t_cyrillic=1;static u8g2_font_10x20_tn=2;static u8g2_font_crox2c_tr=3}class E{static MINUS=0;static PLUS=1;static EITHER=2}class T{static INCREMENT=0;static DECREMENT=1;static SHOW=2;static HIDE=3;static SET=4;static BROADCAST=5;static TIMER=6;static CONDITION=7;static BREAK=8;static MAP=9}class A{static TYPE=0;static ID=1;static SHOW=2;static X=3;static Y=4;static WIDTH=5;static HEIGHT=6;static RADIUS=7;static FILL=8;static DATA=9;static FONT=10}class n{static EQUAL=0;static GREATER=1;static LESS=2;static GREATER_EQUAL=3;static LESS_EQUAL=4}class D{static STRING=0;static NUMBER=1;static ELEMENT=2}exports.ActionCondition=n;exports.ActionDataType=D;exports.ActionType=T;exports.Button=E;exports.Data=c;exports.DataType=s;exports.ElementData=A;exports.Font=i;exports.HandshakeType=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class a{static CONNECT=0;static DISCONNECT=1}class s{static UPLOAD=0;static DRAW_IMAGE=1;static DRAW_RECTANGLE=2;static BUTTON_PRESS=3;static DRAW_TEXT=4;static ALL=5;static CLEAR_GRAPHICS=6;static ACTIONS=7;static CLEAR_SCREEN=8;static MESSAGE_DONE=9;static LOADER=10}class c{static ID=0;static CACHE=1;static TTL=2;static POSITION=3;static DATA_SIZE=4;static TYPE=5;static DATA=6}class i{static u8g2_font_5x7_mf=0;static u8g2_font_inr33_t_cyrillic=1;static u8g2_font_10x20_tn=2;static u8g2_font_crox2c_tr=3}class E{static MINUS=0;static PLUS=1;static EITHER=2}class T{static INCREMENT=0;static DECREMENT=1;static SHOW=2;static HIDE=3;static SET=4;static BROADCAST=5;static TIMER=6;static CONDITION=7;static BREAK=8;static MAP=9}class A{static TYPE=0;static ID=1;static SHOW=2;static X=3;static Y=4;static WIDTH=5;static HEIGHT=6;static RADIUS=7;static FILL=8;static DATA=9;static FONT=10}class n{static EQUAL=0;static GREATER=1;static LESS=2;static GREATER_EQUAL=3;static LESS_EQUAL=4}class D{static STRING=0;static NUMBER=1;static ELEMENT=2}exports.ActionCondition=n;exports.ActionDataType=D;exports.ActionType=T;exports.Button=E;exports.Data=c;exports.DataType=s;exports.ElementData=A;exports.Font=i;exports.HandshakeType=a;
package/dist/enums.js CHANGED
@@ -13,6 +13,7 @@ class s {
13
13
  static ACTIONS = 7;
14
14
  static CLEAR_SCREEN = 8;
15
15
  static MESSAGE_DONE = 9;
16
+ static LOADER = 10;
16
17
  }
17
18
  class c {
18
19
  static ID = 0;
@@ -59,21 +60,21 @@ class A {
59
60
  static DATA = 9;
60
61
  static FONT = 10;
61
62
  }
62
- class _ {
63
+ class R {
63
64
  static EQUAL = 0;
64
65
  static GREATER = 1;
65
66
  static LESS = 2;
66
67
  static GREATER_EQUAL = 3;
67
68
  static LESS_EQUAL = 4;
68
69
  }
69
- class R {
70
+ class _ {
70
71
  static STRING = 0;
71
72
  static NUMBER = 1;
72
73
  static ELEMENT = 2;
73
74
  }
74
75
  export {
75
- _ as ActionCondition,
76
- R as ActionDataType,
76
+ R as ActionCondition,
77
+ _ as ActionDataType,
77
78
  T as ActionType,
78
79
  E as Button,
79
80
  c as Data,
package/dist/main.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./Objects-C8zMIamb.cjs"),i=require("./enums.cjs"),T=require("./elements.cjs"),{serviceUuid:H,handshakeCharUuid:k}=u.useBluetoothSettings(),v=new u.libExports.SyncEvent,B=new u.libExports.SyncEvent;function O(){return new Promise((t,e)=>{u.useBluetooth().subscribe(H,k,G).then(()=>t()).catch(n=>e(n))})}function G(t){t.getUint8(i.Data.TYPE)===i.HandshakeType.CONNECT&&v.post(t),t.getUint8(i.Data.TYPE)===i.HandshakeType.DISCONNECT&&B.post(t)}function D(){return{subscribe:O,onConnected:v,onDisconnected:B}}const{onConnected:W}=D(),{onDisconnected:V}=D();function q(){return new Promise((t,e)=>{u.useBluetooth().connect(u.useBluetoothSettings().options).then(()=>Promise.all([D().subscribe(),u.useMessageCharacteristic().subscribe()]).then(()=>{t()})).catch(n=>e(n))})}function b(){return{connect:q,onConnected:W,onDisconnected:V}}const w=[];function j(){let t=Math.floor(Math.random()*256);for(;w.includes(t);)t=Math.floor(Math.random()*256);return t}function z(t){w.push(t),K()}function K(){w.length<=20||w.splice(0,w.length-20)}function Y(){const t=j();return z(t),t}function F(){return{create:Y}}const{serviceUuid:X,messageCharUuid:Z}=u.useBluetoothSettings(),{onMessageDone:J}=u.useMessageCharacteristic(),Q=u.useBluetooth(),I=10,M=15,R=[],E=new Map;let p=!1;J.attach(nt);function tt(t,e,n){const r=F().create();return et(r,t,e,n).forEach(o=>R.push(o)),new Promise(o=>{E.set(r,o),p||x()})}function et(t,e,n,r){if(r==null)return[new Uint8Array([n,t,I,0,2,e,0])];const s=new Uint8Array(2+r.length),o=r.length+2,a=[];s.set([e,o],0),s.set(r,2);for(let c=0;c<o;c+=M){const l=Math.min(M,o-c),d=new Uint8Array(l),y=[n,t,I,c,o];d.set(s.subarray(c,c+l),0),a.push(new Uint8Array([...y,...d]))}return a}function x(){if(p)return;const t=R.shift();if(t==null){p=!1;return}p=!0,Q.writeCharacteristic(X,Z,t).catch(e=>console.log(e)).finally(()=>{p=!1,x()})}function nt(t){E.get(t)?.(),E.delete(t),x()}function A(){return{write:tt}}const{write:S}=A();function rt(t){return{upload:(e,n)=>{const r=new Uint8Array(n.length+1);return r.set([e],0),r.set(n,1),S(i.DataType.UPLOAD,t,r)},clear:()=>S(i.DataType.CLEAR_GRAPHICS,t)}}const{onConnected:st,onDisconnected:ot}=b();st.attach(it);ot.attach(at);const g=[],C=new u.libExports.SyncEvent;function it(t){const e=new Uint8Array(t.buffer,6);for(const n of e)ct(n);C.post(g)}function at(t){const e=t.getUint8(2);ut(e),C.post(g)}function ct(t){g.some(e=>e.id===t)||g.push(new u.Standee(t))}function ut(t){const e=g.findIndex(n=>n.id===t);e!==-1&&g.splice(e,1)}function ht(){return{standees:g,onChange:C}}function lt(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 ft(t){return{add:r=>(r.id=lt(t.elements).generate(),t.elements.push(r),r),remove:r=>{t.elements=t.elements.filter(s=>s.id!==r)}}}const{write:_}=A();function dt(t){return _(i.DataType.CLEAR_SCREEN,t.id)}function gt(t){let e=new Uint8Array;for(const n of t.elements)n.dirty!==!1&&(n instanceof T.Image&&(e=U(e,yt(n))),n instanceof T.Rectangle&&(e=U(e,pt(n))),n instanceof T.Text&&(e=U(e,wt(n))),n.dirty=!1);return _(i.DataType.ALL,t.id,e)}function U(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function yt(t){return new Uint8Array([i.DataType.DRAW_IMAGE,7,t.id,t.show?1:0,t.x,t.y,t.width,t.height,t.data])}function pt(t){return new Uint8Array([i.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 wt(t){const e=new TextEncoder().encode(t.text),n=new Uint8Array(9+e.length);return n.set([i.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 At(){return{clear:dt,draw:gt}}function mt(t,e){const n=Math.ceil(t.length/e),r=Math.ceil(e/8),s=new Uint8Array(r*n);for(let o=0;o<n;o++)for(let a=0;a<r;a++){let c=0;for(let l=0;l<8;l++){const d=a*8+l,y=o*e+d;d<e&&y<t.length&&t[y]&&(c|=1<<7-l)}s[o*r+a]=N(c)}return s}function N(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 Tt(t){const e=t.reduce((s,o)=>s+o.length,0),n=new Uint8Array(e);let r=0;for(const s of t)n.set(s,r),r+=s.length;return n}function m(){return{pixelsToBytes:mt,bitswap:N,flattenUint8Arrays:Tt}}const{flattenUint8Arrays:P}=m();class f{element_id;property;constructor(e,n){this.element_id=e,this.property=n}}class h{target;constructor(e){this.target=e}format(){return new Uint8Array}}class Ut extends h{format(){return new Uint8Array([i.ActionType.INCREMENT,2,this.target.element_id,this.target.property])}}class Et extends h{format(){return new Uint8Array([i.ActionType.DECREMENT,2,this.target.element_id,this.target.property])}}class Dt extends h{format(){return new Uint8Array([i.ActionType.SHOW,1,this.target.element_id])}}class xt extends h{format(){return new Uint8Array([i.ActionType.HIDE,1,this.target.element_id])}}class Ct extends h{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=[i.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"?i.ActionDataType.STRING:i.ActionDataType.NUMBER}convertValue(e){return e===i.ActionDataType.STRING?new TextEncoder().encode(this.value):e===i.ActionDataType.NUMBER?new Uint8Array([this.value]):new Uint8Array}}class It extends h{format(){return this.target.element_id!==0&&this.target.property!==0?new Uint8Array([i.ActionType.BROADCAST,2,this.target.element_id,this.target.property]):new Uint8Array([i.ActionType.BROADCAST,0])}}class Mt extends h{format(){return new Uint8Array([i.ActionType.BREAK,0])}}let St=class extends h{fromLow;fromHigh;toLow;toHigh;value;constructor(e,n,r,s,o,a){super(a),this.value=e,this.fromLow=n,this.fromHigh=r,this.toLow=s,this.toHigh=o}format(){return new Uint8Array([i.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 vt extends h{deciseconds;resetable;onComplete;constructor(e,n,r){super(new f(0,0)),this.deciseconds=e,this.resetable=n,this.onComplete=r}format(){const e=P(this.onComplete.map(s=>s.format())),n=new Uint8Array(4+e.length),r=[i.ActionType.TIMER,e.length+2,this.resetable?1:0,this.deciseconds];return n.set(r,0),e.forEach((s,o)=>n.set([s],o+4)),n}}class Bt extends h{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([i.ActionDataType.NUMBER,1,e]);if(typeof e=="string"){const n=new TextEncoder().encode(e);return new Uint8Array([i.ActionDataType.STRING,n.length,...n])}return e instanceof f?new Uint8Array([i.ActionDataType.ELEMENT,2,e.element_id,e.property]):new Uint8Array}format(){const e=P(this.actions.map(c=>c.format())),n=this.convertValue(this.left),r=this.convertValue(this.right),s=4+n.length+r.length+e.length,o=new Uint8Array(s),a=[i.ActionType.CONDITION,s-2,n.length+r.length+1];return o.set(a,0),o.set([this.operator],3),o.set(n,4),o.set(r,4+n.length),o.set(e,4+n.length+r.length),o}}function bt(){return{target(t,e){return new f(t,e)},increment(t){return new Ut(t)},decrement(t){return new Et(t)},show(t){return new Dt(new f(t,0))},hide(t){return new xt(new f(t,0))},set(t,e){return new Ct(t,e)},broadcast(t){return new It(t||new f(0,0))},timer(t,e,n){return new vt(t,e,n)},stop(){return new Mt(new f(0,0))},condition(t,e,n,r){return new Bt(t,e,n,r)},map(t,e,n,r,s,o){return new St(t,e,n,r,s,o)}}}const{write:Rt}=A(),{flattenUint8Arrays:_t}=m();function Nt(t){return{setButton(e,n){const r=_t(n.map(o=>o.format())),s=new Uint8Array(1+r.length);return s.set([e],0),r.forEach((o,a)=>s.set([o],a+1)),Rt(i.DataType.ACTIONS,t.id,s)}}}function Pt(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=n,r.src=t})}function $t(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 Lt(t){const e=[],n=t.data,r=t.width,s=t.height;for(let o=0;o<s;o++)for(let a=0;a<r;a++){const c=(o*r+a)*4,l=n[c],d=n[c+1],y=n[c+2],L=.2126*l+.7152*d+.0722*y;e.push(L<128?0:1)}return{width:r,height:s,pixels:e}}function $(){return{createImage:Pt,getImageData:$t,imageDataToPixels:Lt}}const{createImage:Ht,getImageData:kt,imageDataToPixels:Ot}=$(),{pixelsToBytes:Gt}=m();function Wt(t){return new Promise((e,n)=>{Ht(t).then(r=>kt(r)).then(r=>Ot(r)).then(r=>Gt(r.pixels,r.width)).then(r=>e(r)).catch(r=>n(r))})}function Vt(){return{imageToBytes:Wt}}function qt(t,e,n,r,s){return(t-e)/(n-e)*(s-r)+r}function jt(){return{map:qt}}exports.useMessageCharacteristic=u.useMessageCharacteristic;exports.useActions=bt;exports.useBinary=m;exports.useButtons=Nt;exports.useConverter=Vt;exports.useDisplay=At;exports.useImage=$;exports.useMesh=b;exports.useMeshUpload=rt;exports.useMeshWriter=A;exports.useStandeeElements=ft;exports.useStandees=ht;exports.useUtils=jt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./Objects-DgZKSQY-.cjs"),o=require("./enums.cjs"),T=require("./elements.cjs"),{serviceUuid:L,handshakeCharUuid:b}=c.useBluetoothSettings(),M=new c.libExports.SyncEvent,S=new c.libExports.SyncEvent;function H(){return new Promise((t,e)=>{c.useBluetooth().subscribe(L,b,$).then(()=>t()).catch(n=>e(n))})}function $(t){t.getUint8(o.Data.TYPE)===o.HandshakeType.CONNECT&&M.post(t),t.getUint8(o.Data.TYPE)===o.HandshakeType.DISCONNECT&&S.post(t)}function D(){return{subscribe:H,onConnected:M,onDisconnected:S}}const{onConnected:O}=D(),{onDisconnected:G}=D(),{onPlusButton:V,onMinButton:W,onEitherButton:q}=c.useMessageCharacteristic();function j(){return new Promise((t,e)=>{c.useBluetooth().connect(c.useBluetoothSettings().options).then(()=>Promise.all([D().subscribe(),c.useMessageCharacteristic().subscribe()]).then(()=>{t()})).catch(n=>e(n))})}function v(){return{connect:j,onConnected:O,onDisconnected:G,onPlusButton:V,onMinButton:W,onEitherButton:q}}const g=[];function z(){let t=Math.floor(Math.random()*256);for(;g.includes(t);)t=Math.floor(Math.random()*256);return t}function K(t){g.push(t),Y()}function Y(){g.length<=20||g.splice(0,g.length-20)}function F(){const t=z();return K(t),t}function X(){return{create:F}}const{serviceUuid:Z,messageCharUuid:J}=c.useBluetoothSettings(),{onMessageDone:Q}=c.useMessageCharacteristic(),tt=c.useBluetooth(),R=[],E=new Map;let y=!1;Q.attach(nt);function et(t){return t.packets.forEach(e=>R.push(e)),new Promise(e=>{E.set(t.cache,e),y||x()})}function x(){if(y)return;const t=R.shift();if(t==null){y=!1;return}y=!0,tt.writeCharacteristic(Z,J,t).catch(e=>console.log(e)).finally(()=>{y=!1,x()})}function nt(t){E.get(t)?.(),E.delete(t),x()}function rt(){return{write:et}}const I=10,B=15;function st(t){if(t.data==null){let s=[t.id,t.cache,I,0,2,t.type,0];return[new Uint8Array(s)]}const e=new Uint8Array(2+t.data.length),n=t.data.length+2,r=[];e.set([t.type,n],0),e.set(t.data,2);for(let s=0;s<n;s+=B){const i=Math.min(B,n-s),a=new Uint8Array(i),u=[t.id,t.cache,I,s,n];a.set(e.subarray(s,s+i),0),r.push(new Uint8Array([...u,...a]))}return r}class p{cache=X().create();type;id;data;packets=[];constructor(e,n,r){this.type=e,this.id=n,this.data=r,this.packets=st(this)}send(){return rt().write(this)}}function ot(t){return{upload:(e,n)=>{const r=new Uint8Array(n.length+1);return r.set([e],0),r.set(n,1),new p(o.DataType.UPLOAD,t.id,r)},clear:()=>new p(o.DataType.CLEAR_GRAPHICS,t.id)}}class it{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,0]);await new p(o.DataType.LOADER,this.id,e).send(),await Promise.all(this.buffers.map(r=>r.send()))}}function at(t){return{load:e=>new it(e,t.id)}}const{onConnected:ct,onDisconnected:ut}=v();ct.attach(ht);ut.attach(dt);const l=[],C=new c.libExports.SyncEvent;function ht(t){const e=new Uint8Array(t.buffer,6);for(const n of e)lt(n);C.post(l)}function dt(t){const e=t.getUint8(2);ft(e),C.post(l)}function lt(t){l.some(e=>e.id===t)||l.push(new c.Standee(t))}function ft(t){const e=l.findIndex(n=>n.id===t);e!==-1&&l.splice(e,1)}function pt(){return{standees:l,onChange:C}}function yt(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 gt(t){return{add:r=>(r.id=yt(t.elements).generate(),t.elements.push(r),r),remove:r=>{t.elements=t.elements.filter(s=>s.id!==r)}}}function wt(t){return new p(o.DataType.CLEAR_SCREEN,t.id)}function At(t){let e=new Uint8Array;for(const n of t.elements)n.dirty!==!1&&(n instanceof T.Image&&(e=U(e,mt(n))),n instanceof T.Rectangle&&(e=U(e,Tt(n))),n instanceof T.Text&&(e=U(e,Ut(n))),n.dirty=!1);return new p(o.DataType.ALL,t.id,e)}function U(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function mt(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 Tt(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 Ut(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:wt,draw:At}}function Dt(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 a=0;a<r;a++){let u=0;for(let f=0;f<8;f++){const w=a*8+f,A=i*e+w;w<e&&A<t.length&&t[A]&&(u|=1<<7-f)}s[i*r+a]=P(u)}return s}function P(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 xt(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 m(){return{pixelsToBytes:Dt,bitswap:P,flattenUint8Arrays:xt}}const{flattenUint8Arrays:_}=m();class d{element_id;property;constructor(e,n){this.element_id=e,this.property=n}}class h{target;constructor(e){this.target=e}format(){return new Uint8Array}}class Ct extends h{format(){return new Uint8Array([o.ActionType.INCREMENT,2,this.target.element_id,this.target.property])}}class It extends h{format(){return new Uint8Array([o.ActionType.DECREMENT,2,this.target.element_id,this.target.property])}}class Bt extends h{format(){return new Uint8Array([o.ActionType.SHOW,1,this.target.element_id])}}class Mt extends h{format(){return new Uint8Array([o.ActionType.HIDE,1,this.target.element_id])}}class St extends h{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 vt extends h{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 Rt extends h{format(){return new Uint8Array([o.ActionType.BREAK,0])}}let Pt=class extends h{fromLow;fromHigh;toLow;toHigh;value;constructor(e,n,r,s,i,a){super(a),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 _t extends h{deciseconds;resetable;onComplete;constructor(e,n,r){super(new d(0,0)),this.deciseconds=e,this.resetable=n,this.onComplete=r}format(){const e=_(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 Nt extends h{left;operator;right;actions;constructor(e,n,r,s){super(new d(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 d?new Uint8Array([o.ActionDataType.ELEMENT,2,e.element_id,e.property]):new Uint8Array}format(){const e=_(this.actions.map(u=>u.format())),n=this.convertValue(this.left),r=this.convertValue(this.right),s=4+n.length+r.length+e.length,i=new Uint8Array(s),a=[o.ActionType.CONDITION,s-2,n.length+r.length+1];return i.set(a,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 kt(){return{target(t,e){return new d(t,e)},increment(t){return new Ct(t)},decrement(t){return new It(t)},show(t){return new Bt(new d(t,0))},hide(t){return new Mt(new d(t,0))},set(t,e){return new St(t,e)},broadcast(t){return new vt(t||new d(0,0))},timer(t,e,n){return new _t(t,e,n)},stop(){return new Rt(new d(0,0))},condition(t,e,n,r){return new Nt(t,e,n,r)},map(t,e,n,r,s,i){return new Pt(t,e,n,r,s,i)}}}const{flattenUint8Arrays:Lt}=m();function bt(t){return{setButton(e,n){const r=Lt(n.map(i=>i.format())),s=new Uint8Array(1+r.length);return s.set([e],0),r.forEach((i,a)=>s.set([i],a+1)),new p(o.DataType.ACTIONS,t.id,s)}}}function Ht(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=n,r.src=t})}function $t(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 Ot(t){const e=[],n=t.data,r=t.width,s=t.height;for(let i=0;i<s;i++)for(let a=0;a<r;a++){const u=(i*r+a)*4,f=n[u],w=n[u+1],A=n[u+2],k=.2126*f+.7152*w+.0722*A;e.push(k<128?0:1)}return{width:r,height:s,pixels:e}}function N(){return{createImage:Ht,getImageData:$t,imageDataToPixels:Ot}}const{createImage:Gt,getImageData:Vt,imageDataToPixels:Wt}=N(),{pixelsToBytes:qt}=m();function jt(t){return new Promise((e,n)=>{Gt(t).then(r=>Vt(r)).then(r=>Wt(r)).then(r=>qt(r.pixels,r.width)).then(r=>e(r)).catch(r=>n(r))})}function zt(){return{imageToBytes:jt}}function Kt(t,e,n,r,s){return(t-e)/(n-e)*(s-r)+r}function Yt(){return{map:Kt}}exports.useActions=kt;exports.useBinary=m;exports.useButtons=bt;exports.useConverter=zt;exports.useDisplay=Et;exports.useGraphics=ot;exports.useImage=N;exports.useLoader=at;exports.useMesh=v;exports.useStandeeElements=gt;exports.useStandees=pt;exports.useUtils=Yt;
package/dist/main.js CHANGED
@@ -1,162 +1,195 @@
1
- import { l as E, u as T, a as x, b as N, S as V } from "./Objects-BFbD5RI-.js";
2
- import { Data as S, HandshakeType as R, DataType as l, ActionType as c, ActionDataType as g } from "./enums.js";
3
- import { Image as W, Rectangle as z, Text as K } from "./elements.js";
4
- const { serviceUuid: Y, handshakeCharUuid: q } = x(), P = new E.SyncEvent(), $ = new E.SyncEvent();
5
- function F() {
1
+ import { l as T, u as x, a as C, b as D, S as O } from "./Objects-CmJJGRgZ.js";
2
+ import { Data as S, HandshakeType as R, DataType as h, ActionType as a, ActionDataType as l } from "./enums.js";
3
+ import { Image as G, Rectangle as V, Text as W } from "./elements.js";
4
+ const { serviceUuid: z, handshakeCharUuid: K } = C(), N = new T.SyncEvent(), k = new T.SyncEvent();
5
+ function Y() {
6
6
  return new Promise((t, e) => {
7
- T().subscribe(Y, q, X).then(() => t()).catch((n) => e(n));
7
+ x().subscribe(z, K, q).then(() => t()).catch((n) => e(n));
8
8
  });
9
9
  }
10
- function X(t) {
11
- t.getUint8(S.TYPE) === R.CONNECT && P.post(t), t.getUint8(S.TYPE) === R.DISCONNECT && $.post(t);
10
+ function q(t) {
11
+ t.getUint8(S.TYPE) === R.CONNECT && N.post(t), t.getUint8(S.TYPE) === R.DISCONNECT && k.post(t);
12
12
  }
13
- function C() {
14
- return { subscribe: F, onConnected: P, onDisconnected: $ };
13
+ function I() {
14
+ return { subscribe: Y, onConnected: N, onDisconnected: k };
15
15
  }
16
- const { onConnected: Z } = C(), { onDisconnected: j } = C();
17
- function J() {
16
+ const { onConnected: F } = I(), { onDisconnected: X } = I(), { onPlusButton: Z, onMinButton: j, onEitherButton: J } = D();
17
+ function Q() {
18
18
  return new Promise((t, e) => {
19
- T().connect(x().options).then(
19
+ x().connect(C().options).then(
20
20
  () => Promise.all([
21
- C().subscribe(),
22
- N().subscribe()
21
+ I().subscribe(),
22
+ D().subscribe()
23
23
  ]).then(() => {
24
24
  t();
25
25
  })
26
26
  ).catch((n) => e(n));
27
27
  });
28
28
  }
29
- function Q() {
29
+ function tt() {
30
30
  return {
31
- connect: J,
32
- onConnected: Z,
33
- onDisconnected: j
31
+ connect: Q,
32
+ onConnected: F,
33
+ onDisconnected: X,
34
+ onPlusButton: Z,
35
+ onMinButton: j,
36
+ onEitherButton: J
34
37
  };
35
38
  }
36
- const m = [];
37
- function tt() {
39
+ const y = [];
40
+ function et() {
38
41
  let t = Math.floor(Math.random() * 256);
39
- for (; m.includes(t); ) t = Math.floor(Math.random() * 256);
42
+ for (; y.includes(t); ) t = Math.floor(Math.random() * 256);
40
43
  return t;
41
44
  }
42
- function et(t) {
43
- m.push(t), nt();
44
- }
45
- function nt() {
46
- m.length <= 20 || m.splice(0, m.length - 20);
45
+ function nt(t) {
46
+ y.push(t), rt();
47
47
  }
48
48
  function rt() {
49
- const t = tt();
50
- return et(t), t;
49
+ y.length <= 20 || y.splice(0, y.length - 20);
51
50
  }
52
51
  function st() {
52
+ const t = et();
53
+ return nt(t), t;
54
+ }
55
+ function ot() {
53
56
  return {
54
- create: rt
57
+ create: st
55
58
  };
56
59
  }
57
- const { serviceUuid: ot, messageCharUuid: it } = x(), { onMessageDone: at } = N(), ct = T(), _ = 10, B = 15, L = [], U = /* @__PURE__ */ new Map();
58
- let y = !1;
59
- at.attach(ft);
60
- function ut(t, e, n) {
61
- const r = st().create();
62
- return ht(r, t, e, n).forEach((o) => L.push(o)), new Promise((o) => {
63
- U.set(r, o), y || I();
60
+ const { serviceUuid: it, messageCharUuid: at } = C(), { onMessageDone: ct } = D(), ut = x(), L = [], E = /* @__PURE__ */ new Map();
61
+ let p = !1;
62
+ ct.attach(dt);
63
+ function ht(t) {
64
+ return t.packets.forEach((e) => L.push(e)), new Promise((e) => {
65
+ E.set(t.cache, e), p || M();
64
66
  });
65
67
  }
66
- function ht(t, e, n, r) {
67
- if (r == null)
68
- return [new Uint8Array([n, t, _, 0, 2, e, 0])];
69
- const s = new Uint8Array(2 + r.length), o = r.length + 2, i = [];
70
- s.set([e, o], 0), s.set(r, 2);
71
- for (let a = 0; a < o; a += B) {
72
- const h = Math.min(B, o - a), d = new Uint8Array(h), p = [n, t, _, a, o];
73
- d.set(s.subarray(a, a + h), 0), i.push(new Uint8Array([...p, ...d]));
74
- }
75
- return i;
76
- }
77
- function I() {
78
- if (y)
68
+ function M() {
69
+ if (p)
79
70
  return;
80
71
  const t = L.shift();
81
72
  if (t == null) {
82
- y = !1;
73
+ p = !1;
83
74
  return;
84
75
  }
85
- y = !0, ct.writeCharacteristic(ot, it, t).catch((e) => console.log(e)).finally(() => {
86
- y = !1, I();
76
+ p = !0, ut.writeCharacteristic(it, at, t).catch((e) => console.log(e)).finally(() => {
77
+ p = !1, M();
87
78
  });
88
79
  }
89
- function ft(t) {
90
- U.get(t)?.(), U.delete(t), I();
80
+ function dt(t) {
81
+ E.get(t)?.(), E.delete(t), M();
82
+ }
83
+ function lt() {
84
+ return { write: ht };
91
85
  }
92
- function D() {
93
- return { write: ut };
86
+ const _ = 10, P = 15;
87
+ function ft(t) {
88
+ if (t.data == null) {
89
+ let s = [t.id, t.cache, _, 0, 2, t.type, 0];
90
+ return [new Uint8Array(s)];
91
+ }
92
+ const e = new Uint8Array(2 + t.data.length), n = t.data.length + 2, r = [];
93
+ e.set([t.type, n], 0), e.set(t.data, 2);
94
+ for (let s = 0; s < n; s += P) {
95
+ const o = Math.min(P, n - s), i = new Uint8Array(o), c = [t.id, t.cache, _, s, n];
96
+ i.set(e.subarray(s, s + o), 0), r.push(new Uint8Array([...c, ...i]));
97
+ }
98
+ return r;
99
+ }
100
+ class w {
101
+ cache = ot().create();
102
+ type;
103
+ id;
104
+ data;
105
+ packets = [];
106
+ constructor(e, n, r) {
107
+ this.type = e, this.id = n, this.data = r, this.packets = ft(this);
108
+ }
109
+ send() {
110
+ return lt().write(this);
111
+ }
94
112
  }
95
- const { write: b } = D();
96
- function jt(t) {
113
+ function Qt(t) {
97
114
  return {
98
115
  upload: (e, n) => {
99
116
  const r = new Uint8Array(n.length + 1);
100
- return r.set([e], 0), r.set(n, 1), b(l.UPLOAD, t, r);
117
+ return r.set([e], 0), r.set(n, 1), new w(h.UPLOAD, t.id, r);
101
118
  },
102
- clear: () => b(l.CLEAR_GRAPHICS, t)
119
+ clear: () => new w(h.CLEAR_GRAPHICS, t.id)
103
120
  };
104
121
  }
105
- const { onConnected: lt, onDisconnected: dt } = Q();
106
- lt.attach(gt);
107
- dt.attach(wt);
108
- const w = [], M = new E.SyncEvent();
109
- function gt(t) {
122
+ class gt {
123
+ id;
124
+ buffers;
125
+ totalPackets = 0;
126
+ constructor(e, n) {
127
+ this.id = n, this.buffers = e, this.buffers.forEach((r) => this.totalPackets += r.packets.length);
128
+ }
129
+ async send() {
130
+ const e = new Uint8Array([this.totalPackets, 0]);
131
+ await new w(h.LOADER, this.id, e).send(), await Promise.all(this.buffers.map((r) => r.send()));
132
+ }
133
+ }
134
+ function te(t) {
135
+ return {
136
+ load: (e) => new gt(e, t.id)
137
+ };
138
+ }
139
+ const { onConnected: wt, onDisconnected: pt } = tt();
140
+ wt.attach(yt);
141
+ pt.attach(mt);
142
+ const f = [], v = new T.SyncEvent();
143
+ function yt(t) {
110
144
  const e = new Uint8Array(t.buffer, 6);
111
145
  for (const n of e)
112
- pt(n);
113
- M.post(w);
146
+ At(n);
147
+ v.post(f);
114
148
  }
115
- function wt(t) {
149
+ function mt(t) {
116
150
  const e = t.getUint8(2);
117
- yt(e), M.post(w);
151
+ Ut(e), v.post(f);
118
152
  }
119
- function pt(t) {
120
- w.some((e) => e.id === t) || w.push(new V(t));
153
+ function At(t) {
154
+ f.some((e) => e.id === t) || f.push(new O(t));
121
155
  }
122
- function yt(t) {
123
- const e = w.findIndex((n) => n.id === t);
124
- e !== -1 && w.splice(e, 1);
156
+ function Ut(t) {
157
+ const e = f.findIndex((n) => n.id === t);
158
+ e !== -1 && f.splice(e, 1);
125
159
  }
126
- function Jt() {
127
- return { standees: w, onChange: M };
160
+ function ee() {
161
+ return { standees: f, onChange: v };
128
162
  }
129
- function mt(t) {
163
+ function Et(t) {
130
164
  const e = () => {
131
165
  let r = Math.floor(Math.random() * 256);
132
166
  return n(r) ? e() : r;
133
167
  }, n = (r) => t.some((s) => s.id === r);
134
168
  return { generate: e };
135
169
  }
136
- function Qt(t) {
137
- return { add: (r) => (r.id = mt(t.elements).generate(), t.elements.push(r), r), remove: (r) => {
170
+ function ne(t) {
171
+ return { add: (r) => (r.id = Et(t.elements).generate(), t.elements.push(r), r), remove: (r) => {
138
172
  t.elements = t.elements.filter(
139
173
  (s) => s.id !== r
140
174
  );
141
175
  } };
142
176
  }
143
- const { write: H } = D();
144
- function At(t) {
145
- return H(l.CLEAR_SCREEN, t.id);
177
+ function Tt(t) {
178
+ return new w(h.CLEAR_SCREEN, t.id);
146
179
  }
147
- function Ut(t) {
180
+ function xt(t) {
148
181
  let e = new Uint8Array();
149
182
  for (const n of t.elements)
150
- n.dirty !== !1 && (n instanceof W && (e = A(e, Et(n))), n instanceof z && (e = A(e, Tt(n))), n instanceof K && (e = A(e, xt(n))), n.dirty = !1);
151
- return H(l.ALL, t.id, e);
183
+ n.dirty !== !1 && (n instanceof G && (e = U(e, Ct(n))), n instanceof V && (e = U(e, Dt(n))), n instanceof W && (e = U(e, It(n))), n.dirty = !1);
184
+ return new w(h.ALL, t.id, e);
152
185
  }
153
- function A(t, e) {
186
+ function U(t, e) {
154
187
  const n = new Uint8Array(t.length + e.length);
155
188
  return n.set(t, 0), n.set(e, t.length), n;
156
189
  }
157
- function Et(t) {
190
+ function Ct(t) {
158
191
  return new Uint8Array([
159
- l.DRAW_IMAGE,
192
+ h.DRAW_IMAGE,
160
193
  7,
161
194
  t.id,
162
195
  t.show ? 1 : 0,
@@ -167,9 +200,9 @@ function Et(t) {
167
200
  t.data
168
201
  ]);
169
202
  }
170
- function Tt(t) {
203
+ function Dt(t) {
171
204
  return new Uint8Array([
172
- l.DRAW_RECTANGLE,
205
+ h.DRAW_RECTANGLE,
173
206
  9,
174
207
  t.id,
175
208
  t.show ? 1 : 0,
@@ -182,11 +215,11 @@ function Tt(t) {
182
215
  t.colorBlack ? 0 : 1
183
216
  ]);
184
217
  }
185
- function xt(t) {
218
+ function It(t) {
186
219
  const e = new TextEncoder().encode(t.text), n = new Uint8Array(9 + e.length);
187
220
  return n.set(
188
221
  [
189
- l.DRAW_TEXT,
222
+ h.DRAW_TEXT,
190
223
  7 + e.length,
191
224
  t.id,
192
225
  t.show ? 1 : 0,
@@ -199,41 +232,41 @@ function xt(t) {
199
232
  0
200
233
  ), n.set(e, 9), n;
201
234
  }
202
- function te() {
203
- return { clear: At, draw: Ut };
235
+ function re() {
236
+ return { clear: Tt, draw: xt };
204
237
  }
205
- function Ct(t, e) {
238
+ function Mt(t, e) {
206
239
  const n = Math.ceil(t.length / e), r = Math.ceil(e / 8), s = new Uint8Array(r * n);
207
240
  for (let o = 0; o < n; o++)
208
241
  for (let i = 0; i < r; i++) {
209
- let a = 0;
210
- for (let h = 0; h < 8; h++) {
211
- const d = i * 8 + h, p = o * e + d;
212
- d < e && p < t.length && t[p] && (a |= 1 << 7 - h);
242
+ let c = 0;
243
+ for (let g = 0; g < 8; g++) {
244
+ const m = i * 8 + g, A = o * e + m;
245
+ m < e && A < t.length && t[A] && (c |= 1 << 7 - g);
213
246
  }
214
- s[o * r + i] = k(a);
247
+ s[o * r + i] = b(c);
215
248
  }
216
249
  return s;
217
250
  }
218
- function k(t) {
251
+ function b(t) {
219
252
  return t = (t & 240) >> 4 | (t & 15) << 4, t = (t & 204) >> 2 | (t & 51) << 2, t = (t & 170) >> 1 | (t & 85) << 1, t;
220
253
  }
221
- function It(t) {
254
+ function vt(t) {
222
255
  const e = t.reduce((s, o) => s + o.length, 0), n = new Uint8Array(e);
223
256
  let r = 0;
224
257
  for (const s of t)
225
258
  n.set(s, r), r += s.length;
226
259
  return n;
227
260
  }
228
- function v() {
261
+ function B() {
229
262
  return {
230
- pixelsToBytes: Ct,
231
- bitswap: k,
232
- flattenUint8Arrays: It
263
+ pixelsToBytes: Mt,
264
+ bitswap: b,
265
+ flattenUint8Arrays: vt
233
266
  };
234
267
  }
235
- const { flattenUint8Arrays: O } = v();
236
- class f {
268
+ const { flattenUint8Arrays: $ } = B();
269
+ class d {
237
270
  element_id;
238
271
  property;
239
272
  constructor(e, n) {
@@ -249,44 +282,44 @@ class u {
249
282
  return new Uint8Array();
250
283
  }
251
284
  }
252
- class Dt extends u {
285
+ class Bt extends u {
253
286
  format() {
254
287
  return new Uint8Array([
255
- c.INCREMENT,
288
+ a.INCREMENT,
256
289
  2,
257
290
  this.target.element_id,
258
291
  this.target.property
259
292
  ]);
260
293
  }
261
294
  }
262
- class Mt extends u {
295
+ class St extends u {
263
296
  format() {
264
297
  return new Uint8Array([
265
- c.DECREMENT,
298
+ a.DECREMENT,
266
299
  2,
267
300
  this.target.element_id,
268
301
  this.target.property
269
302
  ]);
270
303
  }
271
304
  }
272
- class vt extends u {
305
+ class Rt extends u {
273
306
  format() {
274
- return new Uint8Array([c.SHOW, 1, this.target.element_id]);
307
+ return new Uint8Array([a.SHOW, 1, this.target.element_id]);
275
308
  }
276
309
  }
277
- class St extends u {
310
+ class _t extends u {
278
311
  format() {
279
- return new Uint8Array([c.HIDE, 1, this.target.element_id]);
312
+ return new Uint8Array([a.HIDE, 1, this.target.element_id]);
280
313
  }
281
314
  }
282
- class Rt extends u {
315
+ class Pt extends u {
283
316
  value;
284
317
  constructor(e, n) {
285
318
  super(e), this.value = n;
286
319
  }
287
320
  format() {
288
321
  const e = this.dataType(), n = this.convertValue(e), r = new Uint8Array(5 + n.length), s = [
289
- c.SET,
322
+ a.SET,
290
323
  n.length + 3,
291
324
  e,
292
325
  this.target.element_id,
@@ -295,28 +328,28 @@ class Rt extends u {
295
328
  return r.set(s, 0), r.set(n, 5), r;
296
329
  }
297
330
  dataType() {
298
- return typeof this.value === "string" ? g.STRING : g.NUMBER;
331
+ return typeof this.value === "string" ? l.STRING : l.NUMBER;
299
332
  }
300
333
  convertValue(e) {
301
- return e === g.STRING ? new TextEncoder().encode(this.value) : e === g.NUMBER ? new Uint8Array([this.value]) : new Uint8Array();
334
+ return e === l.STRING ? new TextEncoder().encode(this.value) : e === l.NUMBER ? new Uint8Array([this.value]) : new Uint8Array();
302
335
  }
303
336
  }
304
- class _t extends u {
337
+ class Nt extends u {
305
338
  format() {
306
339
  return this.target.element_id !== 0 && this.target.property !== 0 ? new Uint8Array([
307
- c.BROADCAST,
340
+ a.BROADCAST,
308
341
  2,
309
342
  this.target.element_id,
310
343
  this.target.property
311
- ]) : new Uint8Array([c.BROADCAST, 0]);
344
+ ]) : new Uint8Array([a.BROADCAST, 0]);
312
345
  }
313
346
  }
314
- class Bt extends u {
347
+ class kt extends u {
315
348
  format() {
316
- return new Uint8Array([c.BREAK, 0]);
349
+ return new Uint8Array([a.BREAK, 0]);
317
350
  }
318
351
  }
319
- let bt = class extends u {
352
+ let Lt = class extends u {
320
353
  fromLow;
321
354
  fromHigh;
322
355
  toLow;
@@ -327,7 +360,7 @@ let bt = class extends u {
327
360
  }
328
361
  format() {
329
362
  return new Uint8Array([
330
- c.MAP,
363
+ a.MAP,
331
364
  8,
332
365
  this.value.element_id,
333
366
  this.value.property,
@@ -340,18 +373,18 @@ let bt = class extends u {
340
373
  ]);
341
374
  }
342
375
  };
343
- class Nt extends u {
376
+ class bt extends u {
344
377
  deciseconds;
345
378
  resetable;
346
379
  onComplete;
347
380
  constructor(e, n, r) {
348
- super(new f(0, 0)), this.deciseconds = e, this.resetable = n, this.onComplete = r;
381
+ super(new d(0, 0)), this.deciseconds = e, this.resetable = n, this.onComplete = r;
349
382
  }
350
383
  format() {
351
- const e = O(
384
+ const e = $(
352
385
  this.onComplete.map((s) => s.format())
353
386
  ), n = new Uint8Array(4 + e.length), r = [
354
- c.TIMER,
387
+ a.TIMER,
355
388
  e.length + 2,
356
389
  this.resetable ? 1 : 0,
357
390
  this.deciseconds
@@ -361,111 +394,111 @@ class Nt extends u {
361
394
  ), n;
362
395
  }
363
396
  }
364
- class Pt extends u {
397
+ class $t extends u {
365
398
  left;
366
399
  operator;
367
400
  right;
368
401
  actions;
369
402
  constructor(e, n, r, s) {
370
- super(new f(0, 0)), this.actions = s, this.left = e, this.operator = n, this.right = r;
403
+ super(new d(0, 0)), this.actions = s, this.left = e, this.operator = n, this.right = r;
371
404
  }
372
405
  convertValue(e) {
373
406
  if (typeof e == "number")
374
- return new Uint8Array([g.NUMBER, 1, e]);
407
+ return new Uint8Array([l.NUMBER, 1, e]);
375
408
  if (typeof e == "string") {
376
409
  const n = new TextEncoder().encode(e);
377
410
  return new Uint8Array([
378
- g.STRING,
411
+ l.STRING,
379
412
  n.length,
380
413
  ...n
381
414
  ]);
382
415
  }
383
- return e instanceof f ? new Uint8Array([
384
- g.ELEMENT,
416
+ return e instanceof d ? new Uint8Array([
417
+ l.ELEMENT,
385
418
  2,
386
419
  e.element_id,
387
420
  e.property
388
421
  ]) : new Uint8Array();
389
422
  }
390
423
  format() {
391
- const e = O(
392
- this.actions.map((a) => a.format())
424
+ const e = $(
425
+ this.actions.map((c) => c.format())
393
426
  ), n = this.convertValue(this.left), r = this.convertValue(this.right), s = 4 + n.length + r.length + e.length, o = new Uint8Array(s), i = [
394
- c.CONDITION,
427
+ a.CONDITION,
395
428
  s - 2,
396
429
  n.length + r.length + 1
397
430
  ];
398
431
  return o.set(i, 0), o.set([this.operator], 3), o.set(n, 4), o.set(r, 4 + n.length), o.set(e, 4 + n.length + r.length), o;
399
432
  }
400
433
  }
401
- function ne() {
434
+ function oe() {
402
435
  return {
403
436
  target(t, e) {
404
- return new f(t, e);
437
+ return new d(t, e);
405
438
  },
406
439
  increment(t) {
407
- return new Dt(t);
440
+ return new Bt(t);
408
441
  },
409
442
  decrement(t) {
410
- return new Mt(t);
443
+ return new St(t);
411
444
  },
412
445
  show(t) {
413
- return new vt(new f(t, 0));
446
+ return new Rt(new d(t, 0));
414
447
  },
415
448
  hide(t) {
416
- return new St(new f(t, 0));
449
+ return new _t(new d(t, 0));
417
450
  },
418
451
  set(t, e) {
419
- return new Rt(t, e);
452
+ return new Pt(t, e);
420
453
  },
421
454
  broadcast(t) {
422
- return new _t(t || new f(0, 0));
455
+ return new Nt(t || new d(0, 0));
423
456
  },
424
457
  timer(t, e, n) {
425
- return new Nt(t, e, n);
458
+ return new bt(t, e, n);
426
459
  },
427
460
  stop() {
428
- return new Bt(new f(0, 0));
461
+ return new kt(new d(0, 0));
429
462
  },
430
463
  condition(t, e, n, r) {
431
- return new Pt(t, e, n, r);
464
+ return new $t(t, e, n, r);
432
465
  },
433
466
  map(t, e, n, r, s, o) {
434
- return new bt(t, e, n, r, s, o);
467
+ return new Lt(t, e, n, r, s, o);
435
468
  }
436
469
  };
437
470
  }
438
- const { write: $t } = D(), { flattenUint8Arrays: Lt } = v();
439
- function re(t) {
471
+ const { flattenUint8Arrays: Ht } = B();
472
+ function ie(t) {
440
473
  return {
441
474
  setButton(e, n) {
442
- const r = Lt(
475
+ const r = Ht(
443
476
  n.map((o) => o.format())
444
477
  ), s = new Uint8Array(1 + r.length);
445
478
  return s.set([e], 0), r.forEach(
446
479
  (o, i) => s.set([o], i + 1)
447
- ), $t(l.ACTIONS, t.id, s);
480
+ ), new w(h.ACTIONS, t.id, s);
448
481
  }
449
482
  };
450
483
  }
451
- function Ht(t) {
484
+ function Ot(t) {
452
485
  return new Promise((e, n) => {
453
486
  const r = new Image();
454
487
  r.onload = () => e(r), r.onerror = n, r.src = t;
455
488
  });
456
489
  }
457
- function kt(t) {
490
+ function Gt(t) {
458
491
  const e = document.createElement("canvas"), n = e.getContext("2d");
459
492
  if (e.width = t.width, e.height = t.height, !n)
460
493
  throw new Error("Failed to get 2D context for image data.");
461
494
  return n.drawImage(t, 0, 0), n.getImageData(0, 0, t.width, t.height);
462
495
  }
463
- function Ot(t) {
496
+ function Vt(t) {
464
497
  const e = [], n = t.data, r = t.width, s = t.height;
465
498
  for (let o = 0; o < s; o++)
466
499
  for (let i = 0; i < r; i++) {
467
- const a = (o * r + i) * 4, h = n[a], d = n[a + 1], p = n[a + 2], G = 0.2126 * h + 0.7152 * d + 0.0722 * p;
468
- e.push(G < 128 ? 0 : 1);
500
+ const c = (o * r + i) * 4, g = n[c], m = n[c + 1], A = n[c + 2], H = 0.2126 * g + 0.7152 * m + 0.0722 * A;
501
+ e.push(H < 128 ? 0 : 1);
469
502
  }
470
503
  return {
471
504
  width: r,
@@ -473,42 +506,41 @@ function Ot(t) {
473
506
  pixels: e
474
507
  };
475
508
  }
476
- function Gt() {
509
+ function Wt() {
477
510
  return {
478
- createImage: Ht,
479
- getImageData: kt,
480
- imageDataToPixels: Ot
511
+ createImage: Ot,
512
+ getImageData: Gt,
513
+ imageDataToPixels: Vt
481
514
  };
482
515
  }
483
- const { createImage: Vt, getImageData: Wt, imageDataToPixels: zt } = Gt(), { pixelsToBytes: Kt } = v();
484
- function Yt(t) {
516
+ const { createImage: zt, getImageData: Kt, imageDataToPixels: Yt } = Wt(), { pixelsToBytes: qt } = B();
517
+ function Ft(t) {
485
518
  return new Promise((e, n) => {
486
- Vt(t).then((r) => Wt(r)).then((r) => zt(r)).then((r) => Kt(r.pixels, r.width)).then((r) => e(r)).catch((r) => n(r));
519
+ zt(t).then((r) => Kt(r)).then((r) => Yt(r)).then((r) => qt(r.pixels, r.width)).then((r) => e(r)).catch((r) => n(r));
487
520
  });
488
521
  }
489
- function se() {
522
+ function ae() {
490
523
  return {
491
- imageToBytes: Yt
524
+ imageToBytes: Ft
492
525
  };
493
526
  }
494
- function qt(t, e, n, r, s) {
527
+ function Xt(t, e, n, r, s) {
495
528
  return (t - e) / (n - e) * (s - r) + r;
496
529
  }
497
- function oe() {
498
- return { map: qt };
530
+ function ce() {
531
+ return { map: Xt };
499
532
  }
500
533
  export {
501
- ne as useActions,
502
- v as useBinary,
503
- re as useButtons,
504
- se as useConverter,
505
- te as useDisplay,
506
- Gt as useImage,
507
- Q as useMesh,
508
- jt as useMeshUpload,
509
- D as useMeshWriter,
510
- N as useMessageCharacteristic,
511
- Qt as useStandeeElements,
512
- Jt as useStandees,
513
- oe as useUtils
534
+ oe as useActions,
535
+ B as useBinary,
536
+ ie as useButtons,
537
+ ae as useConverter,
538
+ re as useDisplay,
539
+ Qt as useGraphics,
540
+ Wt as useImage,
541
+ te as useLoader,
542
+ tt as useMesh,
543
+ ne as useStandeeElements,
544
+ ee as useStandees,
545
+ ce as useUtils
514
546
  };
package/dist/objects.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Objects-C8zMIamb.cjs");exports.ButtonResult=e.ButtonResult;exports.Standee=e.Standee;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Objects-DgZKSQY-.cjs");exports.ButtonResult=e.ButtonResult;exports.Standee=e.Standee;
package/dist/objects.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B as a, S as o } from "./Objects-BFbD5RI-.js";
1
+ import { B as a, S as o } from "./Objects-CmJJGRgZ.js";
2
2
  export {
3
3
  a as ButtonResult,
4
4
  o as Standee
@@ -13,6 +13,7 @@ declare class DataType {
13
13
  static ACTIONS: number;
14
14
  static CLEAR_SCREEN: number;
15
15
  static MESSAGE_DONE: number;
16
+ static LOADER: number;
16
17
  }
17
18
  declare class Data {
18
19
  static ID: number;
@@ -0,0 +1,10 @@
1
+ import { DataType } from '../Enums.js';
2
+ export default class Buffer {
3
+ cache: number;
4
+ type: DataType;
5
+ id: number;
6
+ data?: Uint8Array;
7
+ packets: Uint8Array[];
8
+ constructor(type: DataType, id: number, data?: Uint8Array);
9
+ send(): Promise<void>;
10
+ }
@@ -3,5 +3,8 @@ export declare function useMesh(): {
3
3
  connect: typeof connect;
4
4
  onConnected: import('ts-events').SyncEvent<DataView<ArrayBufferLike>>;
5
5
  onDisconnected: import('ts-events').SyncEvent<DataView<ArrayBufferLike>>;
6
+ onPlusButton: import('ts-events').SyncEvent<import('./MessageCharacteristic.js').ButtonResult>;
7
+ onMinButton: import('ts-events').SyncEvent<import('./MessageCharacteristic.js').ButtonResult>;
8
+ onEitherButton: import('ts-events').SyncEvent<import('./MessageCharacteristic.js').ButtonResult>;
6
9
  };
7
10
  export {};
@@ -1,5 +1,5 @@
1
- import { DataType } from '../Enums.js';
2
- declare function write(type: DataType, id: number, data?: Uint8Array): Promise<void>;
1
+ import { default as Buffer } from './Buffer.js';
2
+ declare function write(buffer: Buffer): Promise<void>;
3
3
  export declare function useMeshWriter(): {
4
4
  write: typeof write;
5
5
  };
@@ -7,9 +7,9 @@ export declare class ButtonResult {
7
7
  declare function subscribe(): Promise<void>;
8
8
  export declare function useMessageCharacteristic(): {
9
9
  subscribe: typeof subscribe;
10
- onPlus: SyncEvent<ButtonResult>;
11
- onMin: SyncEvent<ButtonResult>;
12
- onEither: SyncEvent<ButtonResult>;
10
+ onPlusButton: SyncEvent<ButtonResult>;
11
+ onMinButton: SyncEvent<ButtonResult>;
12
+ onEitherButton: SyncEvent<ButtonResult>;
13
13
  onMessageDone: SyncEvent<number>;
14
14
  };
15
15
  export {};
@@ -1,7 +1,6 @@
1
- import { useMessageCharacteristic } from './ble/MessageCharacteristic';
2
1
  import { useMesh } from './ble/Mesh';
3
- import { useMeshWriter } from './ble/MeshWriter';
4
- import { useMeshUpload } from './ble/MeshUpload';
2
+ import { useGraphics } from './standee/Graphics';
3
+ import { useLoader } from './standee/Loader';
5
4
  import { useStandees } from './standee/Standees';
6
5
  import { useStandeeElements } from './standee/StandeeElements';
7
6
  import { useDisplay } from './standee/Display';
@@ -11,4 +10,4 @@ import { useBinary } from './composable/Binary';
11
10
  import { useImage } from './composable/Image';
12
11
  import { useConverter } from './composable/Converter';
13
12
  import { useUtils } from './composable/DisplayUtils';
14
- export { useMesh, useMeshWriter, useMeshUpload, useStandees, useStandeeElements, useDisplay, useActions, useButtons, useBinary, useImage, useConverter, useUtils, useMessageCharacteristic, };
13
+ export { useMesh, useGraphics, useStandees, useLoader, useStandeeElements, useDisplay, useActions, useButtons, useBinary, useImage, useConverter, useUtils, };
@@ -1,6 +1,7 @@
1
1
  import { default as Standee } from './Standee';
2
2
  import { Action } from './Actions';
3
+ import { default as Buffer } from '../ble/Buffer';
3
4
  declare function useButtons(standee: Standee): {
4
- setButton(button: number, actions: Array<Action>): Promise<void>;
5
+ setButton(button: number, actions: Array<Action>): Buffer;
5
6
  };
6
7
  export { useButtons };
@@ -1,6 +1,7 @@
1
+ import { default as Buffer } from '../ble/Buffer';
1
2
  import { default as Standee } from './Standee';
2
- declare function clear(standee: Standee): Promise<void>;
3
- declare function draw(standee: Standee): Promise<void>;
3
+ declare function clear(standee: Standee): Buffer;
4
+ declare function draw(standee: Standee): Buffer;
4
5
  export declare function useDisplay(): {
5
6
  clear: typeof clear;
6
7
  draw: typeof draw;
@@ -0,0 +1,6 @@
1
+ import { default as Buffer } from '../ble/Buffer';
2
+ import { default as Standee } from './Standee';
3
+ export declare function useGraphics(standee: Standee): {
4
+ upload: (id: number, image: Uint8Array) => Buffer;
5
+ clear: () => Buffer;
6
+ };
@@ -0,0 +1,13 @@
1
+ import { default as Buffer } from '../ble/Buffer';
2
+ import { default as Standee } from './Standee';
3
+ declare class Loader {
4
+ id: number;
5
+ buffers: Buffer[];
6
+ totalPackets: number;
7
+ constructor(buffers: Buffer[], id: number);
8
+ send(): Promise<void>;
9
+ }
10
+ export declare function useLoader(standee: Standee): {
11
+ load: (buffers: Buffer[]) => Loader;
12
+ };
13
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsd-ble",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
package/readme.md ADDED
@@ -0,0 +1,30 @@
1
+ # NotSoDoom standees bluetooth
2
+
3
+ This package is needed to communicate with the bluetooth standees. You can send to it what you want to be displayed on the screen. You can also give instructions on what the buttons need to do as well as upload graphics to them to be displayed. The standees communicate through a mesh they create on their own. You inly have to connect to one standee to be part of the mesh.
4
+
5
+ ## Mesh
6
+
7
+ The mesh lets you read and write to the standees.
8
+
9
+ #### `useMesh()`
10
+
11
+ - `connect()` is the method to call when you want to search for a bluetooth device through the browser. This needs to be on a user action like a click.
12
+ - `onConnected` is a `SyncEvent<DataView<ArrayBufferLike>>` event that you can attach your method to. This will be called when the mesh is connected.
13
+
14
+ ```javascript
15
+ let connected = false;
16
+ const mesh = useMesh();
17
+
18
+ mesh.onConnected.attach(() => (connected = true));
19
+ ```
20
+
21
+ - `onDisconnected` is a `SyncEvent<DataView<ArrayBufferLike>>` event that you can attach your method to. This will be called when the mesh is connected.
22
+
23
+ ```javascript
24
+ let connected = false;
25
+ const mesh = useMesh();
26
+
27
+ mesh.onDisconnected.attach(() => (connected = false));
28
+ ```
29
+
30
+ for more information on the events package check out https://github.com/rogierschouten/ts-events.
@@ -1,4 +0,0 @@
1
- export declare function useMeshUpload(target: number): {
2
- upload: (id: number, image: Uint8Array) => Promise<void>;
3
- clear: () => Promise<void>;
4
- };