nsd-ble 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nsd-ble.d.ts CHANGED
@@ -55,7 +55,7 @@ declare class Decrement extends Action {
55
55
  format(): Uint8Array;
56
56
  }
57
57
 
58
- declare class DisplayElement {
58
+ export declare class DisplayElement {
59
59
  id: number;
60
60
  dirty: boolean;
61
61
  _show: boolean;
@@ -83,6 +83,20 @@ declare class Hide extends Action {
83
83
  format(): Uint8Array;
84
84
  }
85
85
 
86
+ declare class Image_2 extends DisplayElement {
87
+ _width: number;
88
+ _height: number;
89
+ _data: number;
90
+ constructor(x: number, y: number, width: number, height: number, data: number, show?: boolean, colorBlack?: boolean);
91
+ set width(width: number);
92
+ set height(height: number);
93
+ set data(data: number);
94
+ get width(): number;
95
+ get height(): number;
96
+ get data(): number;
97
+ }
98
+ export { Image_2 as Image }
99
+
86
100
  declare function imageDataToPixels(data: ImageData): ImagePixels;
87
101
 
88
102
  declare function imageToBytes(image_url: string): Promise<Uint8Array>;
@@ -105,6 +119,22 @@ declare class Map_2 extends Action {
105
119
 
106
120
  declare function pixelsToBytes(pixels: number[], width: number): Uint8Array<ArrayBuffer>;
107
121
 
122
+ export declare class Rectangle extends DisplayElement {
123
+ _width: number;
124
+ _height: number;
125
+ _radius: number;
126
+ _fill: boolean;
127
+ constructor(x: number, y: number, width: number, height: number, radius?: number, fill?: boolean, show?: boolean, colorBlack?: boolean);
128
+ set width(width: number);
129
+ set height(height: number);
130
+ set radius(radius: number);
131
+ set fill(fill: boolean);
132
+ get width(): number;
133
+ get height(): number;
134
+ get radius(): number;
135
+ get fill(): boolean;
136
+ }
137
+
108
138
  declare class Set_2 extends Action {
109
139
  value: number | string;
110
140
  constructor(target: Target, value: number | string);
@@ -126,12 +156,28 @@ export declare class Standee {
126
156
  name(): string;
127
157
  }
128
158
 
159
+ declare function subscribe(): Promise<void>;
160
+
129
161
  declare class Target {
130
162
  element_id: number;
131
163
  property: number;
132
164
  constructor(element_id: number, property: number);
133
165
  }
134
166
 
167
+ declare class Text_2 extends DisplayElement {
168
+ _text: string;
169
+ _font: number;
170
+ _center: boolean;
171
+ constructor(x: number, y: number, text: string, font: number, center?: boolean, show?: boolean, colorBlack?: boolean);
172
+ set text(text: string);
173
+ set font(font: number);
174
+ get text(): string;
175
+ get font(): number;
176
+ get center(): boolean;
177
+ set center(center: boolean);
178
+ }
179
+ export { Text_2 as Text }
180
+
135
181
  declare class Timer extends Action {
136
182
  deciseconds: number;
137
183
  resetable: boolean;
@@ -194,6 +240,14 @@ export declare function useMeshWriter(): {
194
240
  write: typeof write;
195
241
  };
196
242
 
243
+ export declare function useMessageCharacteristic(): {
244
+ subscribe: typeof subscribe;
245
+ onPlus: SyncEvent<ButtonResult>;
246
+ onMin: SyncEvent<ButtonResult>;
247
+ onEither: SyncEvent<ButtonResult>;
248
+ onMessageDone: SyncEvent<number>;
249
+ };
250
+
197
251
  export declare function useStandeeElements(standee: Standee): {
198
252
  add: <T>(element: DisplayElement) => T;
199
253
  remove: (id: number) => void;
package/dist/nsd-ble.js CHANGED
@@ -1437,7 +1437,11 @@ function wn() {
1437
1437
  }
1438
1438
  export {
1439
1439
  Zt as ButtonResult,
1440
+ st as DisplayElement,
1441
+ Le as Image,
1442
+ Pe as Rectangle,
1440
1443
  Vt as Standee,
1444
+ Ie as Text,
1441
1445
  pn as useActions,
1442
1446
  it as useBinary,
1443
1447
  _n as useButtons,
@@ -1447,6 +1451,7 @@ export {
1447
1451
  fe as useMesh,
1448
1452
  ln as useMeshUpload,
1449
1453
  rt as useMeshWriter,
1454
+ Pt as useMessageCharacteristic,
1450
1455
  vn as useStandeeElements,
1451
1456
  fn as useStandees,
1452
1457
  wn as useUtils
@@ -1 +1 @@
1
- (function(g,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(g=typeof globalThis<"u"?globalThis:g||self,w(g["nsd-ble"]={}))})(this,(function(g){"use strict";var w={},L={},at;function Q(){if(at)return L;at=1,Object.defineProperty(L,"__esModule",{value:!0}),L.BaseEvent=void 0;var t=(function(){function e(){}return e.prototype.attach=function(n,r){return this._attach(n,r,!1)},e.prototype.once=function(n,r){return this._attach(n,r,!0)},e.prototype._attach=function(n,r,f){var l=this,u,i,a,h;if(typeof n=="function")i=n,h=function(){return l.detach(i)};else if(!r&&typeof n.post=="function")a=n,h=function(){return l.detach(a)};else{if(typeof n!="object"||n===void 0)throw new Error("Expect a function or object as first argument");if(typeof r!="function")throw new Error("Expect a function as second argument");u=n,i=r,h=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:a,once:f}),h},e.prototype.detach=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];this._detach.apply(this,n)},e.prototype._detach=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];if(!(!this._listeners||this._listeners.length===0)){var f,l,u;n.length>=1&&(typeof n[0]=="function"?l=n[0]:n.length===1&&typeof n[0].post=="function"?u=n[0]:f=n[0]),n.length>=2&&(l=n[1]),this._listeners=this._listeners.filter(function(i){return(typeof l>"u"||i.handler===l)&&(typeof u>"u"||i.event===u)&&(typeof f>"u"||i.boundTo===f)?(i.deleted=!0,!1):!0}),this._listeners.length===0&&delete this._listeners}},e.prototype.post=function(n){throw new Error("abstract")},e.prototype.listenerCount=function(){return this._listeners?this._listeners.length:0},e.prototype._call=function(n,r){this._listeners&&(n.deleted||(n.once&&(n.deleted=!0,this._listeners=this._listeners.filter(function(f){return f!==n}),this._listeners.length===0&&delete this._listeners),n.event?n.event.post.apply(n.event,r):n.handler&&n.handler.apply(typeof n.boundTo=="object"?n.boundTo:this,r)))},e})();return L.BaseEvent=t,L}var A={},ut;function I(){if(ut)return A;ut=1;var t=A&&A.__extends||(function(){var l=function(u,i){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,h){a.__proto__=h}||function(a,h){for(var o in h)h.hasOwnProperty(o)&&(a[o]=h[o])},l(u,i)};return function(u,i){l(u,i);function a(){this.constructor=u}u.prototype=i===null?Object.create(i):(a.prototype=i.prototype,new a)}})();Object.defineProperty(A,"__esModule",{value:!0}),A.ErrorSyncEvent=A.VoidSyncEvent=A.SyncEvent=void 0;var e=Q(),n=(function(l){t(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 r),this._listenersChanged},enumerable:!1,configurable:!0}),u.prototype.post=function(){for(var i=[],a=0;a<arguments.length;a++)i[a]=arguments[a];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 h=this._listeners,o=0;o<h.length;++o){var s=h[o];this._call(s,i)}this._recursion--}},u.prototype._attach=function(i,a,h){var o,s,c,d,v=(s=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&s!==void 0?s:0,y=l.prototype._attach.call(this,i,a,h);return this.evtListenersChanged&&v!==((d=(c=this._listeners)===null||c===void 0?void 0:c.length)!==null&&d!==void 0?d:0)&&this.evtListenersChanged.post(),y},u.prototype._detach=function(){for(var i,a,h,o,s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];var d=(a=(i=this._listeners)===null||i===void 0?void 0:i.length)!==null&&a!==void 0?a:0,v=l.prototype._detach.apply(this,s);return this.evtListenersChanged&&d!==((o=(h=this._listeners)===null||h===void 0?void 0:h.length)!==null&&o!==void 0?o:0)&&this.evtListenersChanged.post(),v},u.MAX_RECURSION_DEPTH=10,u})(e.BaseEvent);A.SyncEvent=n;var r=(function(l){t(u,l);function u(){return l!==null&&l.apply(this,arguments)||this}return u.prototype.post=function(){l.prototype.post.call(this,void 0)},u})(n);A.VoidSyncEvent=r;var f=(function(l){t(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})(n);return A.ErrorSyncEvent=f,A}var m={},V={},ct;function Y(){if(ct)return V;ct=1,Object.defineProperty(V,"__esModule",{value:!0});var t=I(),e=(function(){function n(){this.evtFilled=new t.SyncEvent,this.evtDrained=new t.SyncEvent,this._queue=[],this._flushing=!1}return n.global=function(){return n._instance||n.resetGlobal(),n._instance},n.resetGlobal=function(){n._instance=new n},n.prototype.empty=function(){return this._queue.length===0},n.prototype.add=function(r){this._queue.push(r),this._queue.length===1&&!this._flushing&&this.evtFilled.post(this)},n.prototype.flushOnce=function(){var r=this._queue.length===0,f=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=f,!r&&!f&&this._queue.length===0&&this.evtDrained.post(this)}},n.prototype.flush=function(r){r===void 0&&(r=10);var f=this._queue.length===0,l=this._flushing;this._flushing=!0;try{for(var u=0;this._queue.length>0;){if(typeof r=="number"&&u>=r)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,!f&&!l&&this._queue.length===0&&this.evtDrained.post(this)}},n})();return V.default=e,V}var ht;function lt(){if(ht)return m;ht=1;var t=m&&m.__extends||(function(){var i=function(a,h){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,s){o.__proto__=s}||function(o,s){for(var c in s)s.hasOwnProperty(c)&&(o[c]=s[c])},i(a,h)};return function(a,h){i(a,h);function o(){this.constructor=a}a.prototype=h===null?Object.create(h):(o.prototype=h.prototype,new o)}})();Object.defineProperty(m,"__esModule",{value:!0}),m.ErrorQueuedEvent=m.VoidQueuedEvent=m.QueuedEvent=void 0;var e=Q(),n=Y(),r=I(),f=(function(i){t(a,i);function a(h){h===void 0&&(h={});var o=i.call(this)||this;return o._queued=!1,o.options=h,typeof h.condensed=="boolean"?o._condensed=h.condensed:o._condensed=!1,typeof h.queue=="object"&&h.queue!==null&&(o._queue=h.queue),o}return Object.defineProperty(a.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new r.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),a.prototype.post=function(){for(var h=this,o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];if(!(!this._listeners||this._listeners.length===0)){var c=this._queue?this._queue:n.default.global();if(this._condensed){if(this._queuedData=o,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,c.add(function(){h._queued=!1;for(var v=h._queuedData,y=h._queuedListeners,p=0;p<y.length;++p){var _=y[p];h._call(_,v)}})}else{var d=this._listeners;c.add(function(){for(var v=0;v<d.length;++v){var y=d[v];h._call(y,o)}})}}},a.prototype._attach=function(h,o,s){var c,d,v,y,p=(d=(c=this._listeners)===null||c===void 0?void 0:c.length)!==null&&d!==void 0?d:0,_=i.prototype._attach.call(this,h,o,s);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(),_},a.prototype._detach=function(){for(var h,o,s,c,d=[],v=0;v<arguments.length;v++)d[v]=arguments[v];var y=(o=(h=this._listeners)===null||h===void 0?void 0:h.length)!==null&&o!==void 0?o:0,p=i.prototype._detach.apply(this,d);return this.evtListenersChanged&&y!==((c=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&c!==void 0?c:0)&&this.evtListenersChanged.post(),p},a})(e.BaseEvent);m.QueuedEvent=f;var l=(function(i){t(a,i);function a(){return i!==null&&i.apply(this,arguments)||this}return a.prototype.post=function(){i.prototype.post.call(this,void 0)},a})(f);m.VoidQueuedEvent=l;var u=(function(i){t(a,i);function a(){return i!==null&&i.apply(this,arguments)||this}return a.prototype.post=function(h){if(!this._listeners||this._listeners.length===0)throw new Error("error event posted while no listeners attached. Error: "+h.message);i.prototype.post.call(this,h)},a})(f);return m.ErrorQueuedEvent=u,m}var C={},ft;function dt(){if(ft)return C;ft=1;var t=C&&C.__extends||(function(){var u=function(i,a){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(h,o){h.__proto__=o}||function(h,o){for(var s in o)o.hasOwnProperty(s)&&(h[s]=o[s])},u(i,a)};return function(i,a){u(i,a);function h(){this.constructor=i}i.prototype=a===null?Object.create(a):(h.prototype=a.prototype,new h)}})();Object.defineProperty(C,"__esModule",{value:!0}),C.ErrorAsyncEvent=C.VoidAsyncEvent=C.AsyncEvent=void 0;var e=Q(),n=I(),r=(function(u){t(i,u);function i(a){a===void 0&&(a={});var h=u.call(this)||this;return h._queued=!1,h.options=a,typeof a.condensed=="boolean"?h._condensed=a.condensed:h._condensed=!1,h}return Object.defineProperty(i.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new n.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),i.defaultScheduler=function(a){typeof window<"u"?setTimeout(a,0):setImmediate(a)},i.setScheduler=function(a){i._scheduler=a},i.prototype.post=function(){for(var a=this,h=[],o=0;o<arguments.length;o++)h[o]=arguments[o];if(!(!this._listeners||this._listeners.length===0))if(this._condensed){if(this._queuedData=h,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,i._scheduler(function(){a._queued=!1;for(var c=a._queuedData,d=a._queuedListeners,v=0;v<d.length;++v){var y=d[v];a._call(y,c)}})}else{var s=this._listeners;i._scheduler(function(){for(var c=0;c<s.length;++c){var d=s[c];a._call(d,h)}})}},i.prototype._call=function(a,h){a.event&&a.event instanceof i?a.event._postDirect(h):u.prototype._call.call(this,a,h)},i.prototype._postDirect=function(a){if(!(!this._listeners||this._listeners.length===0))for(var h=this._listeners,o=0;o<h.length;++o){var s=h[o];this._call(s,a)}},i.prototype._attach=function(a,h,o){var s,c,d,v,y=(c=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&c!==void 0?c:0,p=u.prototype._attach.call(this,a,h,o);return this.evtListenersChanged&&y!==((v=(d=this._listeners)===null||d===void 0?void 0:d.length)!==null&&v!==void 0?v:0)&&this.evtListenersChanged.post(),p},i.prototype._detach=function(){for(var a,h,o,s,c=[],d=0;d<arguments.length;d++)c[d]=arguments[d];var v=(h=(a=this._listeners)===null||a===void 0?void 0:a.length)!==null&&h!==void 0?h:0,y=u.prototype._detach.apply(this,c);return this.evtListenersChanged&&v!==((s=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&s!==void 0?s:0)&&this.evtListenersChanged.post(),y},i._scheduler=i.defaultScheduler,i})(e.BaseEvent);C.AsyncEvent=r;var f=(function(u){t(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})(r);C.VoidAsyncEvent=f;var l=(function(u){t(i,u);function i(){return u!==null&&u.apply(this,arguments)||this}return i.prototype.post=function(a){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+a.message);u.prototype.post.call(this,a)},i})(r);return C.ErrorAsyncEvent=l,C}var M={},R={},vt;function Ht(){if(vt)return R;vt=1,Object.defineProperty(R,"__esModule",{value:!0}),R.shallowEquals=void 0;function t(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;switch(typeof e){case"boolean":case"number":case"string":case"function":case"symbol":case"undefined":return!1;case"object":if(e===null||n===null)return!1;if(Array.isArray(e)||Array.isArray(n)){if(!Array.isArray(e)||!Array.isArray(n)||e.length!==n.length)return!1;for(var r=0;r<e.length;++r)if(e[r]!==n[r])return!1;return!0}var f=[],l=[];for(var u in e)e.hasOwnProperty(u)&&f.push(u);for(var i in n)n.hasOwnProperty(i)&&l.push(i);if(f.sort(),l.sort(),f.join(",")!==l.join(","))return!1;for(var r=0;r<f.length;++r)if(e[f[r]]!==n[f[r]])return!1;return!0;default:return!1}}return R.shallowEquals=t,R}var yt;function kt(){return yt||(yt=1,(function(t){var e=M&&M.__extends||(function(){var o=function(s,c){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,v){d.__proto__=v}||function(d,v){for(var y in v)v.hasOwnProperty(y)&&(d[y]=v[y])},o(s,c)};return function(s,c){o(s,c);function d(){this.constructor=s}s.prototype=c===null?Object.create(c):(d.prototype=c.prototype,new d)}})();Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorAnyEvent=t.VoidAnyEvent=t.AnyEvent=t.EventType=void 0;var n=Ht(),r=I(),f=dt(),l=lt(),u;(function(o){o[o.Sync=0]="Sync",o[o.Async=1]="Async",o[o.Queued=2]="Queued"})(u=t.EventType||(t.EventType={}));var i=(function(){function o(s){this._events=[],s&&s.monitorAttach&&(this.evtFirstAttached=new a,this.evtLastDetached=new a)}return Object.defineProperty(o.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new r.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),o.prototype.attach=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];var d=u.Sync;s.length>0&&typeof s[0]=="number"&&(d=s.shift());var v=this,y,p,_;return typeof s[0]=="function"||s[0]&&typeof s[0]=="object"&&typeof s[0].post=="function"?(typeof s[0]=="function"?y=s[0]:_=s[0],p=s[1]):(v=s[0],y=s[1],p=s[2]),this._attach(d,v,y,_,p,!1)},o.prototype.once=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];var d=u.Sync;s.length>0&&typeof s[0]=="number"&&(d=s.shift());var v=this,y,p,_;return typeof s[0]=="function"||s[0]&&typeof s[0]=="object"&&typeof s[0].post=="function"?(typeof s[0]=="function"?y=s[0]:_=s[0],p=s[1]):(v=s[0],y=s[1],p=s[2]),this._attach(d,v,y,_,p,!0)},o.prototype._attach=function(s,c,d,v,y,p){var _=this,jt=this.evtFirstAttached?this.listenerCount():0,E;switch(s){case u.Sync:{for(var st=0,xt=this._events;st<xt.length;st++){var D=xt[st];D instanceof r.SyncEvent&&(E=D)}E||(E=new r.SyncEvent,this._events.push(E))}break;case u.Async:{for(var it=0,Qt=this._events;it<Qt.length;it++){var D=Qt[it];D instanceof f.AsyncEvent&&n.shallowEquals(D.options,y)&&(E=D)}E||(E=new f.AsyncEvent(y),this._events.push(E))}break;case u.Queued:{for(var ot=0,Vt=this._events;ot<Vt.length;ot++){var D=Vt[ot];D instanceof l.QueuedEvent&&n.shallowEquals(D.options,y)&&(E=D)}E||(E=new l.QueuedEvent(y),this._events.push(E))}break;default:throw new Error("unknown EventType")}var x;return p?v?x=E.once(v):x=E.once(c,d):v?x=E.attach(v):x=E.attach(c,d),this.evtFirstAttached&&jt===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&jt!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var $t=_.evtLastDetached?_.listenerCount():0;x(),_.evtLastDetached&&$t>0&&_.listenerCount()===0&&_.evtLastDetached.post(),_.evtListenersChanged&&$t!==_.listenerCount()&&_.evtListenersChanged.post()}},o.prototype.attachSync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Sync),this.attach.apply(this,s)},o.prototype.onceSync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Sync),this.once.apply(this,s)},o.prototype.attachAsync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Async),this.attach.apply(this,s)},o.prototype.onceAsync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Async),this.once.apply(this,s)},o.prototype.attachQueued=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Queued),this.attach.apply(this,s)},o.prototype.onceQueued=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Queued),this.once.apply(this,s)},o.prototype.detach=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];for(var d=this.listenerCount(),v=0;v<this._events.length;++v)this._events[v].detach.apply(this._events[v],s);this.evtListenersChanged&&d!==this.listenerCount()&&this.evtListenersChanged.post(),this.evtLastDetached&&d>0&&this.listenerCount()===0&&this.evtLastDetached.post()},o.prototype.post=function(s){for(var c=[],d=0;d<this._events.length;++d)c.push(this._events[d]);for(var d=0;d<c.length;++d)c[d].post(s)},o.prototype.listenerCount=function(){for(var s=0,c=0;c<this._events.length;++c)s+=this._events[c].listenerCount();return s},o})();t.AnyEvent=i;var a=(function(o){e(s,o);function s(){return o!==null&&o.apply(this,arguments)||this}return s.prototype.post=function(){o.prototype.post.call(this,void 0)},s})(i);t.VoidAnyEvent=a;var h=(function(o){e(s,o);function s(){return o!==null&&o.apply(this,arguments)||this}return s.prototype.post=function(c){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+c.message);o.prototype.post.call(this,c)},s})(i);t.ErrorAnyEvent=h})(M)),M}var gt;function Gt(){return gt||(gt=1,(function(t){var e=w&&w.__createBinding||(Object.create?(function(a,h,o,s){s===void 0&&(s=o),Object.defineProperty(a,s,{enumerable:!0,get:function(){return h[o]}})}):(function(a,h,o,s){s===void 0&&(s=o),a[s]=h[o]})),n=w&&w.__exportStar||function(a,h){for(var o in a)o!=="default"&&!h.hasOwnProperty(o)&&e(h,a,o)};Object.defineProperty(t,"__esModule",{value:!0}),t.flush=t.flushOnce=t.queue=void 0,n(Q(),t),n(I(),t),n(lt(),t),n(dt(),t),n(kt(),t);var r=Y(),f=Y();Object.defineProperty(t,"EventQueue",{enumerable:!0,get:function(){return f.default}});function l(){return r.default.global()}t.queue=l;function u(){r.default.global().flushOnce()}t.flushOnce=u;function i(a){a===void 0&&(a=10),r.default.global().flush(a)}t.flush=i})(w)),w}var U=Gt();class pt{id;elements=[];onPlus=new U.SyncEvent;onMin=new U.SyncEvent;constructor(e){this.id=e}name(){return this.id.toString(16).padStart(2,"0")}}let K=!1,$=[],H,_t,k=new Map;async function Wt(t){try{if(H=await navigator.bluetooth.requestDevice(t),H.gatt===void 0)throw new Error("Device does not support GATT");_t=await H.gatt.connect(),H.addEventListener("gattserverdisconnected",Ft),K=!0}catch(e){throw e}}function Ft(){k.clear(),K=!1,$.forEach(t=>t())}function Xt(t){$.push(t)}function Yt(t){$=$.filter(e=>e!==t)}async function z(t,e){if(k.has(e)){const f=k.get(e);if(f===void 0)throw new Error("Characteristic not found");return f}const r=await(await _t.getPrimaryService(t)).getCharacteristic(e);return k.set(e,r),r}async function Kt(t,e){return await(await z(t,e)).readValue()}async function zt(t,e,n){const r=new DataView(new ArrayBuffer(n.length));r.setUint8(0,n[0]),await(await z(t,e)).writeValue(r)}async function Zt(t,e,n){const r=await z(t,e);r.addEventListener("characteristicvaluechanged",f=>{let l=f.target.value;l===void 0&&(l=new DataView(new ArrayBuffer(0))),n(l)}),await r.startNotifications()}function G(){return{connected:K,connect:Wt,readCharacteristic:Kt,writeCharacteristic:zt,subscribe:Zt,setDisconnectCallback:Xt,removeDisconnectCallback:Yt}}class Et{static CONNECT=0;static DISCONNECT=1}class b{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 q{static ID=0;static CACHE=1;static TTL=2;static POSITION=3;static DATA_SIZE=4;static TYPE=5;static DATA=6}class Z{static MINUS=0;static PLUS=1;static EITHER=2}class S{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 P{static STRING=0;static NUMBER=1;static ELEMENT=2}const wt="19b10000-e8f2-537e-4f6c-d104768a1214",Jt="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",te="998ff920-81af-42a9-a915-f88025f9647d",ee={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[wt]};function W(){return{serviceUuid:wt,messageCharUuid:Jt,handshakeCharUuid:te,options:ee}}class At{id;data;constructor(e,n){this.id=e,this.data=n}}const{serviceUuid:ne,messageCharUuid:re}=W(),mt=new U.SyncEvent,Ct=new U.SyncEvent,St=new U.SyncEvent,bt=new U.SyncEvent;function se(){return new Promise((t,e)=>{G().subscribe(ne,re,ie).then(()=>t()).catch(n=>e(n))})}function ie(t){t!==void 0&&(t.getUint8(q.TYPE)===b.BUTTON_PRESS&&oe(t),t.getUint8(q.TYPE)===b.MESSAGE_DONE&&bt.post(t.getUint8(q.DATA)))}function oe(t){const e=t.getUint8(q.DATA),n=new At(t.getUint8(q.ID),ae(t));e===Z.MINUS&&Ct.post(n),e===Z.PLUS&&mt.post(n),e===Z.EITHER&&St.post(n)}function ae(t){const e=t.buffer,n=7,r=t.byteLength-7;return Array.from(new Uint8Array(e,n,r)).map(f=>String.fromCharCode(f)).join("").replace(/\0/g,"").trim()}function Tt(){return{subscribe:se,onPlus:mt,onMin:Ct,onEither:St,onMessageDone:bt}}const{serviceUuid:ue,handshakeCharUuid:ce}=W(),Dt=new U.SyncEvent,Ut=new U.SyncEvent;function he(){return new Promise((t,e)=>{G().subscribe(ue,ce,le).then(()=>t()).catch(n=>e(n))})}function le(t){t.getUint8(q.TYPE)===Et.CONNECT&&Dt.post(t),t.getUint8(q.TYPE)===Et.DISCONNECT&&Ut.post(t)}function J(){return{subscribe:he,onConnected:Dt,onDisconnected:Ut}}const{onConnected:fe}=J(),{onDisconnected:de}=J();function ve(){return new Promise((t,e)=>{G().connect(W().options).then(()=>Promise.all([J().subscribe(),Tt().subscribe()]).then(()=>{t()})).catch(n=>e(n))})}function Ot(){return{connect:ve,onConnected:fe,onDisconnected:de}}const B=[];function ye(){let t=Math.floor(Math.random()*256);for(;B.includes(t);)t=Math.floor(Math.random()*256);return t}function ge(t){B.push(t),pe()}function pe(){B.length<=20||B.splice(0,B.length-20)}function _e(){const t=ye();return ge(t),t}function Ee(){return{create:_e}}const{serviceUuid:we,messageCharUuid:Ae}=W(),{onMessageDone:me}=Tt(),Ce=G(),qt=10,Pt=15,Lt=[],tt=new Map;let N=!1;me.attach(Te);function Se(t,e,n){const r=Ee().create();return be(r,t,e,n).forEach(l=>Lt.push(l)),new Promise(l=>{tt.set(r,l),N||et()})}function be(t,e,n,r){if(r==null)return[new Uint8Array([n,t,qt,0,2,e,0])];const f=new Uint8Array(2+r.length),l=r.length+2,u=[];f.set([e,l],0),f.set(r,2);for(let i=0;i<l;i+=Pt){const a=Math.min(Pt,l-i),h=new Uint8Array(a),o=[n,t,qt,i,l];h.set(f.subarray(i,i+a),0),u.push(new Uint8Array([...o,...h]))}return u}function et(){if(N)return;const t=Lt.shift();if(t==null){N=!1;return}N=!0,Ce.writeCharacteristic(we,Ae,t).catch(e=>console.log(e)).finally(()=>{N=!1,et()})}function Te(t){tt.get(t)?.(),tt.delete(t),et()}function F(){return{write:Se}}const{write:It}=F();function De(t){return{upload:(e,n)=>{const r=new Uint8Array(n.length+1);return r.set([e],0),r.set(n,1),It(b.UPLOAD,t,r)},clear:()=>It(b.CLEAR_GRAPHICS,t)}}const{onConnected:Ue,onDisconnected:Oe}=Ot();Ue.attach(qe),Oe.attach(Pe);const j=[];function qe(t){const e=new Uint8Array(t.buffer,6);for(const n of e)Le(n)}function Pe(t){const e=t.getUint8(2);Ie(e)}function Le(t){j.some(e=>e.id===t)||j.push(new pt(t))}function Ie(t){const e=j.findIndex(n=>n.id===t);e!==-1&&j.splice(e,1)}function Me(){return{standees:j}}class nt{id=0;dirty=!0;_show=!0;_x;_y;_colorBlack=!1;constructor(e,n,r=!0,f=!1){this._x=e,this._y=n,this._show=r,this._colorBlack=f}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this.dirty=!0}set y(e){this._y=e,this.dirty=!0}set show(e){this._show=e,this.dirty=!0}get show(){return this._show}set colorBlack(e){this._colorBlack=e,this.dirty=!0}get colorBlack(){return this._colorBlack}}class Re extends nt{_width;_height;_radius;_fill;constructor(e,n,r,f,l=0,u=!1,i=!0,a=!1){super(e,n,i,a),this._width=r,this._height=f,this._radius=l,this._fill=u}set width(e){this._width=e,this.dirty=!0}set height(e){this._height=e,this.dirty=!0}set radius(e){this._radius=e,this.dirty=!0}set fill(e){this._fill=e,this.dirty=!0}get width(){return this._width}get height(){return this._height}get radius(){return this._radius}get fill(){return this._fill}}let Be=class extends nt{_width;_height;_data;constructor(e,n,r,f,l,u=!0,i=!1){super(e,n,u,i),this._width=r,this._height=f,this._data=l}set width(e){this._width=e,this.dirty=!0}set height(e){this._height=e,this.dirty=!0}set data(e){this._data=e,this.dirty=!0}get width(){return this._width}get height(){return this._height}get data(){return this._data}};class Ne extends nt{_text;_font;_center;constructor(e,n,r,f,l=!1,u=!0,i=!1){super(e,n,u,i),this._text=r,this._font=f,this._center=l}set text(e){this._text=e,this.dirty=!0}set font(e){this._font=e,this.dirty=!0}get text(){return this._text}get font(){return this._font}get center(){return this._center}set center(e){this._center=e,this.dirty=!0}}function je(t){const e=()=>{let r=Math.floor(Math.random()*256);return n(r)?e():r},n=r=>t.some(f=>f.id===r);return{generate:e}}function xe(t){return{add:r=>(r.id=je(t.elements).generate(),t.elements.push(r),r),remove:r=>{t.elements=t.elements.filter(f=>f.id!==r)}}}const{write:Mt}=F();function Qe(t){return Mt(b.CLEAR_SCREEN,t.id)}function Ve(t){let e=new Uint8Array;for(const n of t.elements)n.dirty!==!1&&(n instanceof Be&&(e=rt(e,$e(n))),n instanceof Re&&(e=rt(e,He(n))),n instanceof Ne&&(e=rt(e,ke(n))),n.dirty=!1);return Mt(b.ALL,t.id,e)}function rt(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function $e(t){return new Uint8Array([b.DRAW_IMAGE,7,t.id,t.show?1:0,t.x,t.y,t.width,t.height,t.data])}function He(t){return new Uint8Array([b.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 ke(t){const e=new TextEncoder().encode(t.text),n=new Uint8Array(9+e.length);return n.set([b.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 Ge(){return{clear:Qe,draw:Ve}}function We(t,e){const n=Math.ceil(t.length/e),r=Math.ceil(e/8),f=new Uint8Array(r*n);for(let l=0;l<n;l++)for(let u=0;u<r;u++){let i=0;for(let a=0;a<8;a++){const h=u*8+a,o=l*e+h;h<e&&o<t.length&&t[o]&&(i|=1<<7-a)}f[l*r+u]=Rt(i)}return f}function Rt(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 Fe(t){const e=t.reduce((f,l)=>f+l.length,0),n=new Uint8Array(e);let r=0;for(const f of t)n.set(f,r),r+=f.length;return n}function X(){return{pixelsToBytes:We,bitswap:Rt,flattenUint8Arrays:Fe}}const{flattenUint8Arrays:Bt}=X();class O{element_id;property;constructor(e,n){this.element_id=e,this.property=n}}class T{target;constructor(e){this.target=e}format(){return new Uint8Array}}class Xe extends T{format(){return new Uint8Array([S.INCREMENT,2,this.target.element_id,this.target.property])}}class Ye extends T{format(){return new Uint8Array([S.DECREMENT,2,this.target.element_id,this.target.property])}}class Ke extends T{format(){return new Uint8Array([S.SHOW,1,this.target.element_id])}}class ze extends T{format(){return new Uint8Array([S.HIDE,1,this.target.element_id])}}class Ze extends T{value;constructor(e,n){super(e),this.value=n}format(){const e=this.dataType(),n=this.convertValue(e),r=new Uint8Array(5+n.length),f=[S.SET,n.length+3,e,this.target.element_id,this.target.property];return r.set(f,0),r.set(n,5),r}dataType(){return typeof this.value==="string"?P.STRING:P.NUMBER}convertValue(e){return e===P.STRING?new TextEncoder().encode(this.value):e===P.NUMBER?new Uint8Array([this.value]):new Uint8Array}}class Je extends T{format(){return this.target.element_id!==0&&this.target.property!==0?new Uint8Array([S.BROADCAST,2,this.target.element_id,this.target.property]):new Uint8Array([S.BROADCAST,0])}}class tn extends T{format(){return new Uint8Array([S.BREAK,0])}}let en=class extends T{fromLow;fromHigh;toLow;toHigh;value;constructor(e,n,r,f,l,u){super(u),this.value=e,this.fromLow=n,this.fromHigh=r,this.toLow=f,this.toHigh=l}format(){return new Uint8Array([S.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 nn extends T{deciseconds;resetable;onComplete;constructor(e,n,r){super(new O(0,0)),this.deciseconds=e,this.resetable=n,this.onComplete=r}format(){const e=Bt(this.onComplete.map(f=>f.format())),n=new Uint8Array(4+e.length),r=[S.TIMER,e.length+2,this.resetable?1:0,this.deciseconds];return n.set(r,0),e.forEach((f,l)=>n.set([f],l+4)),n}}class rn extends T{left;operator;right;actions;constructor(e,n,r,f){super(new O(0,0)),this.actions=f,this.left=e,this.operator=n,this.right=r}convertValue(e){if(typeof e=="number")return new Uint8Array([P.NUMBER,1,e]);if(typeof e=="string"){const n=new TextEncoder().encode(e);return new Uint8Array([P.STRING,n.length,...n])}return e instanceof O?new Uint8Array([P.ELEMENT,2,e.element_id,e.property]):new Uint8Array}format(){const e=Bt(this.actions.map(i=>i.format())),n=this.convertValue(this.left),r=this.convertValue(this.right),f=4+n.length+r.length+e.length,l=new Uint8Array(f),u=[S.CONDITION,f-2,n.length+r.length+1];return l.set(u,0),l.set([this.operator],3),l.set(n,4),l.set(r,4+n.length),l.set(e,4+n.length+r.length),l}}function sn(){return{target(t,e){return new O(t,e)},increment(t){return new Xe(t)},decrement(t){return new Ye(t)},show(t){return new Ke(new O(t,0))},hide(t){return new ze(new O(t,0))},set(t,e){return new Ze(t,e)},broadcast(t){return new Je(t||new O(0,0))},timer(t,e,n){return new nn(t,e,n)},stop(){return new tn(new O(0,0))},condition(t,e,n,r){return new rn(t,e,n,r)},map(t,e,n,r,f,l){return new en(t,e,n,r,f,l)}}}const{write:on}=F(),{flattenUint8Arrays:an}=X();function un(t){return{setButton(e,n){const r=an(n.map(l=>l.format())),f=new Uint8Array(1+r.length);return f.set([e],0),r.forEach((l,u)=>f.set([l],u+1)),on(b.ACTIONS,t.id,f)}}}function cn(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=n,r.src=t})}function hn(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 ln(t){const e=[],n=t.data,r=t.width,f=t.height;for(let l=0;l<f;l++)for(let u=0;u<r;u++){const i=(l*r+u)*4,a=n[i],h=n[i+1],o=n[i+2],s=.2126*a+.7152*h+.0722*o;e.push(s<128?0:1)}return{width:r,height:f,pixels:e}}function Nt(){return{createImage:cn,getImageData:hn,imageDataToPixels:ln}}const{createImage:fn,getImageData:dn,imageDataToPixels:vn}=Nt(),{pixelsToBytes:yn}=X();function gn(t){return new Promise((e,n)=>{fn(t).then(r=>dn(r)).then(r=>vn(r)).then(r=>yn(r.pixels,r.width)).then(r=>e(r)).catch(r=>n(r))})}function pn(){return{imageToBytes:gn}}function _n(t,e,n,r,f){return(t-e)/(n-e)*(f-r)+r}function En(){return{map:_n}}g.ButtonResult=At,g.Standee=pt,g.useActions=sn,g.useBinary=X,g.useButtons=un,g.useConverter=pn,g.useDisplay=Ge,g.useImage=Nt,g.useMesh=Ot,g.useMeshUpload=De,g.useMeshWriter=F,g.useStandeeElements=xe,g.useStandees=Me,g.useUtils=En,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(g,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(g=typeof globalThis<"u"?globalThis:g||self,w(g["nsd-ble"]={}))})(this,(function(g){"use strict";var w={},I={},ut;function x(){if(ut)return I;ut=1,Object.defineProperty(I,"__esModule",{value:!0}),I.BaseEvent=void 0;var t=(function(){function e(){}return e.prototype.attach=function(n,r){return this._attach(n,r,!1)},e.prototype.once=function(n,r){return this._attach(n,r,!0)},e.prototype._attach=function(n,r,f){var l=this,u,i,a,h;if(typeof n=="function")i=n,h=function(){return l.detach(i)};else if(!r&&typeof n.post=="function")a=n,h=function(){return l.detach(a)};else{if(typeof n!="object"||n===void 0)throw new Error("Expect a function or object as first argument");if(typeof r!="function")throw new Error("Expect a function as second argument");u=n,i=r,h=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:a,once:f}),h},e.prototype.detach=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];this._detach.apply(this,n)},e.prototype._detach=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];if(!(!this._listeners||this._listeners.length===0)){var f,l,u;n.length>=1&&(typeof n[0]=="function"?l=n[0]:n.length===1&&typeof n[0].post=="function"?u=n[0]:f=n[0]),n.length>=2&&(l=n[1]),this._listeners=this._listeners.filter(function(i){return(typeof l>"u"||i.handler===l)&&(typeof u>"u"||i.event===u)&&(typeof f>"u"||i.boundTo===f)?(i.deleted=!0,!1):!0}),this._listeners.length===0&&delete this._listeners}},e.prototype.post=function(n){throw new Error("abstract")},e.prototype.listenerCount=function(){return this._listeners?this._listeners.length:0},e.prototype._call=function(n,r){this._listeners&&(n.deleted||(n.once&&(n.deleted=!0,this._listeners=this._listeners.filter(function(f){return f!==n}),this._listeners.length===0&&delete this._listeners),n.event?n.event.post.apply(n.event,r):n.handler&&n.handler.apply(typeof n.boundTo=="object"?n.boundTo:this,r)))},e})();return I.BaseEvent=t,I}var m={},ct;function L(){if(ct)return m;ct=1;var t=m&&m.__extends||(function(){var l=function(u,i){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,h){a.__proto__=h}||function(a,h){for(var o in h)h.hasOwnProperty(o)&&(a[o]=h[o])},l(u,i)};return function(u,i){l(u,i);function a(){this.constructor=u}u.prototype=i===null?Object.create(i):(a.prototype=i.prototype,new a)}})();Object.defineProperty(m,"__esModule",{value:!0}),m.ErrorSyncEvent=m.VoidSyncEvent=m.SyncEvent=void 0;var e=x(),n=(function(l){t(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 r),this._listenersChanged},enumerable:!1,configurable:!0}),u.prototype.post=function(){for(var i=[],a=0;a<arguments.length;a++)i[a]=arguments[a];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 h=this._listeners,o=0;o<h.length;++o){var s=h[o];this._call(s,i)}this._recursion--}},u.prototype._attach=function(i,a,h){var o,s,c,d,v=(s=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&s!==void 0?s:0,y=l.prototype._attach.call(this,i,a,h);return this.evtListenersChanged&&v!==((d=(c=this._listeners)===null||c===void 0?void 0:c.length)!==null&&d!==void 0?d:0)&&this.evtListenersChanged.post(),y},u.prototype._detach=function(){for(var i,a,h,o,s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];var d=(a=(i=this._listeners)===null||i===void 0?void 0:i.length)!==null&&a!==void 0?a:0,v=l.prototype._detach.apply(this,s);return this.evtListenersChanged&&d!==((o=(h=this._listeners)===null||h===void 0?void 0:h.length)!==null&&o!==void 0?o:0)&&this.evtListenersChanged.post(),v},u.MAX_RECURSION_DEPTH=10,u})(e.BaseEvent);m.SyncEvent=n;var r=(function(l){t(u,l);function u(){return l!==null&&l.apply(this,arguments)||this}return u.prototype.post=function(){l.prototype.post.call(this,void 0)},u})(n);m.VoidSyncEvent=r;var f=(function(l){t(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})(n);return m.ErrorSyncEvent=f,m}var A={},V={},ht;function K(){if(ht)return V;ht=1,Object.defineProperty(V,"__esModule",{value:!0});var t=L(),e=(function(){function n(){this.evtFilled=new t.SyncEvent,this.evtDrained=new t.SyncEvent,this._queue=[],this._flushing=!1}return n.global=function(){return n._instance||n.resetGlobal(),n._instance},n.resetGlobal=function(){n._instance=new n},n.prototype.empty=function(){return this._queue.length===0},n.prototype.add=function(r){this._queue.push(r),this._queue.length===1&&!this._flushing&&this.evtFilled.post(this)},n.prototype.flushOnce=function(){var r=this._queue.length===0,f=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=f,!r&&!f&&this._queue.length===0&&this.evtDrained.post(this)}},n.prototype.flush=function(r){r===void 0&&(r=10);var f=this._queue.length===0,l=this._flushing;this._flushing=!0;try{for(var u=0;this._queue.length>0;){if(typeof r=="number"&&u>=r)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,!f&&!l&&this._queue.length===0&&this.evtDrained.post(this)}},n})();return V.default=e,V}var lt;function ft(){if(lt)return A;lt=1;var t=A&&A.__extends||(function(){var i=function(a,h){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,s){o.__proto__=s}||function(o,s){for(var c in s)s.hasOwnProperty(c)&&(o[c]=s[c])},i(a,h)};return function(a,h){i(a,h);function o(){this.constructor=a}a.prototype=h===null?Object.create(h):(o.prototype=h.prototype,new o)}})();Object.defineProperty(A,"__esModule",{value:!0}),A.ErrorQueuedEvent=A.VoidQueuedEvent=A.QueuedEvent=void 0;var e=x(),n=K(),r=L(),f=(function(i){t(a,i);function a(h){h===void 0&&(h={});var o=i.call(this)||this;return o._queued=!1,o.options=h,typeof h.condensed=="boolean"?o._condensed=h.condensed:o._condensed=!1,typeof h.queue=="object"&&h.queue!==null&&(o._queue=h.queue),o}return Object.defineProperty(a.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new r.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),a.prototype.post=function(){for(var h=this,o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];if(!(!this._listeners||this._listeners.length===0)){var c=this._queue?this._queue:n.default.global();if(this._condensed){if(this._queuedData=o,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,c.add(function(){h._queued=!1;for(var v=h._queuedData,y=h._queuedListeners,p=0;p<y.length;++p){var _=y[p];h._call(_,v)}})}else{var d=this._listeners;c.add(function(){for(var v=0;v<d.length;++v){var y=d[v];h._call(y,o)}})}}},a.prototype._attach=function(h,o,s){var c,d,v,y,p=(d=(c=this._listeners)===null||c===void 0?void 0:c.length)!==null&&d!==void 0?d:0,_=i.prototype._attach.call(this,h,o,s);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(),_},a.prototype._detach=function(){for(var h,o,s,c,d=[],v=0;v<arguments.length;v++)d[v]=arguments[v];var y=(o=(h=this._listeners)===null||h===void 0?void 0:h.length)!==null&&o!==void 0?o:0,p=i.prototype._detach.apply(this,d);return this.evtListenersChanged&&y!==((c=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&c!==void 0?c:0)&&this.evtListenersChanged.post(),p},a})(e.BaseEvent);A.QueuedEvent=f;var l=(function(i){t(a,i);function a(){return i!==null&&i.apply(this,arguments)||this}return a.prototype.post=function(){i.prototype.post.call(this,void 0)},a})(f);A.VoidQueuedEvent=l;var u=(function(i){t(a,i);function a(){return i!==null&&i.apply(this,arguments)||this}return a.prototype.post=function(h){if(!this._listeners||this._listeners.length===0)throw new Error("error event posted while no listeners attached. Error: "+h.message);i.prototype.post.call(this,h)},a})(f);return A.ErrorQueuedEvent=u,A}var C={},dt;function vt(){if(dt)return C;dt=1;var t=C&&C.__extends||(function(){var u=function(i,a){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(h,o){h.__proto__=o}||function(h,o){for(var s in o)o.hasOwnProperty(s)&&(h[s]=o[s])},u(i,a)};return function(i,a){u(i,a);function h(){this.constructor=i}i.prototype=a===null?Object.create(a):(h.prototype=a.prototype,new h)}})();Object.defineProperty(C,"__esModule",{value:!0}),C.ErrorAsyncEvent=C.VoidAsyncEvent=C.AsyncEvent=void 0;var e=x(),n=L(),r=(function(u){t(i,u);function i(a){a===void 0&&(a={});var h=u.call(this)||this;return h._queued=!1,h.options=a,typeof a.condensed=="boolean"?h._condensed=a.condensed:h._condensed=!1,h}return Object.defineProperty(i.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new n.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),i.defaultScheduler=function(a){typeof window<"u"?setTimeout(a,0):setImmediate(a)},i.setScheduler=function(a){i._scheduler=a},i.prototype.post=function(){for(var a=this,h=[],o=0;o<arguments.length;o++)h[o]=arguments[o];if(!(!this._listeners||this._listeners.length===0))if(this._condensed){if(this._queuedData=h,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,i._scheduler(function(){a._queued=!1;for(var c=a._queuedData,d=a._queuedListeners,v=0;v<d.length;++v){var y=d[v];a._call(y,c)}})}else{var s=this._listeners;i._scheduler(function(){for(var c=0;c<s.length;++c){var d=s[c];a._call(d,h)}})}},i.prototype._call=function(a,h){a.event&&a.event instanceof i?a.event._postDirect(h):u.prototype._call.call(this,a,h)},i.prototype._postDirect=function(a){if(!(!this._listeners||this._listeners.length===0))for(var h=this._listeners,o=0;o<h.length;++o){var s=h[o];this._call(s,a)}},i.prototype._attach=function(a,h,o){var s,c,d,v,y=(c=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&c!==void 0?c:0,p=u.prototype._attach.call(this,a,h,o);return this.evtListenersChanged&&y!==((v=(d=this._listeners)===null||d===void 0?void 0:d.length)!==null&&v!==void 0?v:0)&&this.evtListenersChanged.post(),p},i.prototype._detach=function(){for(var a,h,o,s,c=[],d=0;d<arguments.length;d++)c[d]=arguments[d];var v=(h=(a=this._listeners)===null||a===void 0?void 0:a.length)!==null&&h!==void 0?h:0,y=u.prototype._detach.apply(this,c);return this.evtListenersChanged&&v!==((s=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&s!==void 0?s:0)&&this.evtListenersChanged.post(),y},i._scheduler=i.defaultScheduler,i})(e.BaseEvent);C.AsyncEvent=r;var f=(function(u){t(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})(r);C.VoidAsyncEvent=f;var l=(function(u){t(i,u);function i(){return u!==null&&u.apply(this,arguments)||this}return i.prototype.post=function(a){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+a.message);u.prototype.post.call(this,a)},i})(r);return C.ErrorAsyncEvent=l,C}var M={},R={},yt;function Wt(){if(yt)return R;yt=1,Object.defineProperty(R,"__esModule",{value:!0}),R.shallowEquals=void 0;function t(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;switch(typeof e){case"boolean":case"number":case"string":case"function":case"symbol":case"undefined":return!1;case"object":if(e===null||n===null)return!1;if(Array.isArray(e)||Array.isArray(n)){if(!Array.isArray(e)||!Array.isArray(n)||e.length!==n.length)return!1;for(var r=0;r<e.length;++r)if(e[r]!==n[r])return!1;return!0}var f=[],l=[];for(var u in e)e.hasOwnProperty(u)&&f.push(u);for(var i in n)n.hasOwnProperty(i)&&l.push(i);if(f.sort(),l.sort(),f.join(",")!==l.join(","))return!1;for(var r=0;r<f.length;++r)if(e[f[r]]!==n[f[r]])return!1;return!0;default:return!1}}return R.shallowEquals=t,R}var gt;function Ft(){return gt||(gt=1,(function(t){var e=M&&M.__extends||(function(){var o=function(s,c){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,v){d.__proto__=v}||function(d,v){for(var y in v)v.hasOwnProperty(y)&&(d[y]=v[y])},o(s,c)};return function(s,c){o(s,c);function d(){this.constructor=s}s.prototype=c===null?Object.create(c):(d.prototype=c.prototype,new d)}})();Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorAnyEvent=t.VoidAnyEvent=t.AnyEvent=t.EventType=void 0;var n=Wt(),r=L(),f=vt(),l=ft(),u;(function(o){o[o.Sync=0]="Sync",o[o.Async=1]="Async",o[o.Queued=2]="Queued"})(u=t.EventType||(t.EventType={}));var i=(function(){function o(s){this._events=[],s&&s.monitorAttach&&(this.evtFirstAttached=new a,this.evtLastDetached=new a)}return Object.defineProperty(o.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new r.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),o.prototype.attach=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];var d=u.Sync;s.length>0&&typeof s[0]=="number"&&(d=s.shift());var v=this,y,p,_;return typeof s[0]=="function"||s[0]&&typeof s[0]=="object"&&typeof s[0].post=="function"?(typeof s[0]=="function"?y=s[0]:_=s[0],p=s[1]):(v=s[0],y=s[1],p=s[2]),this._attach(d,v,y,_,p,!1)},o.prototype.once=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];var d=u.Sync;s.length>0&&typeof s[0]=="number"&&(d=s.shift());var v=this,y,p,_;return typeof s[0]=="function"||s[0]&&typeof s[0]=="object"&&typeof s[0].post=="function"?(typeof s[0]=="function"?y=s[0]:_=s[0],p=s[1]):(v=s[0],y=s[1],p=s[2]),this._attach(d,v,y,_,p,!0)},o.prototype._attach=function(s,c,d,v,y,p){var _=this,Vt=this.evtFirstAttached?this.listenerCount():0,E;switch(s){case u.Sync:{for(var it=0,$t=this._events;it<$t.length;it++){var D=$t[it];D instanceof r.SyncEvent&&(E=D)}E||(E=new r.SyncEvent,this._events.push(E))}break;case u.Async:{for(var ot=0,Ht=this._events;ot<Ht.length;ot++){var D=Ht[ot];D instanceof f.AsyncEvent&&n.shallowEquals(D.options,y)&&(E=D)}E||(E=new f.AsyncEvent(y),this._events.push(E))}break;case u.Queued:{for(var at=0,kt=this._events;at<kt.length;at++){var D=kt[at];D instanceof l.QueuedEvent&&n.shallowEquals(D.options,y)&&(E=D)}E||(E=new l.QueuedEvent(y),this._events.push(E))}break;default:throw new Error("unknown EventType")}var Q;return p?v?Q=E.once(v):Q=E.once(c,d):v?Q=E.attach(v):Q=E.attach(c,d),this.evtFirstAttached&&Vt===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&Vt!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var Gt=_.evtLastDetached?_.listenerCount():0;Q(),_.evtLastDetached&&Gt>0&&_.listenerCount()===0&&_.evtLastDetached.post(),_.evtListenersChanged&&Gt!==_.listenerCount()&&_.evtListenersChanged.post()}},o.prototype.attachSync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Sync),this.attach.apply(this,s)},o.prototype.onceSync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Sync),this.once.apply(this,s)},o.prototype.attachAsync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Async),this.attach.apply(this,s)},o.prototype.onceAsync=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Async),this.once.apply(this,s)},o.prototype.attachQueued=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Queued),this.attach.apply(this,s)},o.prototype.onceQueued=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];return s.unshift(u.Queued),this.once.apply(this,s)},o.prototype.detach=function(){for(var s=[],c=0;c<arguments.length;c++)s[c]=arguments[c];for(var d=this.listenerCount(),v=0;v<this._events.length;++v)this._events[v].detach.apply(this._events[v],s);this.evtListenersChanged&&d!==this.listenerCount()&&this.evtListenersChanged.post(),this.evtLastDetached&&d>0&&this.listenerCount()===0&&this.evtLastDetached.post()},o.prototype.post=function(s){for(var c=[],d=0;d<this._events.length;++d)c.push(this._events[d]);for(var d=0;d<c.length;++d)c[d].post(s)},o.prototype.listenerCount=function(){for(var s=0,c=0;c<this._events.length;++c)s+=this._events[c].listenerCount();return s},o})();t.AnyEvent=i;var a=(function(o){e(s,o);function s(){return o!==null&&o.apply(this,arguments)||this}return s.prototype.post=function(){o.prototype.post.call(this,void 0)},s})(i);t.VoidAnyEvent=a;var h=(function(o){e(s,o);function s(){return o!==null&&o.apply(this,arguments)||this}return s.prototype.post=function(c){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+c.message);o.prototype.post.call(this,c)},s})(i);t.ErrorAnyEvent=h})(M)),M}var pt;function Xt(){return pt||(pt=1,(function(t){var e=w&&w.__createBinding||(Object.create?(function(a,h,o,s){s===void 0&&(s=o),Object.defineProperty(a,s,{enumerable:!0,get:function(){return h[o]}})}):(function(a,h,o,s){s===void 0&&(s=o),a[s]=h[o]})),n=w&&w.__exportStar||function(a,h){for(var o in a)o!=="default"&&!h.hasOwnProperty(o)&&e(h,a,o)};Object.defineProperty(t,"__esModule",{value:!0}),t.flush=t.flushOnce=t.queue=void 0,n(x(),t),n(L(),t),n(ft(),t),n(vt(),t),n(Ft(),t);var r=K(),f=K();Object.defineProperty(t,"EventQueue",{enumerable:!0,get:function(){return f.default}});function l(){return r.default.global()}t.queue=l;function u(){r.default.global().flushOnce()}t.flushOnce=u;function i(a){a===void 0&&(a=10),r.default.global().flush(a)}t.flush=i})(w)),w}var U=Xt();class _t{id;elements=[];onPlus=new U.SyncEvent;onMin=new U.SyncEvent;constructor(e){this.id=e}name(){return this.id.toString(16).padStart(2,"0")}}let z=!1,$=[],H,Et,k=new Map;async function Yt(t){try{if(H=await navigator.bluetooth.requestDevice(t),H.gatt===void 0)throw new Error("Device does not support GATT");Et=await H.gatt.connect(),H.addEventListener("gattserverdisconnected",Kt),z=!0}catch(e){throw e}}function Kt(){k.clear(),z=!1,$.forEach(t=>t())}function zt(t){$.push(t)}function Zt(t){$=$.filter(e=>e!==t)}async function Z(t,e){if(k.has(e)){const f=k.get(e);if(f===void 0)throw new Error("Characteristic not found");return f}const r=await(await Et.getPrimaryService(t)).getCharacteristic(e);return k.set(e,r),r}async function Jt(t,e){return await(await Z(t,e)).readValue()}async function te(t,e,n){const r=new DataView(new ArrayBuffer(n.length));r.setUint8(0,n[0]),await(await Z(t,e)).writeValue(r)}async function ee(t,e,n){const r=await Z(t,e);r.addEventListener("characteristicvaluechanged",f=>{let l=f.target.value;l===void 0&&(l=new DataView(new ArrayBuffer(0))),n(l)}),await r.startNotifications()}function G(){return{connected:z,connect:Yt,readCharacteristic:Jt,writeCharacteristic:te,subscribe:ee,setDisconnectCallback:zt,removeDisconnectCallback:Zt}}class wt{static CONNECT=0;static DISCONNECT=1}class b{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 q{static ID=0;static CACHE=1;static TTL=2;static POSITION=3;static DATA_SIZE=4;static TYPE=5;static DATA=6}class J{static MINUS=0;static PLUS=1;static EITHER=2}class S{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 P{static STRING=0;static NUMBER=1;static ELEMENT=2}const mt="19b10000-e8f2-537e-4f6c-d104768a1214",ne="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",re="998ff920-81af-42a9-a915-f88025f9647d",se={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[mt]};function W(){return{serviceUuid:mt,messageCharUuid:ne,handshakeCharUuid:re,options:se}}class At{id;data;constructor(e,n){this.id=e,this.data=n}}const{serviceUuid:ie,messageCharUuid:oe}=W(),Ct=new U.SyncEvent,St=new U.SyncEvent,bt=new U.SyncEvent,Tt=new U.SyncEvent;function ae(){return new Promise((t,e)=>{G().subscribe(ie,oe,ue).then(()=>t()).catch(n=>e(n))})}function ue(t){t!==void 0&&(t.getUint8(q.TYPE)===b.BUTTON_PRESS&&ce(t),t.getUint8(q.TYPE)===b.MESSAGE_DONE&&Tt.post(t.getUint8(q.DATA)))}function ce(t){const e=t.getUint8(q.DATA),n=new At(t.getUint8(q.ID),he(t));e===J.MINUS&&St.post(n),e===J.PLUS&&Ct.post(n),e===J.EITHER&&bt.post(n)}function he(t){const e=t.buffer,n=7,r=t.byteLength-7;return Array.from(new Uint8Array(e,n,r)).map(f=>String.fromCharCode(f)).join("").replace(/\0/g,"").trim()}function tt(){return{subscribe:ae,onPlus:Ct,onMin:St,onEither:bt,onMessageDone:Tt}}const{serviceUuid:le,handshakeCharUuid:fe}=W(),Dt=new U.SyncEvent,Ut=new U.SyncEvent;function de(){return new Promise((t,e)=>{G().subscribe(le,fe,ve).then(()=>t()).catch(n=>e(n))})}function ve(t){t.getUint8(q.TYPE)===wt.CONNECT&&Dt.post(t),t.getUint8(q.TYPE)===wt.DISCONNECT&&Ut.post(t)}function et(){return{subscribe:de,onConnected:Dt,onDisconnected:Ut}}const{onConnected:ye}=et(),{onDisconnected:ge}=et();function pe(){return new Promise((t,e)=>{G().connect(W().options).then(()=>Promise.all([et().subscribe(),tt().subscribe()]).then(()=>{t()})).catch(n=>e(n))})}function Ot(){return{connect:pe,onConnected:ye,onDisconnected:ge}}const B=[];function _e(){let t=Math.floor(Math.random()*256);for(;B.includes(t);)t=Math.floor(Math.random()*256);return t}function Ee(t){B.push(t),we()}function we(){B.length<=20||B.splice(0,B.length-20)}function me(){const t=_e();return Ee(t),t}function Ae(){return{create:me}}const{serviceUuid:Ce,messageCharUuid:Se}=W(),{onMessageDone:be}=tt(),Te=G(),qt=10,Pt=15,It=[],nt=new Map;let N=!1;be.attach(Oe);function De(t,e,n){const r=Ae().create();return Ue(r,t,e,n).forEach(l=>It.push(l)),new Promise(l=>{nt.set(r,l),N||rt()})}function Ue(t,e,n,r){if(r==null)return[new Uint8Array([n,t,qt,0,2,e,0])];const f=new Uint8Array(2+r.length),l=r.length+2,u=[];f.set([e,l],0),f.set(r,2);for(let i=0;i<l;i+=Pt){const a=Math.min(Pt,l-i),h=new Uint8Array(a),o=[n,t,qt,i,l];h.set(f.subarray(i,i+a),0),u.push(new Uint8Array([...o,...h]))}return u}function rt(){if(N)return;const t=It.shift();if(t==null){N=!1;return}N=!0,Te.writeCharacteristic(Ce,Se,t).catch(e=>console.log(e)).finally(()=>{N=!1,rt()})}function Oe(t){nt.get(t)?.(),nt.delete(t),rt()}function F(){return{write:De}}const{write:Lt}=F();function qe(t){return{upload:(e,n)=>{const r=new Uint8Array(n.length+1);return r.set([e],0),r.set(n,1),Lt(b.UPLOAD,t,r)},clear:()=>Lt(b.CLEAR_GRAPHICS,t)}}const{onConnected:Pe,onDisconnected:Ie}=Ot();Pe.attach(Le),Ie.attach(Me);const j=[];function Le(t){const e=new Uint8Array(t.buffer,6);for(const n of e)Re(n)}function Me(t){const e=t.getUint8(2);Be(e)}function Re(t){j.some(e=>e.id===t)||j.push(new _t(t))}function Be(t){const e=j.findIndex(n=>n.id===t);e!==-1&&j.splice(e,1)}function Ne(){return{standees:j}}class X{id=0;dirty=!0;_show=!0;_x;_y;_colorBlack=!1;constructor(e,n,r=!0,f=!1){this._x=e,this._y=n,this._show=r,this._colorBlack=f}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this.dirty=!0}set y(e){this._y=e,this.dirty=!0}set show(e){this._show=e,this.dirty=!0}get show(){return this._show}set colorBlack(e){this._colorBlack=e,this.dirty=!0}get colorBlack(){return this._colorBlack}}class Mt extends X{_width;_height;_radius;_fill;constructor(e,n,r,f,l=0,u=!1,i=!0,a=!1){super(e,n,i,a),this._width=r,this._height=f,this._radius=l,this._fill=u}set width(e){this._width=e,this.dirty=!0}set height(e){this._height=e,this.dirty=!0}set radius(e){this._radius=e,this.dirty=!0}set fill(e){this._fill=e,this.dirty=!0}get width(){return this._width}get height(){return this._height}get radius(){return this._radius}get fill(){return this._fill}}let Rt=class extends X{_width;_height;_data;constructor(e,n,r,f,l,u=!0,i=!1){super(e,n,u,i),this._width=r,this._height=f,this._data=l}set width(e){this._width=e,this.dirty=!0}set height(e){this._height=e,this.dirty=!0}set data(e){this._data=e,this.dirty=!0}get width(){return this._width}get height(){return this._height}get data(){return this._data}};class Bt extends X{_text;_font;_center;constructor(e,n,r,f,l=!1,u=!0,i=!1){super(e,n,u,i),this._text=r,this._font=f,this._center=l}set text(e){this._text=e,this.dirty=!0}set font(e){this._font=e,this.dirty=!0}get text(){return this._text}get font(){return this._font}get center(){return this._center}set center(e){this._center=e,this.dirty=!0}}function je(t){const e=()=>{let r=Math.floor(Math.random()*256);return n(r)?e():r},n=r=>t.some(f=>f.id===r);return{generate:e}}function Qe(t){return{add:r=>(r.id=je(t.elements).generate(),t.elements.push(r),r),remove:r=>{t.elements=t.elements.filter(f=>f.id!==r)}}}const{write:Nt}=F();function xe(t){return Nt(b.CLEAR_SCREEN,t.id)}function Ve(t){let e=new Uint8Array;for(const n of t.elements)n.dirty!==!1&&(n instanceof Rt&&(e=st(e,$e(n))),n instanceof Mt&&(e=st(e,He(n))),n instanceof Bt&&(e=st(e,ke(n))),n.dirty=!1);return Nt(b.ALL,t.id,e)}function st(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function $e(t){return new Uint8Array([b.DRAW_IMAGE,7,t.id,t.show?1:0,t.x,t.y,t.width,t.height,t.data])}function He(t){return new Uint8Array([b.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 ke(t){const e=new TextEncoder().encode(t.text),n=new Uint8Array(9+e.length);return n.set([b.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 Ge(){return{clear:xe,draw:Ve}}function We(t,e){const n=Math.ceil(t.length/e),r=Math.ceil(e/8),f=new Uint8Array(r*n);for(let l=0;l<n;l++)for(let u=0;u<r;u++){let i=0;for(let a=0;a<8;a++){const h=u*8+a,o=l*e+h;h<e&&o<t.length&&t[o]&&(i|=1<<7-a)}f[l*r+u]=jt(i)}return f}function jt(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 Fe(t){const e=t.reduce((f,l)=>f+l.length,0),n=new Uint8Array(e);let r=0;for(const f of t)n.set(f,r),r+=f.length;return n}function Y(){return{pixelsToBytes:We,bitswap:jt,flattenUint8Arrays:Fe}}const{flattenUint8Arrays:Qt}=Y();class O{element_id;property;constructor(e,n){this.element_id=e,this.property=n}}class T{target;constructor(e){this.target=e}format(){return new Uint8Array}}class Xe extends T{format(){return new Uint8Array([S.INCREMENT,2,this.target.element_id,this.target.property])}}class Ye extends T{format(){return new Uint8Array([S.DECREMENT,2,this.target.element_id,this.target.property])}}class Ke extends T{format(){return new Uint8Array([S.SHOW,1,this.target.element_id])}}class ze extends T{format(){return new Uint8Array([S.HIDE,1,this.target.element_id])}}class Ze extends T{value;constructor(e,n){super(e),this.value=n}format(){const e=this.dataType(),n=this.convertValue(e),r=new Uint8Array(5+n.length),f=[S.SET,n.length+3,e,this.target.element_id,this.target.property];return r.set(f,0),r.set(n,5),r}dataType(){return typeof this.value==="string"?P.STRING:P.NUMBER}convertValue(e){return e===P.STRING?new TextEncoder().encode(this.value):e===P.NUMBER?new Uint8Array([this.value]):new Uint8Array}}class Je extends T{format(){return this.target.element_id!==0&&this.target.property!==0?new Uint8Array([S.BROADCAST,2,this.target.element_id,this.target.property]):new Uint8Array([S.BROADCAST,0])}}class tn extends T{format(){return new Uint8Array([S.BREAK,0])}}let en=class extends T{fromLow;fromHigh;toLow;toHigh;value;constructor(e,n,r,f,l,u){super(u),this.value=e,this.fromLow=n,this.fromHigh=r,this.toLow=f,this.toHigh=l}format(){return new Uint8Array([S.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 nn extends T{deciseconds;resetable;onComplete;constructor(e,n,r){super(new O(0,0)),this.deciseconds=e,this.resetable=n,this.onComplete=r}format(){const e=Qt(this.onComplete.map(f=>f.format())),n=new Uint8Array(4+e.length),r=[S.TIMER,e.length+2,this.resetable?1:0,this.deciseconds];return n.set(r,0),e.forEach((f,l)=>n.set([f],l+4)),n}}class rn extends T{left;operator;right;actions;constructor(e,n,r,f){super(new O(0,0)),this.actions=f,this.left=e,this.operator=n,this.right=r}convertValue(e){if(typeof e=="number")return new Uint8Array([P.NUMBER,1,e]);if(typeof e=="string"){const n=new TextEncoder().encode(e);return new Uint8Array([P.STRING,n.length,...n])}return e instanceof O?new Uint8Array([P.ELEMENT,2,e.element_id,e.property]):new Uint8Array}format(){const e=Qt(this.actions.map(i=>i.format())),n=this.convertValue(this.left),r=this.convertValue(this.right),f=4+n.length+r.length+e.length,l=new Uint8Array(f),u=[S.CONDITION,f-2,n.length+r.length+1];return l.set(u,0),l.set([this.operator],3),l.set(n,4),l.set(r,4+n.length),l.set(e,4+n.length+r.length),l}}function sn(){return{target(t,e){return new O(t,e)},increment(t){return new Xe(t)},decrement(t){return new Ye(t)},show(t){return new Ke(new O(t,0))},hide(t){return new ze(new O(t,0))},set(t,e){return new Ze(t,e)},broadcast(t){return new Je(t||new O(0,0))},timer(t,e,n){return new nn(t,e,n)},stop(){return new tn(new O(0,0))},condition(t,e,n,r){return new rn(t,e,n,r)},map(t,e,n,r,f,l){return new en(t,e,n,r,f,l)}}}const{write:on}=F(),{flattenUint8Arrays:an}=Y();function un(t){return{setButton(e,n){const r=an(n.map(l=>l.format())),f=new Uint8Array(1+r.length);return f.set([e],0),r.forEach((l,u)=>f.set([l],u+1)),on(b.ACTIONS,t.id,f)}}}function cn(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=n,r.src=t})}function hn(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 ln(t){const e=[],n=t.data,r=t.width,f=t.height;for(let l=0;l<f;l++)for(let u=0;u<r;u++){const i=(l*r+u)*4,a=n[i],h=n[i+1],o=n[i+2],s=.2126*a+.7152*h+.0722*o;e.push(s<128?0:1)}return{width:r,height:f,pixels:e}}function xt(){return{createImage:cn,getImageData:hn,imageDataToPixels:ln}}const{createImage:fn,getImageData:dn,imageDataToPixels:vn}=xt(),{pixelsToBytes:yn}=Y();function gn(t){return new Promise((e,n)=>{fn(t).then(r=>dn(r)).then(r=>vn(r)).then(r=>yn(r.pixels,r.width)).then(r=>e(r)).catch(r=>n(r))})}function pn(){return{imageToBytes:gn}}function _n(t,e,n,r,f){return(t-e)/(n-e)*(f-r)+r}function En(){return{map:_n}}g.ButtonResult=At,g.DisplayElement=X,g.Image=Rt,g.Rectangle=Mt,g.Standee=_t,g.Text=Bt,g.useActions=sn,g.useBinary=Y,g.useButtons=un,g.useConverter=pn,g.useDisplay=Ge,g.useImage=xt,g.useMesh=Ot,g.useMeshUpload=qe,g.useMeshWriter=F,g.useMessageCharacteristic=tt,g.useStandeeElements=Qe,g.useStandees=Ne,g.useUtils=En,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsd-ble",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"