nsd-ble 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(p,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(p=typeof globalThis<"u"?globalThis:p||self,w(p.StandeeBLE={}))})(this,(function(p){"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,g=0;g<y.length;++g){var _=y[g];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,g=(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&&g!==((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,g=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(),g},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,g=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(),g},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 $t(){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 Ht(){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=$t(),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,g,_;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],g=s[1]):(v=s[0],y=s[1],g=s[2]),this._attach(d,v,y,_,g,!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,g,_;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],g=s[1]):(v=s[0],y=s[1],g=s[2]),this._attach(d,v,y,_,g,!0)},o.prototype._attach=function(s,c,d,v,y,g){var _=this,Nt=this.evtFirstAttached?this.listenerCount():0,E;switch(s){case u.Sync:{for(var st=0,jt=this._events;st<jt.length;st++){var D=jt[st];D instanceof r.SyncEvent&&(E=D)}E||(E=new r.SyncEvent,this._events.push(E))}break;case u.Async:{for(var it=0,xt=this._events;it<xt.length;it++){var D=xt[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,Qt=this._events;ot<Qt.length;ot++){var D=Qt[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 g?v?x=E.once(v):x=E.once(c,d):v?x=E.attach(v):x=E.attach(c,d),this.evtFirstAttached&&Nt===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&Nt!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var Vt=_.evtLastDetached?_.listenerCount():0;x(),_.evtLastDetached&&Vt>0&&_.listenerCount()===0&&_.evtLastDetached.post(),_.evtListenersChanged&&Vt!==_.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 kt(){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(Ht(),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=kt();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 Gt(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",Wt),K=!0}catch(e){throw e}}function Wt(){k.clear(),K=!1,$.forEach(t=>t())}function Ft(t){$.push(t)}function Xt(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 Yt(t,e){return await(await z(t,e)).readValue()}async function Kt(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:Gt,readCharacteristic:Yt,writeCharacteristic:Kt,subscribe:zt,setDisconnectCallback:Ft,removeDisconnectCallback:Xt}}const Et="19b10000-e8f2-537e-4f6c-d104768a1214",Zt="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",Jt="998ff920-81af-42a9-a915-f88025f9647d",te={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[Et]};function W(){return{serviceUuid:Et,messageCharUuid:Zt,handshakeCharUuid:Jt,options:te}}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 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{serviceUuid:ee,handshakeCharUuid:ne}=W(),At=new U.SyncEvent,mt=new U.SyncEvent;function re(){return new Promise((t,e)=>{G().subscribe(ee,ne,se).then(()=>t()).catch(n=>e(n))})}function se(t){t.getUint8(q.TYPE)===wt.CONNECT&&At.post(t),t.getUint8(q.TYPE)===wt.DISCONNECT&&mt.post(t)}function J(){return{subscribe:re,onConnected:At,onDisconnected:mt}}class ie{id;data;constructor(e,n){this.id=e,this.data=n}}const{serviceUuid:oe,messageCharUuid:ae}=W(),Ct=new U.SyncEvent,St=new U.SyncEvent,bt=new U.SyncEvent,Tt=new U.SyncEvent;function ue(){return new Promise((t,e)=>{G().subscribe(oe,ae,ce).then(()=>t()).catch(n=>e(n))})}function ce(t){t!==void 0&&(t.getUint8(q.TYPE)===b.BUTTON_PRESS&&he(t),t.getUint8(q.TYPE)===b.MESSAGE_DONE&&Tt.post(t.getUint8(q.DATA)))}function he(t){const e=t.getUint8(q.DATA),n=new ie(t.getUint8(q.ID),le(t));e===Z.MINUS&&St.post(n),e===Z.PLUS&&Ct.post(n),e===Z.EITHER&&bt.post(n)}function le(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 Dt(){return{subscribe:ue,onPlus:Ct,onMin:St,onEither:bt,onMessageDone:Tt}}const{onConnected:fe}=J(),{onDisconnected:de}=J();function ve(){return new Promise((t,e)=>{G().connect(W().options).then(()=>Promise.all([J().subscribe(),Dt().subscribe()]).then(()=>{t()})).catch(n=>e(n))})}function Ut(){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}=Dt(),Ce=G(),Ot=10,qt=15,Pt=[],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=>Pt.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,Ot,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+=qt){const a=Math.min(qt,l-i),h=new Uint8Array(a),o=[n,t,Ot,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=Pt.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:Lt}=F();function De(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:Ue,onDisconnected:Oe}=Ut();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:It}=F();function Qe(t){return It(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 It(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]=Mt(i)}return f}function Mt(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:Mt,flattenUint8Arrays:Fe}}const{flattenUint8Arrays:Rt}=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=Rt(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=Rt(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 Bt(){return{createImage:cn,getImageData:hn,imageDataToPixels:ln}}const{createImage:fn,getImageData:dn,imageDataToPixels:vn}=Bt(),{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}}p.Standee=pt,p.useActions=sn,p.useBinary=X,p.useButtons=un,p.useConverter=pn,p.useDisplay=Ge,p.useImage=Bt,p.useMesh=Ut,p.useMeshUpload=De,p.useMeshWriter=F,p.useStandeeElements=xe,p.useStandees=Me,p.useUtils=En,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(p,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(p=typeof globalThis<"u"?globalThis:p||self,w(p["nsd-ble"]={}))})(this,(function(p){"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,g=0;g<y.length;++g){var _=y[g];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,g=(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&&g!==((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,g=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(),g},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,g=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(),g},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 $t(){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 Ht(){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=$t(),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,g,_;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],g=s[1]):(v=s[0],y=s[1],g=s[2]),this._attach(d,v,y,_,g,!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,g,_;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],g=s[1]):(v=s[0],y=s[1],g=s[2]),this._attach(d,v,y,_,g,!0)},o.prototype._attach=function(s,c,d,v,y,g){var _=this,Bt=this.evtFirstAttached?this.listenerCount():0,E;switch(s){case u.Sync:{for(var st=0,jt=this._events;st<jt.length;st++){var D=jt[st];D instanceof r.SyncEvent&&(E=D)}E||(E=new r.SyncEvent,this._events.push(E))}break;case u.Async:{for(var it=0,xt=this._events;it<xt.length;it++){var D=xt[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,Qt=this._events;ot<Qt.length;ot++){var D=Qt[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 g?v?x=E.once(v):x=E.once(c,d):v?x=E.attach(v):x=E.attach(c,d),this.evtFirstAttached&&Bt===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&Bt!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var Vt=_.evtLastDetached?_.listenerCount():0;x(),_.evtLastDetached&&Vt>0&&_.listenerCount()===0&&_.evtLastDetached.post(),_.evtListenersChanged&&Vt!==_.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 kt(){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(Ht(),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=kt();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 Gt(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",Wt),K=!0}catch(e){throw e}}function Wt(){k.clear(),K=!1,$.forEach(t=>t())}function Ft(t){$.push(t)}function Xt(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 Yt(t,e){return await(await z(t,e)).readValue()}async function Kt(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:Gt,readCharacteristic:Yt,writeCharacteristic:Kt,subscribe:zt,setDisconnectCallback:Ft,removeDisconnectCallback:Xt}}const Et="19b10000-e8f2-537e-4f6c-d104768a1214",Zt="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",Jt="998ff920-81af-42a9-a915-f88025f9647d",te={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[Et]};function W(){return{serviceUuid:Et,messageCharUuid:Zt,handshakeCharUuid:Jt,options:te}}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 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{serviceUuid:ee,handshakeCharUuid:ne}=W(),At=new U.SyncEvent,mt=new U.SyncEvent;function re(){return new Promise((t,e)=>{G().subscribe(ee,ne,se).then(()=>t()).catch(n=>e(n))})}function se(t){t.getUint8(q.TYPE)===wt.CONNECT&&At.post(t),t.getUint8(q.TYPE)===wt.DISCONNECT&&mt.post(t)}function J(){return{subscribe:re,onConnected:At,onDisconnected:mt}}class ie{id;data;constructor(e,n){this.id=e,this.data=n}}const{serviceUuid:oe,messageCharUuid:ae}=W(),Ct=new U.SyncEvent,St=new U.SyncEvent,bt=new U.SyncEvent,Tt=new U.SyncEvent;function ue(){return new Promise((t,e)=>{G().subscribe(oe,ae,ce).then(()=>t()).catch(n=>e(n))})}function ce(t){t!==void 0&&(t.getUint8(q.TYPE)===b.BUTTON_PRESS&&he(t),t.getUint8(q.TYPE)===b.MESSAGE_DONE&&Tt.post(t.getUint8(q.DATA)))}function he(t){const e=t.getUint8(q.DATA),n=new ie(t.getUint8(q.ID),le(t));e===Z.MINUS&&St.post(n),e===Z.PLUS&&Ct.post(n),e===Z.EITHER&&bt.post(n)}function le(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 Dt(){return{subscribe:ue,onPlus:Ct,onMin:St,onEither:bt,onMessageDone:Tt}}const{onConnected:fe}=J(),{onDisconnected:de}=J();function ve(){return new Promise((t,e)=>{G().connect(W().options).then(()=>Promise.all([J().subscribe(),Dt().subscribe()]).then(()=>{t()})).catch(n=>e(n))})}function Ut(){return{connect:ve,onConnected:fe,onDisconnected:de}}const N=[];function ye(){let t=Math.floor(Math.random()*256);for(;N.includes(t);)t=Math.floor(Math.random()*256);return t}function ge(t){N.push(t),pe()}function pe(){N.length<=20||N.splice(0,N.length-20)}function _e(){const t=ye();return ge(t),t}function Ee(){return{create:_e}}const{serviceUuid:we,messageCharUuid:Ae}=W(),{onMessageDone:me}=Dt(),Ce=G(),Ot=10,qt=15,Pt=[],tt=new Map;let B=!1;me.attach(Te);function Se(t,e,n){const r=Ee().create();return be(r,t,e,n).forEach(l=>Pt.push(l)),new Promise(l=>{tt.set(r,l),B||et()})}function be(t,e,n,r){if(r==null)return[new Uint8Array([n,t,Ot,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+=qt){const a=Math.min(qt,l-i),h=new Uint8Array(a),o=[n,t,Ot,i,l];h.set(f.subarray(i,i+a),0),u.push(new Uint8Array([...o,...h]))}return u}function et(){if(B)return;const t=Pt.shift();if(t==null){B=!1;return}B=!0,Ce.writeCharacteristic(we,Ae,t).catch(e=>console.log(e)).finally(()=>{B=!1,et()})}function Te(t){tt.get(t)?.(),tt.delete(t),et()}function F(){return{write:Se}}const{write:Lt}=F();function De(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:Ue,onDisconnected:Oe}=Ut();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 Ne=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 Be 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:It}=F();function Qe(t){return It(b.CLEAR_SCREEN,t.id)}function Ve(t){let e=new Uint8Array;for(const n of t.elements)n.dirty!==!1&&(n instanceof Ne&&(e=rt(e,$e(n))),n instanceof Re&&(e=rt(e,He(n))),n instanceof Be&&(e=rt(e,ke(n))),n.dirty=!1);return It(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]=Mt(i)}return f}function Mt(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:Mt,flattenUint8Arrays:Fe}}const{flattenUint8Arrays:Rt}=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=Rt(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=Rt(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}}p.Standee=pt,p.useActions=sn,p.useBinary=X,p.useButtons=un,p.useConverter=pn,p.useDisplay=Ge,p.useImage=Nt,p.useMesh=Ut,p.useMeshUpload=De,p.useMeshWriter=F,p.useStandeeElements=xe,p.useStandees=Me,p.useUtils=En,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nsd-ble",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.1.0",
|
|
3
|
+
"version": "0.1.2",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"files": [
|
|
7
6
|
"dist"
|
|
8
7
|
],
|
|
9
|
-
"main": "./dist/
|
|
10
|
-
"module": "./dist/
|
|
8
|
+
"main": "./dist/nsd-ble.umd.cjs",
|
|
9
|
+
"module": "./dist/nsd-ble.js",
|
|
11
10
|
"types": "./dist/types/index.d.ts",
|
|
12
11
|
"exports": {
|
|
13
12
|
".": {
|
|
14
|
-
"import": "./dist/
|
|
15
|
-
"require": "./dist/
|
|
13
|
+
"import": "./dist/nsd-ble.js",
|
|
14
|
+
"require": "./dist/nsd-ble.umd.cjs"
|
|
16
15
|
}
|
|
17
16
|
},
|
|
18
17
|
"scripts": {
|
|
File without changes
|