@camera.ui/browser 0.0.105 → 0.0.106
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/bundle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see bundle.js.LICENSE.txt */
|
|
2
|
-
var t={855:t=>{const e="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,n=()=>e.now(),r=t=>t===1/0||(t=>t&&t===Math.floor(t)&&t>0&&isFinite(t))(t);class i{constructor({max:t=1/0,ttl:e,updateAgeOnGet:n=!1,checkAgeOnGet:i=!1,noUpdateTTL:s=!1,dispose:o,noDisposeOnSet:a=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,void 0!==e&&!r(e))throw new TypeError("ttl must be positive integer or Infinity if set");if(!r(t))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=e,this.max=t,this.updateAgeOnGet=!!n,this.checkAgeOnGet=!!i,this.noUpdateTTL=!!s,this.noDisposeOnSet=!!a,void 0!==o){if("function"!=typeof o)throw new TypeError("dispose must be function if set");this.dispose=o}this.timer=void 0,this.timerExpiration=void 0}setTimer(t,e){if(this.timerExpiration<t)return;this.timer&&clearTimeout(this.timer);const r=setTimeout((()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(const t in this.expirations){this.setTimer(t,t-n());break}}),e);r.unref&&r.unref(),this.timerExpiration=t,this.timer=r}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return process.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){const t=this.dispose!==i.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(const[e,n]of t)this.dispose(n,e,"delete")}setTTL(t,e=this.ttl){const r=this.expirationMap.get(t);if(void 0!==r){const e=this.expirations[r];!e||e.length<=1?delete this.expirations[r]:this.expirations[r]=e.filter((e=>e!==t))}if(e!==1/0){const r=Math.floor(n()+e);this.expirationMap.set(t,r),this.expirations[r]||(this.expirations[r]=[],this.setTimer(r,e)),this.expirations[r].push(t)}else this.expirationMap.set(t,1/0)}set(t,e,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:s=this.noDisposeOnSet}={}){if(!r(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(t)){i||this.setTTL(t,n);const r=this.data.get(t);r!==e&&(this.data.set(t,e),s||this.dispose(r,t,"set"))}else this.setTTL(t,n),this.data.set(t,e);for(;this.size>this.max;)this.purgeToCapacity();return this}has(t){return this.data.has(t)}getRemainingTTL(t){const e=this.expirationMap.get(t);return e===1/0?e:void 0!==e?Math.max(0,Math.ceil(e-n())):0}get(t,{updateAgeOnGet:e=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:r=this.checkAgeOnGet}={}){const i=this.data.get(t);if(!r||0!==this.getRemainingTTL(t))return e&&this.setTTL(t,n),i;this.delete(t)}dispose(t,e){}delete(t){const e=this.expirationMap.get(t);if(void 0!==e){const n=this.data.get(t);this.data.delete(t),this.expirationMap.delete(t);const r=this.expirations[e];return r&&(r.length<=1?delete this.expirations[e]:this.expirations[e]=r.filter((e=>e!==t))),this.dispose(n,t,"delete"),0===this.size&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(const t in this.expirations){const e=this.expirations[t];if(!(this.size-e.length>=this.max)){const t=this.size-this.max,n=[];for(const r of e.splice(0,t))n.push([r,this.data.get(r)]),this.data.delete(r),this.expirationMap.delete(r);for(const[t,e]of n)this.dispose(e,t,"evict");return}{delete this.expirations[t];const n=[];for(const t of e)n.push([t,this.data.get(t)]),this.data.delete(t),this.expirationMap.delete(t);for(const[t,e]of n)this.dispose(e,t,"evict")}}}get size(){return this.data.size}purgeStale(){const t=Math.ceil(n());for(const e in this.expirations){if("Infinity"===e||e>t)return;const n=[...this.expirations[e]||[]],r=[];delete this.expirations[e];for(const t of n)r.push([t,this.data.get(t)]),this.data.delete(t),this.expirationMap.delete(t);for(const[t,e]of r)this.dispose(e,t,"stale")}0===this.size&&this.cancelTimer()}*entries(){for(const t in this.expirations)for(const e of this.expirations[t])yield[e,this.data.get(e)]}*keys(){for(const t in this.expirations)for(const e of this.expirations[t])yield e}*values(){for(const t in this.expirations)for(const e of this.expirations[t])yield this.data.get(e)}[Symbol.iterator](){return this.entries()}}t.exports=i},73:function(t){t.exports=function(){function t(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}var e=function(t,e){this.next=null,this.key=t,this.data=e,this.left=null,this.right=null};function n(t,e){return t>e?1:t<e?-1:0}function r(t,n,r){for(var i=new e(null,null),s=i,o=i;;){var a=r(t,n.key);if(a<0){if(null===n.left)break;if(r(t,n.left.key)<0){var c=n.left;if(n.left=c.right,c.right=n,null===(n=c).left)break}o.left=n,o=n,n=n.left}else{if(!(a>0))break;if(null===n.right)break;if(r(t,n.right.key)>0&&(c=n.right,n.right=c.left,c.left=n,null===(n=c).right))break;s.right=n,s=n,n=n.right}}return s.right=n.left,o.left=n.right,n.left=i.right,n.right=i.left,n}function i(t,n,i,s){var o=new e(t,n);if(null===i)return o.left=o.right=null,o;var a=s(t,(i=r(t,i,s)).key);return a<0?(o.left=i.left,o.right=i,i.left=null):a>=0&&(o.right=i.right,o.left=i,i.right=null),o}function s(t,e,n){var i=null,s=null;if(e){var o=n((e=r(t,e,n)).key,t);0===o?(i=e.left,s=e.right):o<0?(s=e.right,e.right=null,i=e):(i=e.left,e.left=null,s=e)}return{left:i,right:s}}function o(t,e,n,r,i){if(t){r(e+(n?"└── ":"├── ")+i(t)+"\n");var s=e+(n?" ":"│ ");t.left&&o(t.left,s,!1,r,i),t.right&&o(t.right,s,!0,r,i)}}var a=function(){function a(t){void 0===t&&(t=n),this._root=null,this._size=0,this._comparator=t}return a.prototype.insert=function(t,e){return this._size++,this._root=i(t,e,this._root,this._comparator)},a.prototype.add=function(t,n){var i=new e(t,n);null===this._root&&(i.left=i.right=null,this._size++,this._root=i);var s=this._comparator,o=r(t,this._root,s),a=s(t,o.key);return 0===a?this._root=o:(a<0?(i.left=o.left,i.right=o,o.left=null):a>0&&(i.right=o.right,i.left=o,o.right=null),this._size++,this._root=i),this._root},a.prototype.remove=function(t){this._root=this._remove(t,this._root,this._comparator)},a.prototype._remove=function(t,e,n){var i;return null===e?null:0===n(t,(e=r(t,e,n)).key)?(null===e.left?i=e.right:(i=r(t,e.left,n)).right=e.right,this._size--,i):e},a.prototype.pop=function(){var t=this._root;if(t){for(;t.left;)t=t.left;return this._root=r(t.key,this._root,this._comparator),this._root=this._remove(t.key,this._root,this._comparator),{key:t.key,data:t.data}}return null},a.prototype.findStatic=function(t){for(var e=this._root,n=this._comparator;e;){var r=n(t,e.key);if(0===r)return e;e=r<0?e.left:e.right}return null},a.prototype.find=function(t){return this._root&&(this._root=r(t,this._root,this._comparator),0!==this._comparator(t,this._root.key))?null:this._root},a.prototype.contains=function(t){for(var e=this._root,n=this._comparator;e;){var r=n(t,e.key);if(0===r)return!0;e=r<0?e.left:e.right}return!1},a.prototype.forEach=function(t,e){for(var n=this._root,r=[],i=!1;!i;)null!==n?(r.push(n),n=n.left):0!==r.length?(n=r.pop(),t.call(e,n),n=n.right):i=!0;return this},a.prototype.range=function(t,e,n,r){for(var i=[],s=this._comparator,o=this._root;0!==i.length||o;)if(o)i.push(o),o=o.left;else{if(s((o=i.pop()).key,e)>0)break;if(s(o.key,t)>=0&&n.call(r,o))return this;o=o.right}return this},a.prototype.keys=function(){var t=[];return this.forEach((function(e){var n=e.key;return t.push(n)})),t},a.prototype.values=function(){var t=[];return this.forEach((function(e){var n=e.data;return t.push(n)})),t},a.prototype.min=function(){return this._root?this.minNode(this._root).key:null},a.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},a.prototype.minNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.left;)t=t.left;return t},a.prototype.maxNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.right;)t=t.right;return t},a.prototype.at=function(t){for(var e=this._root,n=!1,r=0,i=[];!n;)if(e)i.push(e),e=e.left;else if(i.length>0){if(e=i.pop(),r===t)return e;r++,e=e.right}else n=!0;return null},a.prototype.next=function(t){var e=this._root,n=null;if(t.right){for(n=t.right;n.left;)n=n.left;return n}for(var r=this._comparator;e;){var i=r(t.key,e.key);if(0===i)break;i<0?(n=e,e=e.left):e=e.right}return n},a.prototype.prev=function(t){var e=this._root,n=null;if(null!==t.left){for(n=t.left;n.right;)n=n.right;return n}for(var r=this._comparator;e;){var i=r(t.key,e.key);if(0===i)break;i<0?e=e.left:(n=e,e=e.right)}return n},a.prototype.clear=function(){return this._root=null,this._size=0,this},a.prototype.toList=function(){return function(t){for(var n=t,r=[],i=!1,s=new e(null,null),o=s;!i;)n?(r.push(n),n=n.left):r.length>0?n=(n=o=o.next=r.pop()).right:i=!0;return o.next=null,s.next}(this._root)},a.prototype.load=function(t,n,r){void 0===n&&(n=[]),void 0===r&&(r=!1);var i=t.length,s=this._comparator;if(r&&u(t,n,0,i-1,s),null===this._root)this._root=c(t,n,0,i),this._size=i;else{var o=function(t,n,r){for(var i=new e(null,null),s=i,o=t,a=n;null!==o&&null!==a;)r(o.key,a.key)<0?(s.next=o,o=o.next):(s.next=a,a=a.next),s=s.next;return null!==o?s.next=o:null!==a&&(s.next=a),i.next}(this.toList(),function(t,n){for(var r=new e(null,null),i=r,s=0;s<t.length;s++)i=i.next=new e(t[s],n[s]);return i.next=null,r.next}(t,n),s);i=this._size+i,this._root=h({head:o},0,i)}return this},a.prototype.isEmpty=function(){return null===this._root},Object.defineProperty(a.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),a.prototype.toString=function(t){void 0===t&&(t=function(t){return String(t.key)});var e=[];return o(this._root,"",!0,(function(t){return e.push(t)}),t),e.join("")},a.prototype.update=function(t,e,n){var o=this._comparator,a=s(t,this._root,o),c=a.left,h=a.right;o(t,e)<0?h=i(e,n,h,o):c=i(e,n,c,o),this._root=function(t,e,n){return null===e?t:(null===t||((e=r(t.key,e,n)).left=t),e)}(c,h,o)},a.prototype.split=function(t){return s(t,this._root,this._comparator)},a.prototype[Symbol.iterator]=function(){var e,n,r;return t(this,(function(t){switch(t.label){case 0:e=this._root,n=[],r=!1,t.label=1;case 1:return r?[3,6]:null===e?[3,2]:(n.push(e),e=e.left,[3,5]);case 2:return 0===n.length?[3,4]:[4,e=n.pop()];case 3:return t.sent(),e=e.right,[3,5];case 4:r=!0,t.label=5;case 5:return[3,1];case 6:return[2]}}))},a}();function c(t,n,r,i){var s=i-r;if(s>0){var o=r+Math.floor(s/2),a=t[o],h=n[o],u=new e(a,h);return u.left=c(t,n,r,o),u.right=c(t,n,o+1,i),u}return null}function h(t,e,n){var r=n-e;if(r>0){var i=e+Math.floor(r/2),s=h(t,e,i),o=t.head;return o.left=s,t.head=t.head.next,o.right=h(t,i+1,n),o}return null}function u(t,e,n,r,i){if(!(n>=r)){for(var s=t[n+r>>1],o=n-1,a=r+1;;){do{o++}while(i(t[o],s)<0);do{a--}while(i(t[a],s)>0);if(o>=a)break;var c=t[o];t[o]=t[a],t[a]=c,c=e[o],e[o]=e[a],e[a]=c}u(t,e,n,a,i),u(t,e,a+1,r,i)}}const l=(t,e)=>t.ll.x<=e.x&&e.x<=t.ur.x&&t.ll.y<=e.y&&e.y<=t.ur.y,p=(t,e)=>{if(e.ur.x<t.ll.x||t.ur.x<e.ll.x||e.ur.y<t.ll.y||t.ur.y<e.ll.y)return null;const n=t.ll.x<e.ll.x?e.ll.x:t.ll.x,r=t.ur.x<e.ur.x?t.ur.x:e.ur.x;return{ll:{x:n,y:t.ll.y<e.ll.y?e.ll.y:t.ll.y},ur:{x:r,y:t.ur.y<e.ur.y?t.ur.y:e.ur.y}}};let f=Number.EPSILON;void 0===f&&(f=Math.pow(2,-52));const d=f*f,g=(t,e)=>{if(-f<t&&t<f&&-f<e&&e<f)return 0;const n=t-e;return n*n<d*t*e?0:t<e?-1:1};class y{constructor(){this.tree=new a,this.round(0)}round(t){const e=this.tree.add(t),n=this.tree.prev(e);if(null!==n&&0===g(e.key,n.key))return this.tree.remove(t),n.key;const r=this.tree.next(e);return null!==r&&0===g(e.key,r.key)?(this.tree.remove(t),r.key):t}}const m=new class{constructor(){this.reset()}reset(){this.xRounder=new y,this.yRounder=new y}round(t,e){return{x:this.xRounder.round(t),y:this.yRounder.round(e)}}},b=11102230246251565e-32,v=134217729,w=(3+8*b)*b;function x(t,e,n,r,i){let s,o,a,c,h=e[0],u=r[0],l=0,p=0;u>h==u>-h?(s=h,h=e[++l]):(s=u,u=r[++p]);let f=0;if(l<t&&p<n)for(u>h==u>-h?(o=h+s,a=s-(o-h),h=e[++l]):(o=u+s,a=s-(o-u),u=r[++p]),s=o,0!==a&&(i[f++]=a);l<t&&p<n;)u>h==u>-h?(o=s+h,c=o-s,a=s-(o-c)+(h-c),h=e[++l]):(o=s+u,c=o-s,a=s-(o-c)+(u-c),u=r[++p]),s=o,0!==a&&(i[f++]=a);for(;l<t;)o=s+h,c=o-s,a=s-(o-c)+(h-c),h=e[++l],s=o,0!==a&&(i[f++]=a);for(;p<n;)o=s+u,c=o-s,a=s-(o-c)+(u-c),u=r[++p],s=o,0!==a&&(i[f++]=a);return 0===s&&0!==f||(i[f++]=s),f}function S(t){return new Float64Array(t)}const _=22204460492503146e-32,E=11093356479670487e-47,k=S(4),P=S(8),R=S(12),M=S(16),T=S(4);function O(t,e,n,r,i,s){const o=(e-s)*(n-i),a=(t-i)*(r-s),c=o-a,h=Math.abs(o+a);return Math.abs(c)>=33306690738754716e-32*h?c:-function(t,e,n,r,i,s,o){let a,c,h,u,l,p,f,d,g,y,m,b,S,O,A,C,B,L;const I=t-i,j=n-i,N=e-s,D=r-s;O=I*D,p=v*I,f=p-(p-I),d=I-f,p=v*D,g=p-(p-D),y=D-g,A=d*y-(O-f*g-d*g-f*y),C=N*j,p=v*N,f=p-(p-N),d=N-f,p=v*j,g=p-(p-j),y=j-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,k[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,k[1]=S-(m+l)+(l-C),L=b+m,l=L-b,k[2]=b-(L-l)+(m-l),k[3]=L;let q=function(t,e){let n=e[0];for(let r=1;r<t;r++)n+=e[r];return n}(4,k),F=_*o;if(q>=F||-q>=F)return q;if(l=t-I,a=t-(I+l)+(l-i),l=n-j,h=n-(j+l)+(l-i),l=e-N,c=e-(N+l)+(l-s),l=r-D,u=r-(D+l)+(l-s),0===a&&0===c&&0===h&&0===u)return q;if(F=E*o+w*Math.abs(q),q+=I*u+D*a-(N*h+j*c),q>=F||-q>=F)return q;O=a*D,p=v*a,f=p-(p-a),d=a-f,p=v*D,g=p-(p-D),y=D-g,A=d*y-(O-f*g-d*g-f*y),C=c*j,p=v*c,f=p-(p-c),d=c-f,p=v*j,g=p-(p-j),y=j-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,T[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,T[1]=S-(m+l)+(l-C),L=b+m,l=L-b,T[2]=b-(L-l)+(m-l),T[3]=L;const U=x(4,k,4,T,P);O=I*u,p=v*I,f=p-(p-I),d=I-f,p=v*u,g=p-(p-u),y=u-g,A=d*y-(O-f*g-d*g-f*y),C=N*h,p=v*N,f=p-(p-N),d=N-f,p=v*h,g=p-(p-h),y=h-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,T[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,T[1]=S-(m+l)+(l-C),L=b+m,l=L-b,T[2]=b-(L-l)+(m-l),T[3]=L;const V=x(U,P,4,T,R);O=a*u,p=v*a,f=p-(p-a),d=a-f,p=v*u,g=p-(p-u),y=u-g,A=d*y-(O-f*g-d*g-f*y),C=c*h,p=v*c,f=p-(p-c),d=c-f,p=v*h,g=p-(p-h),y=h-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,T[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,T[1]=S-(m+l)+(l-C),L=b+m,l=L-b,T[2]=b-(L-l)+(m-l),T[3]=L;const Y=x(V,R,4,T,M);return M[Y-1]}(t,e,n,r,i,s,h)}const A=(t,e)=>t.x*e.y-t.y*e.x,C=(t,e)=>t.x*e.x+t.y*e.y,B=(t,e,n)=>{const r=O(t.x,t.y,e.x,e.y,n.x,n.y);return r>0?-1:r<0?1:0},L=t=>Math.sqrt(C(t,t)),I=(t,e,n)=>{const r={x:e.x-t.x,y:e.y-t.y},i={x:n.x-t.x,y:n.y-t.y};return A(i,r)/L(i)/L(r)},j=(t,e,n)=>{const r={x:e.x-t.x,y:e.y-t.y},i={x:n.x-t.x,y:n.y-t.y};return C(i,r)/L(i)/L(r)},N=(t,e,n)=>0===e.y?null:{x:t.x+e.x/e.y*(n-t.y),y:n},D=(t,e,n)=>0===e.x?null:{x:n,y:t.y+e.y/e.x*(n-t.x)};class q{static compare(t,e){const n=q.comparePoints(t.point,e.point);return 0!==n?n:(t.point!==e.point&&t.link(e),t.isLeft!==e.isLeft?t.isLeft?1:-1:U.compare(t.segment,e.segment))}static comparePoints(t,e){return t.x<e.x?-1:t.x>e.x?1:t.y<e.y?-1:t.y>e.y?1:0}constructor(t,e){void 0===t.events?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=e}link(t){if(t.point===this.point)throw new Error("Tried to link already linked events");const e=t.point.events;for(let t=0,n=e.length;t<n;t++){const n=e[t];this.point.events.push(n),n.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let e=0;e<t;e++){const n=this.point.events[e];if(void 0===n.segment.consumedBy)for(let r=e+1;r<t;r++){const t=this.point.events[r];void 0===t.consumedBy&&n.otherSE.point.events===t.otherSE.point.events&&n.segment.consume(t.segment)}}}getAvailableLinkedEvents(){const t=[];for(let e=0,n=this.point.events.length;e<n;e++){const n=this.point.events[e];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&t.push(n)}return t}getLeftmostComparator(t){const e=new Map,n=n=>{const r=n.otherSE;e.set(n,{sine:I(this.point,t.point,r.point),cosine:j(this.point,t.point,r.point)})};return(t,r)=>{e.has(t)||n(t),e.has(r)||n(r);const{sine:i,cosine:s}=e.get(t),{sine:o,cosine:a}=e.get(r);return i>=0&&o>=0?s<a?1:s>a?-1:0:i<0&&o<0?s<a?-1:s>a?1:0:o<i?-1:o>i?1:0}}}let F=0;class U{static compare(t,e){const n=t.leftSE.point.x,r=e.leftSE.point.x,i=t.rightSE.point.x,s=e.rightSE.point.x;if(s<n)return 1;if(i<r)return-1;const o=t.leftSE.point.y,a=e.leftSE.point.y,c=t.rightSE.point.y,h=e.rightSE.point.y;if(n<r){if(a<o&&a<c)return 1;if(a>o&&a>c)return-1;const n=t.comparePoint(e.leftSE.point);if(n<0)return 1;if(n>0)return-1;const r=e.comparePoint(t.rightSE.point);return 0!==r?r:-1}if(n>r){if(o<a&&o<h)return-1;if(o>a&&o>h)return 1;const n=e.comparePoint(t.leftSE.point);if(0!==n)return n;const r=t.comparePoint(e.rightSE.point);return r<0?1:r>0?-1:1}if(o<a)return-1;if(o>a)return 1;if(i<s){const n=e.comparePoint(t.rightSE.point);if(0!==n)return n}if(i>s){const n=t.comparePoint(e.rightSE.point);if(n<0)return 1;if(n>0)return-1}if(i!==s){const t=c-o,e=i-n,u=h-a,l=s-r;if(t>e&&u<l)return 1;if(t<e&&u>l)return-1}return i>s?1:i<s||c<h?-1:c>h?1:t.id<e.id?-1:t.id>e.id?1:0}constructor(t,e,n,r){this.id=++F,this.leftSE=t,t.segment=this,t.otherSE=e,this.rightSE=e,e.segment=this,e.otherSE=t,this.rings=n,this.windings=r}static fromRing(t,e,n){let r,i,s;const o=q.comparePoints(t,e);if(o<0)r=t,i=e,s=1;else{if(!(o>0))throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);r=e,i=t,s=-1}const a=new q(r,!0),c=new q(i,!1);return new U(a,c,[n],[s])}replaceRightSE(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const t=this.leftSE.point.y,e=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t<e?t:e},ur:{x:this.rightSE.point.x,y:t>e?t:e}}}vector(){return{x:this.rightSE.point.x-this.leftSE.point.x,y:this.rightSE.point.y-this.leftSE.point.y}}isAnEndpoint(t){return t.x===this.leftSE.point.x&&t.y===this.leftSE.point.y||t.x===this.rightSE.point.x&&t.y===this.rightSE.point.y}comparePoint(t){if(this.isAnEndpoint(t))return 0;const e=this.leftSE.point,n=this.rightSE.point,r=this.vector();if(e.x===n.x)return t.x===e.x?0:t.x<e.x?1:-1;const i=(t.y-e.y)/r.y,s=e.x+i*r.x;if(t.x===s)return 0;const o=(t.x-e.x)/r.x,a=e.y+o*r.y;return t.y===a?0:t.y<a?-1:1}getIntersection(t){const e=this.bbox(),n=t.bbox(),r=p(e,n);if(null===r)return null;const i=this.leftSE.point,s=this.rightSE.point,o=t.leftSE.point,a=t.rightSE.point,c=l(e,o)&&0===this.comparePoint(o),h=l(n,i)&&0===t.comparePoint(i),u=l(e,a)&&0===this.comparePoint(a),f=l(n,s)&&0===t.comparePoint(s);if(h&&c)return f&&!u?s:!f&&u?a:null;if(h)return u&&i.x===a.x&&i.y===a.y?null:i;if(c)return f&&s.x===o.x&&s.y===o.y?null:o;if(f&&u)return null;if(f)return s;if(u)return a;const d=((t,e,n,r)=>{if(0===e.x)return D(n,r,t.x);if(0===r.x)return D(t,e,n.x);if(0===e.y)return N(n,r,t.y);if(0===r.y)return N(t,e,n.y);const i=A(e,r);if(0==i)return null;const s={x:n.x-t.x,y:n.y-t.y},o=A(s,e)/i,a=A(s,r)/i;return{x:(t.x+a*e.x+(n.x+o*r.x))/2,y:(t.y+a*e.y+(n.y+o*r.y))/2}})(i,this.vector(),o,t.vector());return null===d?null:l(r,d)?m.round(d.x,d.y):null}split(t){const e=[],n=void 0!==t.events,r=new q(t,!0),i=new q(t,!1),s=this.rightSE;this.replaceRightSE(i),e.push(i),e.push(r);const o=new U(r,s,this.rings.slice(),this.windings.slice());return q.comparePoints(o.leftSE.point,o.rightSE.point)>0&&o.swapEvents(),q.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),i.checkForConsuming()),e}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let t=0,e=this.windings.length;t<e;t++)this.windings[t]*=-1}consume(t){let e=this,n=t;for(;e.consumedBy;)e=e.consumedBy;for(;n.consumedBy;)n=n.consumedBy;const r=U.compare(e,n);if(0!==r){if(r>0){const t=e;e=n,n=t}if(e.prev===n){const t=e;e=n,n=t}for(let t=0,r=n.rings.length;t<r;t++){const r=n.rings[t],i=n.windings[t],s=e.rings.indexOf(r);-1===s?(e.rings.push(r),e.windings.push(i)):e.windings[s]+=i}n.rings=null,n.windings=null,n.consumedBy=e,n.leftSE.consumedBy=e.leftSE,n.rightSE.consumedBy=e.rightSE}}prevInResult(){return void 0!==this._prevInResult||(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null),this._prevInResult}beforeState(){if(void 0!==this._beforeState)return this._beforeState;if(this.prev){const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}afterState(){if(void 0!==this._afterState)return this._afterState;const t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};const e=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let t=0,r=this.rings.length;t<r;t++){const r=this.rings[t],i=this.windings[t],s=e.indexOf(r);-1===s?(e.push(r),n.push(i)):n[s]+=i}const i=[],s=[];for(let t=0,r=e.length;t<r;t++){if(0===n[t])continue;const r=e[t],o=r.poly;if(-1===s.indexOf(o))if(r.isExterior)i.push(o);else{-1===s.indexOf(o)&&s.push(o);const t=i.indexOf(r.poly);-1!==t&&i.splice(t,1)}}for(let t=0,e=i.length;t<e;t++){const e=i[t].multiPoly;-1===r.indexOf(e)&&r.push(e)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;const t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(K.type){case"union":{const n=0===t.length,r=0===e.length;this._isInResult=n!==r;break}case"intersection":{let n,r;t.length<e.length?(n=t.length,r=e.length):(n=e.length,r=t.length),this._isInResult=r===K.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(t.length-e.length);this._isInResult=n%2==1;break}case"difference":{const n=t=>1===t.length&&t[0].isSubject;this._isInResult=n(t)!==n(e);break}default:throw new Error(`Unrecognized operation type found ${K.type}`)}return this._isInResult}}class V{constructor(t,e,n){if(!Array.isArray(t)||0===t.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=e,this.isExterior=n,this.segments=[],"number"!=typeof t[0][0]||"number"!=typeof t[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const r=m.round(t[0][0],t[0][1]);this.bbox={ll:{x:r.x,y:r.y},ur:{x:r.x,y:r.y}};let i=r;for(let e=1,n=t.length;e<n;e++){if("number"!=typeof t[e][0]||"number"!=typeof t[e][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");let n=m.round(t[e][0],t[e][1]);n.x===i.x&&n.y===i.y||(this.segments.push(U.fromRing(i,n,this)),n.x<this.bbox.ll.x&&(this.bbox.ll.x=n.x),n.y<this.bbox.ll.y&&(this.bbox.ll.y=n.y),n.x>this.bbox.ur.x&&(this.bbox.ur.x=n.x),n.y>this.bbox.ur.y&&(this.bbox.ur.y=n.y),i=n)}r.x===i.x&&r.y===i.y||this.segments.push(U.fromRing(i,r,this))}getSweepEvents(){const t=[];for(let e=0,n=this.segments.length;e<n;e++){const n=this.segments[e];t.push(n.leftSE),t.push(n.rightSE)}return t}}class Y{constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new V(t[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let e=1,n=t.length;e<n;e++){const n=new V(t[e],this,!1);n.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=n.bbox.ur.y),this.interiorRings.push(n)}this.multiPoly=e}getSweepEvents(){const t=this.exteriorRing.getSweepEvents();for(let e=0,n=this.interiorRings.length;e<n;e++){const n=this.interiorRings[e].getSweepEvents();for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t}}class z{constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof t[0][0][0]&&(t=[t])}catch(t){}this.polys=[],this.bbox={ll:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY},ur:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY}};for(let e=0,n=t.length;e<n;e++){const n=new Y(t[e],this);n.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=n.bbox.ur.y),this.polys.push(n)}this.isSubject=e}getSweepEvents(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const n=this.polys[e].getSweepEvents();for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t}}class X{static factory(t){const e=[];for(let n=0,r=t.length;n<r;n++){const r=t[n];if(!r.isInResult()||r.ringOut)continue;let i=null,s=r.leftSE,o=r.rightSE;const a=[s],c=s.point,h=[];for(;i=s,s=o,a.push(s),s.point!==c;)for(;;){const t=s.getAvailableLinkedEvents();if(0===t.length){const t=a[0].point,e=a[a.length-1].point;throw new Error(`Unable to complete output ring starting at [${t.x}, ${t.y}]. Last matching segment found ends at [${e.x}, ${e.y}].`)}if(1===t.length){o=t[0].otherSE;break}let n=null;for(let t=0,e=h.length;t<e;t++)if(h[t].point===s.point){n=t;break}if(null!==n){const t=h.splice(n)[0],r=a.splice(t.index);r.unshift(r[0].otherSE),e.push(new X(r.reverse()));continue}h.push({index:a.length,point:s.point});const r=s.getLeftmostComparator(i);o=t.sort(r)[0].otherSE;break}e.push(new X(a))}return e}constructor(t){this.events=t;for(let e=0,n=t.length;e<n;e++)t[e].segment.ringOut=this;this.poly=null}getGeom(){let t=this.events[0].point;const e=[t];for(let n=1,r=this.events.length-1;n<r;n++){const r=this.events[n].point,i=this.events[n+1].point;0!==B(r,t,i)&&(e.push(r),t=r)}if(1===e.length)return null;const n=e[0],r=e[1];0===B(n,t,r)&&e.shift(),e.push(e[0]);const i=this.isExteriorRing()?1:-1,s=this.isExteriorRing()?0:e.length-1,o=this.isExteriorRing()?e.length:-1,a=[];for(let t=s;t!=o;t+=i)a.push([e[t].x,e[t].y]);return a}isExteriorRing(){if(void 0===this._isExteriorRing){const t=this.enclosingRing();this._isExteriorRing=!t||!t.isExteriorRing()}return this._isExteriorRing}enclosingRing(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let t=this.events[0];for(let e=1,n=this.events.length;e<n;e++){const n=this.events[e];q.compare(t,n)>0&&(t=n)}let e=t.segment.prevInResult(),n=e?e.prevInResult():null;for(;;){if(!e)return null;if(!n)return e.ringOut;if(n.ringOut!==e.ringOut)return n.ringOut.enclosingRing()!==e.ringOut?e.ringOut:e.ringOut.enclosingRing();e=n.prevInResult(),n=e?e.prevInResult():null}}}class ${constructor(t){this.exteriorRing=t,t.poly=this,this.interiorRings=[]}addInterior(t){this.interiorRings.push(t),t.poly=this}getGeom(){const t=[this.exteriorRing.getGeom()];if(null===t[0])return null;for(let e=0,n=this.interiorRings.length;e<n;e++){const n=this.interiorRings[e].getGeom();null!==n&&t.push(n)}return t}}class W{constructor(t){this.rings=t,this.polys=this._composePolys(t)}getGeom(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const n=this.polys[e].getGeom();null!==n&&t.push(n)}return t}_composePolys(t){const e=[];for(let n=0,r=t.length;n<r;n++){const r=t[n];if(!r.poly)if(r.isExteriorRing())e.push(new $(r));else{const t=r.enclosingRing();t.poly||e.push(new $(t)),t.poly.addInterior(r)}}return e}}class G{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:U.compare;this.queue=t,this.tree=new a(e),this.segments=[]}process(t){const e=t.segment,n=[];if(t.consumedBy)return t.isLeft?this.queue.remove(t.otherSE):this.tree.remove(e),n;const r=t.isLeft?this.tree.add(e):this.tree.find(e);if(!r)throw new Error(`Unable to find segment #${e.id} [${e.leftSE.point.x}, ${e.leftSE.point.y}] -> [${e.rightSE.point.x}, ${e.rightSE.point.y}] in SweepLine tree.`);let i,s,o=r,a=r;for(;void 0===i;)o=this.tree.prev(o),null===o?i=null:void 0===o.key.consumedBy&&(i=o.key);for(;void 0===s;)a=this.tree.next(a),null===a?s=null:void 0===a.key.consumedBy&&(s=a.key);if(t.isLeft){let r=null;if(i){const t=i.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(r=t),!i.isAnEndpoint(t))){const e=this._splitSafely(i,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}}let o=null;if(s){const t=s.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(o=t),!s.isAnEndpoint(t))){const e=this._splitSafely(s,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}}if(null!==r||null!==o){let t=null;t=null===r?o:null===o||q.comparePoints(r,o)<=0?r:o,this.queue.remove(e.rightSE),n.push(e.rightSE);const i=e.split(t);for(let t=0,e=i.length;t<e;t++)n.push(i[t])}n.length>0?(this.tree.remove(e),n.push(t)):(this.segments.push(e),e.prev=i)}else{if(i&&s){const t=i.getIntersection(s);if(null!==t){if(!i.isAnEndpoint(t)){const e=this._splitSafely(i,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}if(!s.isAnEndpoint(t)){const e=this._splitSafely(s,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}}}this.tree.remove(e)}return n}_splitSafely(t,e){this.tree.remove(t);const n=t.rightSE;this.queue.remove(n);const r=t.split(e);return r.push(n),void 0===t.consumedBy&&this.tree.add(t),r}}const H="undefined"!=typeof process&&process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE||1e6,J="undefined"!=typeof process&&process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS||1e6;const K=new class{run(t,e,n){K.type=t,m.reset();const r=[new z(e,!0)];for(let t=0,e=n.length;t<e;t++)r.push(new z(n[t],!1));if(K.numMultiPolys=r.length,"difference"===K.type){const t=r[0];let e=1;for(;e<r.length;)null!==p(r[e].bbox,t.bbox)?e++:r.splice(e,1)}if("intersection"===K.type)for(let t=0,e=r.length;t<e;t++){const e=r[t];for(let n=t+1,i=r.length;n<i;n++)if(null===p(e.bbox,r[n].bbox))return[]}const i=new a(q.compare);for(let t=0,e=r.length;t<e;t++){const e=r[t].getSweepEvents();for(let t=0,n=e.length;t<n;t++)if(i.insert(e[t]),i.size>H)throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).")}const s=new G(i);let o=i.size,c=i.pop();for(;c;){const t=c.key;if(i.size===o){const e=t.segment;throw new Error(`Unable to pop() ${t.isLeft?"left":"right"} SweepEvent [${t.point.x}, ${t.point.y}] from segment #${e.id} [${e.leftSE.point.x}, ${e.leftSE.point.y}] -> [${e.rightSE.point.x}, ${e.rightSE.point.y}] from queue.`)}if(i.size>H)throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");if(s.segments.length>J)throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");const e=s.process(t);for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0===n.consumedBy&&i.insert(n)}o=i.size,c=i.pop()}m.reset();const h=X.factory(s.segments);return new W(h).getGeom()}};var Q={union:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("union",t,n)},intersection:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("intersection",t,n)},xor:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("xor",t,n)},difference:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("difference",t,n)}};return Q}()}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var s=e[r]={exports:{}};return t[r].call(s.exports,s,s.exports,n),s.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};n.d(r,{j:()=>nr});var i={};n.r(i),n.d(i,{Decoder:()=>$n,Encoder:()=>zn,PacketType:()=>Yn,protocol:()=>Vn});class s{baseURL;abortControllers=new Set;constructor(t){this.baseURL=`${t}/api`}async request(t,e,n,r={}){const i=new AbortController;this.abortControllers.add(i);const s=setTimeout((()=>{i.abort(),this.abortControllers.delete(i)}),15e3);try{const s=await fetch(`${this.baseURL}${e}`,{method:t,headers:{"Content-Type":"application/json",...r.headers},body:n?JSON.stringify(n):void 0,signal:i.signal,...r});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s}finally{clearTimeout(s),this.abortControllers.delete(i)}}get(t,e){return this.request("GET",t,void 0,e)}post(t,e,n){return this.request("POST",t,e,n)}}process.env.CAMERA_UI_RUNMODE,process.env.CAMERA_UI_RUNMODE,process.env.CAMERA_UI_RUNMODE;class o{subscriptions=[];additionalSubscriptions=[];addSubscriptions(...t){this.subscriptions.push(...t)}addAdditionalSubscriptions(...t){this.additionalSubscriptions.push(...t)}unsubscribe(){this.subscriptions.forEach((t=>t.unsubscribe()))}unsubscribeAdditional(){this.additionalSubscriptions.forEach((t=>t.unsubscribe()))}}function a(t,e,n=!1){if(t===e)return!0;if((void 0===t||void 0===e||null===t||null===e)&&(t||e))return!1;const r=t?.constructor.name,i=e?.constructor.name;if(r!==i)return!1;if("Array"===r&&"Array"===i){if(t.length!==e.length)return!1;if(n){const r=[...e];return t.every((t=>{const e=r.findIndex((e=>a(t,e,n)));return-1!==e&&(r.splice(e,1),!0)}))}{let r=!0;for(let i=0;i<t.length;i++)if(!a(t[i],e[i],n)){r=!1;break}return r}}if("Object"===r&&"Object"===i){let r=!0;const i=Object.keys(t),s=Object.keys(e);if(i.length!==s.length)return!1;for(let s=0;s<i.length;s++)if(t[i[s]]&&e[i[s]]){if(t[i[s]]===e[i[s]])continue;if(!t[i[s]]||"Array"!==t[i[s]].constructor.name&&"Object"!==t[i[s]].constructor.name){if(t[i[s]]!==e[i[s]]){r=!1;break}}else if(r=a(t[i[s]],e[i[s]],n),!r)break}else if(t[i[s]]&&!e[i[s]]||!t[i[s]]&&e[i[s]]){r=!1;break}return r}return t===e}function c(t){return JSON.parse(JSON.stringify(t))}var h=n(855),u=n.n(h),l=function(t,e){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},l(t,e)};function p(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}l(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function f(t,e){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function d(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function g(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,s=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=s.next()).done;)o.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}return o}function y(t,e,n){if(n||2===arguments.length)for(var r,i=0,s=e.length;i<s;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function m(t){return this instanceof m?(this.v=t,this):new m(t)}function b(t){return"function"==typeof t}function v(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var w=v((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function x(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var S=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var t,e,n,r,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var o=d(s),a=o.next();!a.done;a=o.next())a.value.remove(this)}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}else s.remove(this);var c=this.initialTeardown;if(b(c))try{c()}catch(t){i=t instanceof w?t.errors:[t]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var u=d(h),l=u.next();!l.done;l=u.next()){var p=l.value;try{k(p)}catch(t){i=null!=i?i:[],t instanceof w?i=y(y([],g(i)),g(t.errors)):i.push(t)}}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(i)throw new w(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)k(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&x(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&x(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}(),_=S.EMPTY;function E(t){return t instanceof S||t&&"closed"in t&&b(t.remove)&&b(t.add)&&b(t.unsubscribe)}function k(t){b(t)?t():t.unsubscribe()}var P={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},R={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=R.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,y([t,e],g(n))):setTimeout.apply(void 0,y([t,e],g(n)))},clearTimeout:function(t){var e=R.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function M(t){R.setTimeout((function(){var e=P.onUnhandledError;if(!e)throw t;e(t)}))}function T(){}var O=A("C",void 0,void 0);function A(t,e,n){return{kind:t,value:e,error:n}}var C=null;function B(t){if(P.useDeprecatedSynchronousErrorHandling){var e=!C;if(e&&(C={errorThrown:!1,error:null}),t(),e){var n=C,r=n.errorThrown,i=n.error;if(C=null,r)throw i}}else t()}var L=function(t){function e(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,E(e)&&e.add(n)):n.destination=U,n}return p(e,t),e.create=function(t,e,n){return new D(t,e,n)},e.prototype.next=function(t){this.isStopped?F(function(t){return A("N",t,void 0)}(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?F(A("E",void 0,t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?F(O,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(S),I=Function.prototype.bind;function j(t,e){return I.call(t,e)}var N=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){q(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){q(t)}else q(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){q(t)}},t}(),D=function(t){function e(e,n,r){var i,s,o=t.call(this)||this;return b(e)||!e?i={next:null!=e?e:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:o&&P.useDeprecatedNextContext?((s=Object.create(e)).unsubscribe=function(){return o.unsubscribe()},i={next:e.next&&j(e.next,s),error:e.error&&j(e.error,s),complete:e.complete&&j(e.complete,s)}):i=e,o.destination=new N(i),o}return p(e,t),e}(L);function q(t){var e;P.useDeprecatedSynchronousErrorHandling?(e=t,P.useDeprecatedSynchronousErrorHandling&&C&&(C.errorThrown=!0,C.error=e)):M(t)}function F(t,e){var n=P.onStoppedNotification;n&&R.setTimeout((function(){return n(t,e)}))}var U={closed:!0,next:T,error:function(t){throw t},complete:T},V="function"==typeof Symbol&&Symbol.observable||"@@observable";function Y(t){return t}var z=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(t,e,n){var r=this,i=function(t){return t&&t instanceof L||function(t){return t&&b(t.next)&&b(t.error)&&b(t.complete)}(t)&&E(t)}(t)?t:new D(t,e,n);return B((function(){var t=r,e=t.operator,n=t.source;i.add(e?e.call(i,n):n?r._subscribe(i):r._trySubscribe(i))})),i},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var n=this;return new(e=X(e))((function(e,r){var i=new D({next:function(e){try{t(e)}catch(t){r(t),i.unsubscribe()}},error:r,complete:e});n.subscribe(i)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[V]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(0===(n=t).length?Y:1===n.length?n[0]:function(t){return n.reduce((function(t,e){return e(t)}),t)})(this);var n},t.prototype.toPromise=function(t){var e=this;return new(t=X(t))((function(t,n){var r;e.subscribe((function(t){return r=t}),(function(t){return n(t)}),(function(){return t(r)}))}))},t.create=function(e){return new t(e)},t}();function X(t){var e;return null!==(e=null!=t?t:P.Promise)&&void 0!==e?e:Promise}var $=v((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),W=function(t){function e(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return p(e,t),e.prototype.lift=function(t){var e=new G(this,this);return e.operator=t,e},e.prototype._throwIfClosed=function(){if(this.closed)throw new $},e.prototype.next=function(t){var e=this;B((function(){var n,r;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var i=d(e.currentObservers),s=i.next();!s.done;s=i.next())s.value.next(t)}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}}))},e.prototype.error=function(t){var e=this;B((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var n=e.observers;n.length;)n.shift().error(t)}}))},e.prototype.complete=function(){var t=this;B((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var e=this,n=this,r=n.hasError,i=n.isStopped,s=n.observers;return r||i?_:(this.currentObservers=null,s.push(t),new S((function(){e.currentObservers=null,x(s,t)})))},e.prototype._checkFinalizedStatuses=function(t){var e=this,n=e.hasError,r=e.thrownError,i=e.isStopped;n?t.error(r):i&&t.complete()},e.prototype.asObservable=function(){var t=new z;return t.source=this,t},e.create=function(t,e){return new G(t,e)},e}(z),G=function(t){function e(e,n){var r=t.call(this)||this;return r.destination=e,r.source=n,r}return p(e,t),e.prototype.next=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===n||n.call(e,t)},e.prototype.error=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===n||n.call(e,t)},e.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},e.prototype._subscribe=function(t){var e,n;return null!==(n=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==n?n:_},e}(W),H=function(t){function e(e){var n=t.call(this)||this;return n._value=e,n}return p(e,t),Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(e){var n=t.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},e.prototype.getValue=function(){var t=this,e=t.hasError,n=t.thrownError,r=t._value;if(e)throw n;return this._throwIfClosed(),r},e.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},e}(W),J={now:function(){return(J.delegate||Date).now()},delegate:void 0},K=function(t){function e(e,n,r){void 0===e&&(e=1/0),void 0===n&&(n=1/0),void 0===r&&(r=J);var i=t.call(this)||this;return i._bufferSize=e,i._windowTime=n,i._timestampProvider=r,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=n===1/0,i._bufferSize=Math.max(1,e),i._windowTime=Math.max(1,n),i}return p(e,t),e.prototype.next=function(e){var n=this,r=n.isStopped,i=n._buffer,s=n._infiniteTimeWindow,o=n._timestampProvider,a=n._windowTime;r||(i.push(e),!s&&i.push(o.now()+a)),this._trimBuffer(),t.prototype.next.call(this,e)},e.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var e=this._innerSubscribe(t),n=this._infiniteTimeWindow,r=this._buffer.slice(),i=0;i<r.length&&!t.closed;i+=n?1:2)t.next(r[i]);return this._checkFinalizedStatuses(t),e},e.prototype._trimBuffer=function(){var t=this,e=t._bufferSize,n=t._timestampProvider,r=t._buffer,i=t._infiniteTimeWindow,s=(i?1:2)*e;if(e<1/0&&s<r.length&&r.splice(0,r.length-s),!i){for(var o=n.now(),a=0,c=1;c<r.length&&r[c]<=o;c+=2)a=c;a&&r.splice(0,a+1)}},e}(W);function Q(t){return function(e){if(function(t){return b(null==t?void 0:t.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function Z(t,e,n,r,i){return new tt(t,e,n,r,i)}var tt=function(t){function e(e,n,r,i,s,o){var a=t.call(this,e)||this;return a.onFinalize=s,a.shouldUnsubscribe=o,a._next=n?function(t){try{n(t)}catch(t){e.error(t)}}:t.prototype._next,a._error=i?function(t){try{i(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,a._complete=r?function(){try{r()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,a}return p(e,t),e.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},e}(L);function et(){return Q((function(t,e){var n,r=!1;t.subscribe(Z(e,(function(t){var i=n;n=t,r&&e.next([i,t]),r=!0})))}))}function nt(t,e){return Q((function(n,r){var i=0;n.subscribe(Z(r,(function(n){return t.call(e,n,i++)&&r.next(n)})))}))}function rt(t,e){return Q((function(n,r){var i=0;n.subscribe(Z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var it=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t},st="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ot(t){if(t instanceof z)return t;if(null!=t){if(function(t){return b(t[V])}(t))return i=t,new z((function(t){var e=i[V]();if(b(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(it(t))return r=t,new z((function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()}));if(function(t){return b(null==t?void 0:t.then)}(t))return n=t,new z((function(t){n.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,M)}));if(function(t){return Symbol.asyncIterator&&b(null==t?void 0:t[Symbol.asyncIterator])}(t))return at(t);if(function(t){return b(null==t?void 0:t[st])}(t))return e=t,new z((function(t){var n,r;try{for(var i=d(e),s=i.next();!s.done;s=i.next()){var o=s.value;if(t.next(o),t.closed)return}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}t.complete()}));if(function(t){return b(null==t?void 0:t.getReader)}(t))return at(function(t){return function(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(t,e||[]),s=[];return r=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),o("next"),o("throw"),o("return",(function(t){return function(e){return Promise.resolve(e).then(t,h)}})),r[Symbol.asyncIterator]=function(){return this},r;function o(t,e){i[t]&&(r[t]=function(e){return new Promise((function(n,r){s.push([t,e,n,r])>1||a(t,e)}))},e&&(r[t]=e(r[t])))}function a(t,e){try{(n=i[t](e)).value instanceof m?Promise.resolve(n.value.v).then(c,h):u(s[0][2],n)}catch(t){u(s[0][3],t)}var n}function c(t){a("next",t)}function h(t){a("throw",t)}function u(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}(this,arguments,(function(){var e,n,r;return f(this,(function(i){switch(i.label){case 0:e=t.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,m(e.read())];case 3:return n=i.sent(),r=n.value,n.done?[4,m(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,m(r)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}(t))}var e,n,r,i;throw function(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}(t)}function at(t){return new z((function(e){(function(t,e){var n,r,i,s,o,a,c,h;return o=this,a=void 0,h=function(){var o,a;return f(this,(function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=d(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,i){!function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)}(r,i,(e=t[n](e)).done,e.value)}))}}}(t),c.label=1;case 1:return[4,n.next()];case 2:if((r=c.sent()).done)return[3,4];if(o=r.value,e.next(o),e.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),i={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(s=n.return)?[4,s.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))},new((c=void 0)||(c=Promise))((function(t,e){function n(t){try{i(h.next(t))}catch(t){e(t)}}function r(t){try{i(h.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):function(t){return t instanceof c?t:new c((function(e){e(t)}))}(e.value).then(n,r)}i((h=h.apply(o,a||[])).next())}))})(t,e).catch((function(t){return e.error(t)}))}))}function ct(t){void 0===t&&(t={});var e=t.connector,n=void 0===e?function(){return new W}:e,r=t.resetOnError,i=void 0===r||r,s=t.resetOnComplete,o=void 0===s||s,a=t.resetOnRefCountZero,c=void 0===a||a;return function(t){var e,r,s,a=0,h=!1,u=!1,l=function(){null==r||r.unsubscribe(),r=void 0},p=function(){l(),e=s=void 0,h=u=!1},f=function(){var t=e;p(),null==t||t.unsubscribe()};return Q((function(t,d){a++,u||h||l();var g=s=null!=s?s:n();d.add((function(){0!=--a||u||h||(r=ht(f,c))})),g.subscribe(d),!e&&a>0&&(e=new D({next:function(t){return g.next(t)},error:function(t){u=!0,l(),r=ht(p,i,t),g.error(t)},complete:function(){h=!0,l(),r=ht(p,o),g.complete()}}),ot(t).subscribe(e))}))(t)}}function ht(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!0!==e){if(!1!==e){var i=new D({next:function(){i.unsubscribe(),t()}});return ot(e.apply(void 0,y([],g(n)))).subscribe(i)}}else t()}function ut(t,e,n){return void 0===n&&(n=1/0),b(e)?ut((function(n,r){return rt((function(t,i){return e(n,t,r,i)}))(ot(t(n,r)))}),n):("number"==typeof e&&(n=e),Q((function(e,r){return function(t,e,n,r,i,s,o,a){var c=[],h=0,u=0,l=!1,p=function(){!l||c.length||h||e.complete()},f=function(t){return h<r?d(t):c.push(t)},d=function(t){h++;var i=!1;ot(n(t,u++)).subscribe(Z(e,(function(t){e.next(t)}),(function(){i=!0}),void 0,(function(){if(i)try{h--;for(var t=function(){var t=c.shift();d(t)};c.length&&h<r;)t();p()}catch(t){e.error(t)}})))};return t.subscribe(Z(e,f,(function(){l=!0,p()}))),function(){}}(e,r,t,n)})))}function lt(t,e){return t===e}function pt(t,e,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=e||{},r.geometry=t,r}function ft(t,e,n={}){for(const e of t){if(e.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(e[e.length-1].length!==e[0].length)throw new Error("First and last Position are not equivalent.");for(let t=0;t<e[e.length-1].length;t++)if(e[e.length-1][t]!==e[0][t])throw new Error("First and last Position are not equivalent.")}return pt({type:"Polygon",coordinates:t},e,n)}function dt(t,e={}){const n={type:"FeatureCollection"};return e.id&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.features=t,n}function gt(t){return!isNaN(t)&&null!==t&&!Array.isArray(t)}function yt(t,e,n){if(null!==t)for(var r,i,s,o,a,c,h,u,l=0,p=0,f=t.type,d="FeatureCollection"===f,g="Feature"===f,y=d?t.features.length:1,m=0;m<y;m++){a=(u=!!(h=d?t.features[m].geometry:g?t.geometry:t)&&"GeometryCollection"===h.type)?h.geometries.length:1;for(var b=0;b<a;b++){var v=0,w=0;if(null!==(o=u?h.geometries[b]:h)){c=o.coordinates;var x=o.type;switch(l=!n||"Polygon"!==x&&"MultiPolygon"!==x?0:1,x){case null:break;case"Point":if(!1===e(c,p,m,v,w))return!1;p++,v++;break;case"LineString":case"MultiPoint":for(r=0;r<c.length;r++){if(!1===e(c[r],p,m,v,w))return!1;p++,"MultiPoint"===x&&v++}"LineString"===x&&v++;break;case"Polygon":case"MultiLineString":for(r=0;r<c.length;r++){for(i=0;i<c[r].length-l;i++){if(!1===e(c[r][i],p,m,v,w))return!1;p++}"MultiLineString"===x&&v++,"Polygon"===x&&w++}"Polygon"===x&&v++;break;case"MultiPolygon":for(r=0;r<c.length;r++){for(w=0,i=0;i<c[r].length;i++){for(s=0;s<c[r][i].length-l;s++){if(!1===e(c[r][i][s],p,m,v,w))return!1;p++}w++}v++}break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(!1===yt(o.geometries[r],e,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function mt(t,e){var n,r,i,s,o,a,c,h,u,l,p=0,f="FeatureCollection"===t.type,d="Feature"===t.type,g=f?t.features.length:1;for(n=0;n<g;n++){for(a=f?t.features[n].geometry:d?t.geometry:t,h=f?t.features[n].properties:d?t.properties:{},u=f?t.features[n].bbox:d?t.bbox:void 0,l=f?t.features[n].id:d?t.id:void 0,o=(c=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,i=0;i<o;i++)if(null!==(s=c?a.geometries[i]:a))switch(s.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===e(s,p,h,u,l))return!1;break;case"GeometryCollection":for(r=0;r<s.geometries.length;r++)if(!1===e(s.geometries[r],p,h,u,l))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===e(null,p,h,u,l))return!1;p++}}function bt(t,e){mt(t,(function(t,n,r,i,s){var o,a=null===t?null:t.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return!1!==e(pt(t,r,{bbox:i,id:s}),n,0)&&void 0}switch(a){case"MultiPoint":o="Point";break;case"MultiLineString":o="LineString";break;case"MultiPolygon":o="Polygon"}for(var c=0;c<t.coordinates.length;c++){var h=t.coordinates[c];if(!1===e(pt({type:o,coordinates:h},r),n,c))return!1}}))}function vt(t,e={}){if(null!=t.bbox&&!0!==e.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return yt(t,(t=>{n[0]>t[0]&&(n[0]=t[0]),n[1]>t[1]&&(n[1]=t[1]),n[2]<t[0]&&(n[2]=t[0]),n[3]<t[1]&&(n[3]=t[1])})),n}function wt(t,e={}){const n=Number(t[0]),r=Number(t[1]),i=Number(t[2]),s=Number(t[3]);if(6===t.length)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const o=[n,r];return ft([[o,[i,r],[i,s],[n,s],o]],e.properties,{bbox:t,id:e.id})}Math.PI;var xt=n(73);function St(t,e={}){const n=[];if(mt(t,(t=>{n.push(t.coordinates)})),n.length<2)throw new Error("Must have at least 2 geometries");const r=xt.union(n[0],...n.slice(1));return 0===r.length?null:1===r.length?ft(r[0],e.properties):function(t,e,n={}){return pt({type:"MultiPolygon",coordinates:t},e,n)}(r,e.properties)}function _t(t,e,n=0,r=t.length-1,i=kt){for(;r>n;){if(r-n>600){const s=r-n+1,o=e-n+1,a=Math.log(s),c=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*c*(s-c)/s)*(o-s/2<0?-1:1);_t(t,e,Math.max(n,Math.floor(e-o*c/s+h)),Math.min(r,Math.floor(e+(s-o)*c/s+h)),i)}const s=t[e];let o=n,a=r;for(Et(t,n,e),i(t[r],s)>0&&Et(t,n,r);o<a;){for(Et(t,o,a),o++,a--;i(t[o],s)<0;)o++;for(;i(t[a],s)>0;)a--}0===i(t[n],s)?Et(t,n,a):(a++,Et(t,a,r)),a<=e&&(n=a+1),e<=a&&(r=a-1)}}function Et(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function kt(t,e){return t<e?-1:t>e?1:0}class Pt{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const n=[];if(!Nt(t,e))return n;const r=this.toBBox,i=[];for(;e;){for(let s=0;s<e.children.length;s++){const o=e.children[s],a=e.leaf?r(o):o;Nt(t,a)&&(e.leaf?n.push(o):jt(t,a)?this._all(o,n):i.push(o))}e=i.pop()}return n}collides(t){let e=this.data;if(!Nt(t,e))return!1;const n=[];for(;e;){for(let r=0;r<e.children.length;r++){const i=e.children[r],s=e.leaf?this.toBBox(i):i;if(Nt(t,s)){if(e.leaf||jt(t,s))return!0;n.push(i)}}e=n.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Dt([]),this}remove(t,e){if(!t)return this;let n=this.data;const r=this.toBBox(t),i=[],s=[];let o,a,c;for(;n||i.length;){if(n||(n=i.pop(),a=i[i.length-1],o=s.pop(),c=!0),n.leaf){const r=Rt(t,n.children,e);if(-1!==r)return n.children.splice(r,1),i.push(n),this._condense(i),this}c||n.leaf||!jt(n,r)?a?(o++,n=a.children[o],c=!1):n=null:(i.push(n),s.push(o),o=0,a=n,n=n.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,r){const i=n-e+1;let s,o=this._maxEntries;if(i<=o)return s=Dt(t.slice(e,n+1)),Mt(s,this.toBBox),s;r||(r=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/Math.pow(o,r-1))),s=Dt([]),s.leaf=!1,s.height=r;const a=Math.ceil(i/o),c=a*Math.ceil(Math.sqrt(o));qt(t,e,n,c,this.compareMinX);for(let i=e;i<=n;i+=c){const e=Math.min(i+c-1,n);qt(t,i,e,a,this.compareMinY);for(let n=i;n<=e;n+=a){const i=Math.min(n+a-1,e);s.children.push(this._build(t,n,i,r-1))}}return Mt(s,this.toBBox),s}_chooseSubtree(t,e,n,r){for(;r.push(e),!e.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let a=0;a<e.children.length;a++){const c=e.children[a],h=Bt(c),u=(i=t,s=c,(Math.max(s.maxX,i.maxX)-Math.min(s.minX,i.minX))*(Math.max(s.maxY,i.maxY)-Math.min(s.minY,i.minY))-h);u<o?(o=u,r=h<r?h:r,n=c):u===o&&h<r&&(r=h,n=c)}e=n||e.children[0]}var i,s;return e}_insert(t,e,n){const r=n?t:this.toBBox(t),i=[],s=this._chooseSubtree(r,this.data,e,i);for(s.children.push(t),Ot(s,r);e>=0&&i[e].children.length>this._maxEntries;)this._split(i,e),e--;this._adjustParentBBoxes(r,i,e)}_split(t,e){const n=t[e],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);const s=this._chooseSplitIndex(n,i,r),o=Dt(n.children.splice(s,n.children.length-s));o.height=n.height,o.leaf=n.leaf,Mt(n,this.toBBox),Mt(o,this.toBBox),e?t[e-1].children.push(o):this._splitRoot(n,o)}_splitRoot(t,e){this.data=Dt([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Mt(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let r,i=1/0,s=1/0;for(let o=e;o<=n-e;o++){const e=Tt(t,0,o,this.toBBox),a=Tt(t,o,n,this.toBBox),c=It(e,a),h=Bt(e)+Bt(a);c<i?(i=c,r=o,s=h<s?h:s):c===i&&h<s&&(s=h,r=o)}return r||n-e}_chooseSplitAxis(t,e,n){const r=t.leaf?this.compareMinX:At,i=t.leaf?this.compareMinY:Ct;this._allDistMargin(t,e,n,r)<this._allDistMargin(t,e,n,i)&&t.children.sort(r)}_allDistMargin(t,e,n,r){t.children.sort(r);const i=this.toBBox,s=Tt(t,0,e,i),o=Tt(t,n-e,n,i);let a=Lt(s)+Lt(o);for(let r=e;r<n-e;r++){const e=t.children[r];Ot(s,t.leaf?i(e):e),a+=Lt(s)}for(let r=n-e-1;r>=e;r--){const e=t.children[r];Ot(o,t.leaf?i(e):e),a+=Lt(o)}return a}_adjustParentBBoxes(t,e,n){for(let r=n;r>=0;r--)Ot(e[r],t)}_condense(t){for(let e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children,e.splice(e.indexOf(t[n]),1)):this.clear():Mt(t[n],this.toBBox)}}function Rt(t,e,n){if(!n)return e.indexOf(t);for(let r=0;r<e.length;r++)if(n(t,e[r]))return r;return-1}function Mt(t,e){Tt(t,0,t.children.length,e,t)}function Tt(t,e,n,r,i){i||(i=Dt(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=e;s<n;s++){const e=t.children[s];Ot(i,t.leaf?r(e):e)}return i}function Ot(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function At(t,e){return t.minX-e.minX}function Ct(t,e){return t.minY-e.minY}function Bt(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Lt(t){return t.maxX-t.minX+(t.maxY-t.minY)}function It(t,e){const n=Math.max(t.minX,e.minX),r=Math.max(t.minY,e.minY),i=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,i-n)*Math.max(0,s-r)}function jt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Nt(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Dt(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function qt(t,e,n,r,i){const s=[e,n];for(;s.length;){if((n=s.pop())-(e=s.pop())<=r)continue;const o=e+Math.ceil((n-e)/r/2)*r;_t(t,o,e,n,i),s.push(e,o,o,n)}}function Ft(t){return wt(t)}function Ut(t){return t[0]<t[2]&&t[1]<t[3]}function Vt(t,e){const[n,r,i,s]=t,[o,a,c,h]=e,u=Math.max(n,o),l=Math.max(r,a),p=Math.min(i,c),f=Math.min(s,h);if(p<u||f<l)return 0;const d=(p-u)*(f-l);return d/((i-n)*(s-r)+(c-o)*(h-a)-d)}function Yt(t,e=.01,n=100){if(0===t.length)return[];const r=new Pt,i=t.map((t=>({minX:t.boundingBox[0],minY:t.boundingBox[1],maxX:t.boundingBox[2],maxY:t.boundingBox[3],detection:{...t,id:t.id??Math.random().toString(36).slice(2,9)}})));r.load(i);const s=[],o=new Set;for(const t of i){if(o.has(t.detection.id))continue;const i={...t.detection};let c=i.confidence;const h=[Ft(i.boundingBox)],u=Math.max(n,10),l=r.search({minX:t.minX-u,minY:t.minY-u,maxX:t.maxX+u,maxY:t.maxY+u});for(const r of l){if(r.detection.id===i.id||o.has(r.detection.id)||r.detection.label!==i.label)continue;const s=Vt(i.boundingBox,r.detection.boundingBox),a=Math.abs(t.minX-r.minX)<=n&&Math.abs(t.minY-r.minY)<=n;if(s>e||a){const t=Ft(r.detection.boundingBox);h.push(t),o.add(r.detection.id),c=Math.max(c,r.detection.confidence)}}if(h.length>1){const t=St(dt(h));if(t){const e=(a=vt(t),[Math.max(0,Math.round(a[0])),Math.max(0,Math.round(a[1])),Math.min(1e3,Math.round(a[2])),Math.min(1e3,Math.round(a[3]))]);Ut(e)&&(i.boundingBox=e,i.confidence=c)}}Ut(i.boundingBox)&&s.push(i),o.add(i.id)}var a;return s}const zt=function(t,e){for(var n=0,r=0,i=0,s=0,o=0,a=0,c=0,h=0,u=null,l=null,p=t[0],f=t[1],d=e.length;n<d;n++){r=0;var g=e[n].length-1,y=e[n];if((u=y[0])[0]!==y[g][0]&&u[1]!==y[g][1])throw new Error("First and last coordinates in a ring must be the same");for(o=u[0]-p,a=u[1]-f;r<g;r++)if(h=(l=y[r+1])[1]-f,a<0&&h<0||a>0&&h>0)a=h,o=(u=l)[0]-p;else{if(c=l[0]-t[0],h>0&&a<=0){if((s=o*h-c*a)>0)i+=1;else if(0===s)return 0}else if(a>0&&h<=0){if((s=o*h-c*a)<0)i+=1;else if(0===s)return 0}else if(0===h&&a<0){if(0==(s=o*h-c*a))return 0}else if(0===a&&h<0){if(0==(s=o*h-c*a))return 0}else if(0===a&&0===h){if(c<=0&&o>=0)return 0;if(o<=0&&c>=0)return 0}u=l,a=h,o=c}}return i%2!=0};function Xt(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if("Feature"===t.type&&null!==t.geometry&&"Point"===t.geometry.type)return[...t.geometry.coordinates];if("Point"===t.type)return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function $t(t){return"Feature"===t.type?t.geometry:t}function Wt(t,e,n={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const r=Xt(t),i=$t(e),s=i.type,o=e.bbox;let a=i.coordinates;if(o&&!1===function(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}(r,o))return!1;"Polygon"===s&&(a=[a]);let c=!1;for(var h=0;h<a.length;++h){const t=zt(r,a[h]);if(0===t)return!n.ignoreBoundary;t&&(c=!0)}return c}function Gt(t,e,n={}){const r=Xt(t),i=function(t){if(Array.isArray(t))return t;if("Feature"===t.type){if(null!==t.geometry)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}(e);for(let t=0;t<i.length-1;t++){let e=!1;if(n.ignoreEndVertices&&(0===t&&(e="start"),t===i.length-2&&(e="end"),0===t&&t+1===i.length-1&&(e="both")),Ht(i[t],i[t+1],r,e,void 0===n.epsilon?null:n.epsilon))return!0}return!1}function Ht(t,e,n,r,i){const s=n[0],o=n[1],a=t[0],c=t[1],h=e[0],u=e[1],l=h-a,p=u-c,f=(n[0]-a)*p-(n[1]-c)*l;if(null!==i){if(Math.abs(f)>i)return!1}else if(0!==f)return!1;return r?"start"===r?Math.abs(l)>=Math.abs(p)?l>0?a<s&&s<=h:h<=s&&s<a:p>0?c<o&&o<=u:u<=o&&o<c:"end"===r?Math.abs(l)>=Math.abs(p)?l>0?a<=s&&s<h:h<s&&s<=a:p>0?c<=o&&o<u:u<o&&o<=c:"both"===r&&(Math.abs(l)>=Math.abs(p)?l>0?a<s&&s<h:h<s&&s<a:p>0?c<o&&o<u:u<o&&o<c):Math.abs(l)>=Math.abs(p)?l>0?a<=s&&s<=h:h<=s&&s<=a:p>0?c<=o&&o<=u:u<=o&&o<=c}function Jt(t,e){const n=$t(t),r=$t(e),i=n.type,s=r.type,o=n.coordinates,a=r.coordinates;switch(i){case"Point":if("Point"===s)return Zt(o,a);throw new Error("feature2 "+s+" geometry not supported");case"MultiPoint":switch(s){case"Point":return function(t,e){let n,r=!1;for(n=0;n<t.coordinates.length;n++)if(Zt(t.coordinates[n],e.coordinates)){r=!0;break}return r}(n,r);case"MultiPoint":return function(t,e){for(const n of e.coordinates){let e=!1;for(const r of t.coordinates)if(Zt(n,r)){e=!0;break}if(!e)return!1}return!0}(n,r);default:throw new Error("feature2 "+s+" geometry not supported")}case"LineString":switch(s){case"Point":return Gt(r,n,{ignoreEndVertices:!0});case"LineString":return function(t,e){let n=!1;for(const r of e.coordinates)if(Gt({type:"Point",coordinates:r},t,{ignoreEndVertices:!0})&&(n=!0),!Gt({type:"Point",coordinates:r},t,{ignoreEndVertices:!1}))return!1;return n}(n,r);case"MultiPoint":return function(t,e){let n=!1;for(const r of e.coordinates)if(Gt(r,t,{ignoreEndVertices:!0})&&(n=!0),!Gt(r,t))return!1;return!!n}(n,r);default:throw new Error("feature2 "+s+" geometry not supported")}case"Polygon":switch(s){case"Point":return Wt(r,n,{ignoreBoundary:!0});case"LineString":return function(t,e){let n=!1,r=0;if(!Qt(vt(t),vt(e)))return!1;for(;r<e.coordinates.length-1;r++)if(Wt({type:"Point",coordinates:(i=e.coordinates[r],s=e.coordinates[r+1],[(i[0]+s[0])/2,(i[1]+s[1])/2])},t,{ignoreBoundary:!0})){n=!0;break}var i,s;return n}(n,r);case"Polygon":return Kt(n,r);case"MultiPoint":return function(t,e){for(const n of e.coordinates)if(!Wt(n,t,{ignoreBoundary:!0}))return!1;return!0}(n,r);default:throw new Error("feature2 "+s+" geometry not supported")}case"MultiPolygon":if("Polygon"===s)return function(t,e){return t.coordinates.some((t=>Kt({type:"Polygon",coordinates:t},e)))}(n,r);throw new Error("feature2 "+s+" geometry not supported");default:throw new Error("feature1 "+i+" geometry not supported")}}function Kt(t,e){if("Feature"===t.type&&null===t.geometry)return!1;if("Feature"===e.type&&null===e.geometry)return!1;if(!Qt(vt(t),vt(e)))return!1;const n=$t(e).coordinates;for(const e of n)for(const n of e)if(!Wt(n,t))return!1;return!0}function Qt(t,e){return!(t[0]>e[0]||t[2]<e[2]||t[1]>e[1]||t[3]<e[3])}function Zt(t,e){return t[0]===e[0]&&t[1]===e[1]}class te{constructor(t=[],e=ee){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,r=e[t];for(;t>0;){const i=t-1>>1,s=e[i];if(n(r,s)>=0)break;e[t]=s,t=i}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,i=e[t];for(;t<r;){let r=1+(t<<1),s=e[r];const o=r+1;if(o<this.length&&n(e[o],s)<0&&(r=o,s=e[o]),n(s,i)>=0)break;e[t]=s,t=r}e[t]=i}}function ee(t,e){return t<e?-1:t>e?1:0}function ne(t,e){return t.p.x>e.p.x?1:t.p.x<e.p.x?-1:t.p.y!==e.p.y?t.p.y>e.p.y?1:-1:1}function re(t,e){return t.rightSweepEvent.p.x>e.rightSweepEvent.p.x?1:t.rightSweepEvent.p.x<e.rightSweepEvent.p.x?-1:t.rightSweepEvent.p.y!==e.rightSweepEvent.p.y?t.rightSweepEvent.p.y<e.rightSweepEvent.p.y?1:-1:1}class ie{constructor(t,e,n,r){this.p={x:t[0],y:t[1]},this.featureId=e,this.ringId=n,this.eventId=r,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(t){return this.p.x===t.p.x&&this.p.y===t.p.y}}let se=0,oe=0,ae=0;function ce(t,e){const n="Feature"===t.type?t.geometry:t;let r=n.coordinates;"Polygon"!==n.type&&"MultiLineString"!==n.type||(r=[r]),"LineString"===n.type&&(r=[[r]]);for(let t=0;t<r.length;t++)for(let n=0;n<r[t].length;n++){let i=r[t][n][0],s=null;oe+=1;for(let o=0;o<r[t][n].length-1;o++){s=r[t][n][o+1];const a=new ie(i,se,oe,ae),c=new ie(s,se,oe,ae+1);a.otherEvent=c,c.otherEvent=a,ne(a,c)>0?(c.isLeftEndpoint=!0,a.isLeftEndpoint=!1):(a.isLeftEndpoint=!0,c.isLeftEndpoint=!1),e.push(a),e.push(c),i=s,ae+=1}}se+=1}class he{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}}function ue(t,e){if(null===t||null===e)return!1;if(t.leftSweepEvent.ringId===e.leftSweepEvent.ringId&&(t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.rightSweepEvent)||t.leftSweepEvent.isSamePoint(e.leftSweepEvent)||t.leftSweepEvent.isSamePoint(e.rightSweepEvent)))return!1;const n=t.leftSweepEvent.p.x,r=t.leftSweepEvent.p.y,i=t.rightSweepEvent.p.x,s=t.rightSweepEvent.p.y,o=e.leftSweepEvent.p.x,a=e.leftSweepEvent.p.y,c=e.rightSweepEvent.p.x,h=e.rightSweepEvent.p.y,u=(h-a)*(i-n)-(c-o)*(s-r);if(0===u)return!1;const l=((c-o)*(r-a)-(h-a)*(n-o))/u,p=((i-n)*(r-a)-(s-r)*(n-o))/u;return l>=0&&l<=1&&p>=0&&p<=1&&[n+l*(i-n),r+l*(s-r)]}var le=function(t,e){const n=new te([],ne);return function(t,e){if("FeatureCollection"===t.type){const n=t.features;for(let t=0;t<n.length;t++)ce(n[t],e)}else ce(t,e)}(t,n),function(t,e){e=e||!1;const n=[],r=new te([],re);for(;t.length;){const i=t.pop();if(i.isLeftEndpoint){const t=new he(i);for(let s=0;s<r.data.length;s++){const o=r.data[s];if(e&&o.leftSweepEvent.featureId===i.featureId)continue;const a=ue(t,o);!1!==a&&n.push(a)}r.push(t)}else!1===i.isLeftEndpoint&&r.pop()}return n}(n,e)};function pe(t,e,n={}){const{removeDuplicates:r=!0,ignoreSelfIntersections:i=!1}=n;let s=[];"FeatureCollection"===t.type?s=s.concat(t.features):"Feature"===t.type?s.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||s.push(pt(t)),"FeatureCollection"===e.type?s=s.concat(e.features):"Feature"===e.type?s.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||s.push(pt(e));const o=le(dt(s),i);let a=[];if(r){const t={};o.forEach((e=>{const n=e.join(",");t[n]||(t[n]=!0,a.push(e))}))}else a=o;return dt(a.map((t=>function(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!gt(t[0])||!gt(t[1]))throw new Error("coordinates must contain numbers");return pt({type:"Point",coordinates:t},e,n)}(t))))}function fe(t,e={}){const n=$t(t);switch(e.properties||"Feature"!==t.type||(e.properties=t.properties),n.type){case"Polygon":return function(t,e={}){return de($t(t).coordinates,e.properties?e.properties:"Feature"===t.type?t.properties:{})}(n,e);case"MultiPolygon":return function(t,e={}){const n=$t(t).coordinates,r=e.properties?e.properties:"Feature"===t.type?t.properties:{},i=[];return n.forEach((t=>{i.push(de(t,r))})),dt(i)}(n,e);default:throw new Error("invalid poly")}}function de(t,e){return t.length>1?function(t,e,n={}){return pt({type:"MultiLineString",coordinates:t},e,n)}(t,e):function(t,e,n={}){if(t.length<2)throw new Error("coordinates must be an array of two or more positions");return pt({type:"LineString",coordinates:t},e,n)}(t[0],e)}function ge(t,e){for(let n=0;n<t.coordinates.length-1;n++)if(me(t.coordinates[n],t.coordinates[n+1],e.coordinates))return!0;return!1}function ye(t,e,n){for(const n of e.coordinates)if(Wt(n,t))return!0;return pe(e,fe(t),{ignoreSelfIntersections:n}).features.length>0}function me(t,e,n){const r=n[0]-t[0],i=n[1]-t[1],s=e[0]-t[0],o=e[1]-t[1];return 0==r*o-i*s&&(Math.abs(s)>=Math.abs(o)?s>0?t[0]<=n[0]&&n[0]<=e[0]:e[0]<=n[0]&&n[0]<=t[0]:o>0?t[1]<=n[1]&&n[1]<=e[1]:e[1]<=n[1]&&n[1]<=t[1])}function be(t,e,n={}){var r;const i=null!=(r=n.ignoreSelfIntersections)&&r;let s=!1;return bt(t,(t=>{bt(e,(e=>{if(!0===s)return!0;s=!function(t,e,n={}){var r;const i=null!=(r=n.ignoreSelfIntersections)&&r;let s=!0;return bt(t,(t=>{bt(e,(e=>{if(!1===s)return!1;s=function(t,e,n){switch(t.type){case"Point":switch(e.type){case"Point":return r=t.coordinates,i=e.coordinates,!(r[0]===i[0]&&r[1]===i[1]);case"LineString":return!ge(e,t);case"Polygon":return!Wt(t,e)}break;case"LineString":switch(e.type){case"Point":return!ge(t,e);case"LineString":return!function(t,e,n){return pe(t,e,{ignoreSelfIntersections:n}).features.length>0}(t,e,n);case"Polygon":return!ye(e,t,n)}break;case"Polygon":switch(e.type){case"Point":return!Wt(e,t);case"LineString":return!ye(t,e,n);case"Polygon":return!function(t,e,n){for(const n of t.coordinates[0])if(Wt(n,e))return!0;for(const n of e.coordinates[0])if(Wt(n,t))return!0;return pe(fe(t),fe(e),{ignoreSelfIntersections:n}).features.length>0}(e,t,n)}}var r,i;return!1}(t.geometry,e.geometry,i)}))})),s}(t.geometry,e.geometry,{ignoreSelfIntersections:i})}))})),s}const ve=(t,e)=>{const{origWidth:n,origHeight:r}=e,i=t.points.map((([t,e])=>[t*n/100,e*r/100]));return i.length>0&&!we(i[0],i[i.length-1])&&i.push(i[0]),{...t,points:i}},we=(t,e)=>t[0]===e[0]&&t[1]===e[1],xe=t=>{const{origWidth:e,origHeight:n,inputWidth:r,inputHeight:i}=t;let[s,o,a,c]=t.boundingBox;return s=s*e/r,o=o*n/i,a=a*e/r,c=c*n/i,s=Math.max(0,Math.min(s,e)),o=Math.max(0,Math.min(o,n)),a=Math.max(0,Math.min(a,e)),c=Math.max(0,Math.min(c,n)),{...t,boundingBox:[s,o,a,c]}},Se=(t,e,n)=>{const r=[];for(const i of t)_e(xe(i),e,n)&&e.some((t=>!t.classes.length||t.classes.includes(i.label)))&&r.push(i);return r},_e=(t,e,n)=>{if(t.confidence<n.object.confidence)return!1;if(0===e.length)return!0;const[r,i,s,o]=t.boundingBox,a=wt([r,i,s,o]);for(const n of e){const e=ve(n,t),r=ft([e.points]);if(e.classes.length>0&&!e.classes.includes(t.label))continue;const i=be(a,r),s=Jt(r,a);if(e.isPrivacyMask){if(i||s)return!1}else if("include"===e.filter){if("contain"===e.type){if(s)return!0}else if("intersect"===e.type&&(i||s))return!0}else if("exclude"===e.filter)if("contain"===e.type){if(!s)return!0}else if("intersect"===e.type&&!i&&!s)return!0}return!1};class Ee extends o{logger;snapshotCache;cameraSubject;cameraState=new H(!1);lightState=new H(this.getLightState({state:!1},!0));motionState=new H(this.getMotionState({detections:[],state:!1},!0));audioState=new H(this.getAudioState({state:!1,db:0},!0));objectState=new H(this.getObjectState({detections:[]},!0));doorbellState=new H(this.getDoorbellState({state:!1},!0));sirenState=new H(this.getSirenState({state:!1,level:0},!0));batteryState=new H(this.getBatteryState({level:100,charging:!1,lowBattery:!1},!0));onConnected=this.createStateObservable(this.cameraState);onLightSwitched=this.createStateObservable(this.lightState);onMotionDetected=this.createStateObservable(this.motionState);onAudioDetected=this.createStateObservable(this.audioState);onObjectDetected=this.createStateObservable(this.objectState);onDoorbellPressed=this.createStateObservable(this.doorbellState);onSirenDetected=this.createStateObservable(this.sirenState);onBatteryChanged=this.createStateObservable(this.batteryState);get cameraObject(){return c(this.cameraSubject.getValue())}get id(){return this.cameraSubject.getValue()._id}get nativeId(){return this.cameraSubject.getValue().nativeId}get pluginId(){return this.cameraSubject.getValue().pluginId}get connected(){return this.cameraState.getValue()}get disabled(){return this.cameraSubject.getValue().disabled}get name(){return this.cameraSubject.getValue().name}get type(){return this.cameraSubject.getValue().type}get info(){return c(this.cameraSubject.getValue().info)}get isCloud(){return this.cameraSubject.getValue().isCloud}get hasLight(){return this.cameraSubject.getValue().hasLight}get hasSiren(){return this.cameraSubject.getValue().hasSiren}get hasBinarySensor(){return this.cameraSubject.getValue().hasBinarySensor}get hasBattery(){return this.cameraSubject.getValue().hasBattery}get hasMotionDetector(){return this.cameraSubject.getValue().hasMotionDetector}get extendedMotionDetector(){return this.cameraSubject.getValue().extendedMotionDetector}get hasAudioDetector(){return this.cameraSubject.getValue().hasAudioDetector}get hasObjectDetector(){return this.cameraSubject.getValue().hasObjectDetector}get hasPtz(){return this.cameraSubject.getValue().hasPtz}get hasPrebuffer(){return this.cameraSubject.getValue().hasPrebuffer}get snapshotTTL(){return this.cameraSubject.getValue().snapshotTTL}get activityZones(){return c(this.cameraSubject.getValue().activityZones)}get activitySettings(){return c(this.cameraSubject.getValue().activitySettings)}get frameWorkerSettings(){return c(this.cameraSubject.getValue().frameWorkerSettings)}get streamSource(){return this.highResolutionSource??this.midResolutionSource??this.lowResolutionSource}get snapshotSource(){const t=this.sources.find((t=>t.roles.includes("snapshot")&&!t.internal));if(t)return{_id:t._id,name:t.name,roles:t.roles,urls:t.urls,internal:t.internal}}get highResolutionSource(){return this.sources.find((t=>t.roles.includes("high-resolution")&&!t.internal))}get midResolutionSource(){return this.sources.find((t=>t.roles.includes("mid-resolution")&&!t.internal))}get lowResolutionSource(){return this.sources.find((t=>t.roles.includes("low-resolution")&&!t.internal))}get ptz(){return this.ptzDelegate}constructor(t,e){super(),this.logger=e,this.cameraSubject=new H(t),this.updateCamera(t),this.snapshotCache=new(u())({max:100,ttl:1e3*this.snapshotTTL}),"native"===t.pluginId&&this.cameraState.next(!0)}getValue(t){switch(t){case"light":return c(this.lightState.getValue());case"motion":return c(this.motionState.getValue());case"audio":return c(this.audioState.getValue());case"object":return c(this.objectState.getValue());case"doorbell":return c(this.doorbellState.getValue());case"siren":return c(this.sirenState.getValue());case"battery":return c(this.batteryState.getValue());default:throw new Error(`Unknown state: ${t}`)}}async snapshot(t){this.snapshotCache.purgeStale();const e=this.snapshotSource??this.streamSource,n=e.urls.www.jpegSnapshot,r=this.snapshotCache.get(e._id);if(!t&&r)return r;try{if("native"!==this.cameraObject.pluginId){const t=await this.cameraDelegate.snapshot();if(t&&t.byteLength>0)return this.snapshotCache.set(e._id,t),t}const t=new AbortController,r=setTimeout((()=>t.abort()),5e3),i=await fetch(n,{signal:t.signal});if(clearTimeout(r),!i.ok)throw new Error("Status Code: "+i.status);const s=await i.arrayBuffer();return s.byteLength>0&&this.snapshotCache.set(e._id,s),s}catch{return}}onStateChange(t){return this[`${t}State`].pipe(et(),nt((([e,n])=>"boolean"==typeof e||"boolean"==typeof n?e!==n:this.stateChanged(e,n,t))),rt((([t,e])=>({oldState:t,newState:e}))),ct({connector:()=>new K(1)}))}onPropertyChange(t){return this.cameraSubject.pipe(et(),ut((([e,n])=>(Array.isArray(t)?t:[t]).map((t=>({property:t,oldData:e[t],newData:n[t]}))))),nt((({oldData:t,newData:e})=>!a(t,e,!0))),ct({connector:()=>new K(1)}))}removeAllListeners(){this.lightState.complete(),this.motionState.complete(),this.audioState.complete(),this.objectState.complete(),this.doorbellState.complete(),this.sirenState.complete(),this.batteryState.complete(),this.cameraSubject.complete(),this.cameraState.complete()}updateCamera(t){t.snapshotTTL!==this.snapshotTTL&&this.snapshotCache.clear(),this.cameraSubject.next(t)}updateCameraState(t){this.cameraState.next(t)}updateStateInternal(t,e,n,r){let i,s=!1;if(n)s=!0,i=e;else{const n=this.checkStateInternal(t,e,r);s=n.changed,i=n.event}if(s)switch(t){case"light":this.lightState.next(this.getLightState(i));break;case"motion":this.motionState.next(this.getMotionState(i));break;case"audio":this.audioState.next(this.getAudioState(i));break;case"object":this.objectState.next(this.getObjectState(i));break;case"doorbell":this.doorbellState.next(this.getDoorbellState(i));break;case"siren":this.sirenState.next(this.getSirenState(i));break;case"battery":this.batteryState.next(this.getBatteryState(i));break;default:throw new Error(`Unknown state: ${t}`)}}checkStateInternal(t,e,n){let r,i=!1;switch(t){case"audio":const s=e;r=this.getAudioState(s),i=this.stateChanged(this.getValue("audio"),r,"audio");break;case"light":const o=e;r=this.getLightState(o),i=this.stateChanged(this.getValue("light"),r,"light");break;case"motion":const a=e;void 0!==a.state&&(a.detections=[]),n||(a.detections=Yt(a.detections),a.detections=Se(a.detections,this.activityZones,this.activitySettings)),r=this.getMotionState(a),i=this.stateChanged(this.getValue("motion"),r,"motion");break;case"object":const c=e;n||(c.detections=Yt(c.detections),c.detections=Se(c.detections,this.activityZones,this.activitySettings)),r=this.getObjectState(c),i=this.stateChanged(this.getValue("object"),r,"object");break;case"doorbell":const h=e;r=this.getDoorbellState(h),i=this.stateChanged(this.getValue("doorbell"),r,"doorbell");break;case"siren":const u=e;r=this.getSirenState(u),i=this.stateChanged(this.getValue("siren"),r,"siren");break;case"battery":const l=e;r=this.getBatteryState(l),i=this.stateChanged(this.getValue("battery"),r,"battery");break;default:throw new Error(`Unknown state: ${t}`)}return{changed:i,event:r}}stateChanged(t,e,n){if(!t||!e||!n)return!1;if("audio"==n){if(!this.hasAudioDetector)return!1;const n=t,r=e;return n.state!==r.state||n.db!==r.db}if("motion"==n){if(!this.hasMotionDetector)return!1;const n=t,r=e;return void 0!==r.state?n.state!==r.state:!a(n.detections,r.detections,!0)}if("object"==n){if(!this.hasObjectDetector)return!1;const n=e;return!a(t.detections,n.detections,!0)}if("siren"==n){if(!this.hasSiren)return!1;const n=t,r=e;return n.state!==r.state||n.level!==r.level}if("battery"==n){if(!this.hasBattery)return!1;const n=t,r=e;return n.level!==r.level||n.lowBattery!==r.lowBattery||n.charging!==r.charging}if("doorbell"==n){if(!this.hasBinarySensor)return!1;const n=e;return t.state!==n.state}if("light"==n){if(!this.hasLight)return!1;const n=e;return t.state!==n.state}return!1}getAudioState(t,e=!1){let n,r;if(!e){const t=this.getValue("audio");t.state?n=t:t.lastEvent?.state&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,db:e.db??n?.db??0,lastEvent:n||(e.state?e:void 0)}}return r}getMotionState(t,e=!1){let n,r;if(!e){const t=this.getValue("motion");t.detections.length?n=t:t.lastEvent?.detections.length&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.detections.length?e:void 0)}}return r}getObjectState(t,e=!1){let n,r;if(!e){const t=this.getValue("object");t.detections.length?n=t:t.lastEvent?.detections.length&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.detections.length?e:void 0)}}return r}getDoorbellState(t,e=!1){let n,r;if(!e){const t=this.getValue("doorbell");t.state?n=t:t.lastEvent?.state&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.state?e:void 0)}}return r}getLightState(t,e=!1){let n,r;if(!e){const t=this.getValue("light");t.state?n=t:t.lastEvent?.state&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.state?e:void 0)}}return r}getSirenState(t,e=!1){let n,r;if(!e){const t=this.getValue("siren");t.state?n=t:t.lastEvent?.state&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,level:e.level??n?.level??0,lastEvent:n||(e.state?e:void 0)}}return r}getBatteryState(t,e=!1){let n,r;if(!e){const e=this.getValue("battery");this.stateChanged(e,t,"battery")?n=e:e.lastEvent&&this.stateChanged(e.lastEvent,t,"battery")&&(n=e.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,charging:t.charging??n?.charging??!1,lowBattery:t.lowBattery??n?.lowBattery??!1,lastEvent:n??e}}return r}isStateEvent(t){return"timestamp"in t}createStateObservable(t){return t.pipe((void 0===n&&(n=Y),e=null!=e?e:lt,Q((function(t,r){var i,s=!0;t.subscribe(Z(r,(function(t){var o=n(t);!s&&e(i,o)||(s=!1,i=o,r.next(t))})))}))),ct({connector:()=>new K(1)}));var e,n}}class ke{delegate;onRequest;constructor(t){this.onRequest=t}async snapshot(){return this.delegate?this.delegate.snapshot():this._onRequest("snapshot",[],5e3)}_onRequest(t,e,n){return this.onRequest("cameraDelegate",t,e,n)}}class Pe{delegate;onRequest;constructor(t){this.onRequest=t}async getPrebufferingState(t,e){return this.delegate?this.delegate.getPrebufferingState(t,e):this._onRequest("prebufferDelegate","getPrebufferingState",[t,e])}_onRequest(t,e,n,r){return this.onRequest(t,e,n,r)}}class Re{delegate;onRequest;constructor(t){this.onRequest=t}async moveAbsolute(t,e,n){return this.delegate?this.delegate.moveAbsolute(t,e,n):this._onRequest("moveAbsolute",[t,e,n])}async moveRelative(t,e,n){return this.delegate?this.delegate.moveRelative(t,e,n):this._onRequest("moveRelative",[t,e,n])}async moveContinuous(t,e,n){return this.delegate?this.delegate.moveContinuous(t,e,n):this._onRequest("moveContinuous",[t,e,n])}async stop(){return this.delegate?this.delegate.stop():this._onRequest("stop",[])}_onRequest(t,e,n){return this.onRequest("ptzDelegate",t,e,n)}}const Me=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}));class Te extends EventTarget{cameraDevice;socketService;logger;options;videoPlayer;socket;streamId;hasBackchannel=!1;hasAudio=!0;closed=!1;micTransceiver=null;pc=null;buf=new Uint8Array(2097152);mediaSource=null;sourceBuffer=null;bufLen=0;mseCodecs="";videoPlayerMp4;media=["video","audio","microphone"];codecList=[];reconnectTimeout;_finishLoading=!1;_firstFrameReceived=!1;animationFrameId;get mode(){return this.options.mode}webrtcReconnectTimeout;constructor(t,e,n,r){super(),this.options=r,this.videoPlayer=r.videoElement,this.cameraDevice=t,this.socketService=e,this.logger=n;const{socket:i}=this.socketService.getSocket(`${t.id}-go2rtcSession`,!0);this.socket=i,this.socket.connect(),this.streamId=Me(),this.createCodecsList()}connect(t){t&&(this.options.mode=t),console.log(this.cameraDevice.name,`Connecting... (${this.options.mode})`),this.socket.on("ws-open",this.onWsOpen.bind(this)),this.socket.on("ws-close",this.onWsClose.bind(this)),this.socket.on("ws-message",this.onWsMessage.bind(this)),this.socket.emit("ws-open",{id:this.streamId,cameraSource:this.options.sourceName,mode:this.options.mode})}disconnect(){console.log(this.cameraDevice.name,"Disconnecting..."),this.socket.removeListener("ws-open",this.onWsOpen.bind(this)),this.socket.removeListener("ws-close",this.onWsClose.bind(this)),this.socket.removeListener("ws-message",this.onWsMessage.bind(this)),this.socket.emit("ws-close",{id:this.streamId})}async reconnect(t){console.log(this.cameraDevice.name,"Reconnecting..."),this.dispatchEvent(new Event("reconnect")),this.close(),await new Promise((t=>setTimeout(t,100))),this.connect(t)}reset(){this._finishLoading=!1,this._firstFrameReceived=!1,this.pc?.getTransceivers().forEach((t=>t.sender?.track?.stop())),this.pc?.close(),this.pc=null,this.videoPlayerMp4?.remove(),this.videoPlayerMp4=void 0,this.videoPlayer.srcObject=null,this.videoPlayer.src="",this.videoPlayer.poster="",void 0!==this.animationFrameId&&("cancelVideoFrameCallback"in this.videoPlayer?this.videoPlayer.cancelVideoFrameCallback(this.animationFrameId):cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}close(){console.log(this.cameraDevice.name,"Closing..."),this.closed=!0,this.reset(),this.disconnect(),this.socket.emit("end"),this.socket.removeAllListeners()}onWsOpen({id:t}){if(t===this.streamId)switch(console.log(this.cameraDevice.name,"Connected"),this.options.mode){case"webrtc":case"webrtc/tcp":console.log(this.cameraDevice.name,"Requesting WebRTC session..."),this.requestWebrtc();break;case"mse":console.log(this.cameraDevice.name,"Requesting MSE session..."),this.requestMse();break;case"hls":console.log(this.cameraDevice.name,"Requesting HLS session..."),this.requestHls();break;case"mp4":console.log(this.cameraDevice.name,"Requesting MP4 session..."),this.requestMp4();break;case"mjpeg":console.log(this.cameraDevice.name,"Requesting MJPEG session..."),this.requestMjpeg();break;default:console.log(this.cameraDevice.name,"Unknown mode:",this.options.mode),this.dispatchEvent(new ErrorEvent("error",{message:"Unknown mode: "+this.options.mode}))}}onWsClose({id:t}){t===this.streamId&&(this.closed||void 0===this.options.reconnectInterval||(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=setTimeout((()=>{this.reconnect()}),this.options.reconnectInterval)))}onWsMessage({id:t,data:e}){if(t===this.streamId&&e.type){switch(e.type){case"mse":this.onMseData(e);break;case"hls":this.onHlsData(e);break;case"webrtc/candidate":case"webrtc/answer":this.onWebrtcData(e);break;case"mse-binary":this.onMseBuffer(e);break;case"mjpeg-binary":this.onMjpegBuffer(e);break;case"mp4-binary":this.onMp4Buffer(e);break;case"stream-info":this.onStreamInfo(e);break;case"error":this.dispatchEvent(new ErrorEvent("error",{error:e,message:e.value}))}!this._firstFrameReceived&&["mse-binary","mjpeg-binary","mp4-binary"].includes(e.type)&&this.onFirstFrame()}}async requestWebrtc(){this.reset(),this.pc=new RTCPeerConnection({bundlePolicy:"max-bundle",iceServers:[{urls:"stun:stun.l.google.com:19302"}],sdpSemantics:"unified-plan"}),this.pc.onicecandidate=t=>{if(console.log(this.cameraDevice.name,"onicecandidate",t.candidate),"webrtc/tcp"===this.options.mode&&"udp"===t.candidate?.protocol)return;const e=t.candidate?.toJSON().candidate??"";this.socket.emit("stream-payload",{id:this.streamId,data:{type:"webrtc/candidate",value:e}})},this.pc.onconnectionstatechange=()=>{if(console.log(this.cameraDevice.name,"onconnectionstatechange:",this.pc?.connectionState),"connected"===this.pc?.connectionState){const t=this.pc?.getTransceivers().filter((t=>"recvonly"===t.currentDirection)).map((t=>t.receiver.track));this.videoPlayer.srcObject=new MediaStream(t),this.onFinishLoading(),this.play(),this.disconnect()}else"failed"!==this.pc?.connectionState&&"disconnected"!==this.pc?.connectionState||(clearTimeout(this.webrtcReconnectTimeout),this.webrtcReconnectTimeout=setTimeout((()=>{"failed"!==this.pc?.connectionState&&"disconnected"!==this.pc?.connectionState||this.reconnect()}),1e3))},this.pc.oniceconnectionstatechange=()=>{console.log(this.cameraDevice.name,"iceconnectionstatechange",this.pc?.iceConnectionState)},this.pc.onicecandidateerror=t=>{console.log(this.cameraDevice.name,"onicecandidateerror",t)},this.pc.onsignalingstatechange=()=>{console.log(this.cameraDevice.name,"onsignalingstatechange",this.pc?.signalingState)},this.pc.onicegatheringstatechange=()=>{console.log(this.cameraDevice.name,"onicegatheringstatechange",this.pc?.iceGatheringState)},this.pc.onnegotiationneeded=t=>{console.log(this.cameraDevice.name,"onnegotiationneeded",t)},this.pc.addTransceiver("video",{direction:"recvonly"}),this.pc.addTransceiver("audio",{direction:"recvonly"}),this.micTransceiver=this.pc.addTransceiver("audio",{direction:"sendonly"});const t=await this.pc.createOffer();await this.pc.setLocalDescription(t),console.log(this.cameraDevice.name,"Offer:",t.sdp),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"webrtc/offer",value:t.sdp}})}async onWebrtcData(t){try{switch(t.type){case"webrtc/candidate":if(console.log(this.cameraDevice.name,"remote candidate:",t.value),"webrtc/tcp"===this.options.mode&&t.value.indexOf(" udp ")>0)return;await(this.pc?.addIceCandidate({candidate:t.value,sdpMid:"0"}));break;case"webrtc/answer":if(console.log(this.cameraDevice.name,"Answer:",t.value),await(this.pc?.setRemoteDescription({type:"answer",sdp:t.value})),!this._firstFrameReceived&&this.pc){const t=this.pc.getReceivers().find((t=>"video"===t.track.kind))?.track;if(t)if("requestVideoFrameCallback"in t)this.animationFrameId=t.requestVideoFrameCallback((()=>{this.onFirstFrame()}));else{const t=()=>{this.videoPlayer.readyState>=2&&this.videoPlayer.videoWidth>0?this.onFirstFrame():this.animationFrameId=requestAnimationFrame(t)};this.animationFrameId=requestAnimationFrame(t)}}break;case"error":if(console.log(this.cameraDevice.name,"WebRTC Error:",t.value),t.value.indexOf("webrtc/offer")<0)return;this.pc?.close()}}catch(t){this.dispatchEvent(new ErrorEvent("error",{error:t,message:t.message}))}}requestMse(){if(this.reset(),"ManagedMediaSource"in window){console.log(this.cameraDevice.name,"Using ManagedMediaSource");const t=window.ManagedMediaSource;this.mediaSource=new t,this.mediaSource.addEventListener("sourceopen",(()=>{this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mse",value:this.parseCodecs(t.isTypeSupported.bind(this))}})}),{once:!0}),this.videoPlayer.disableRemotePlayback=!0,this.videoPlayer.srcObject=this.mediaSource}else console.log(this.cameraDevice.name,"Using MediaSource"),this.mediaSource=new MediaSource,this.mediaSource.addEventListener("sourceopen",(()=>{URL.revokeObjectURL(this.videoPlayer.src),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mse",value:this.parseCodecs(MediaSource.isTypeSupported.bind(this))}})}),{once:!0}),this.videoPlayer.src=URL.createObjectURL(this.mediaSource),this.videoPlayer.srcObject=null;this.play(),this.mseCodecs=""}onMseData(t){this.mediaSource&&(this.mseCodecs=t.value,this.bufLen=0,this.buf=new Uint8Array(2097152),this.sourceBuffer=this.mediaSource.addSourceBuffer(t.value),this.sourceBuffer.mode="segments",this.sourceBuffer.addEventListener("updateend",(()=>{if(!this.sourceBuffer?.updating)try{if(this.bufLen>0){const t=this.buf.slice(0,this.bufLen);this.bufLen=0,this.sourceBuffer?.appendBuffer(t)}else if(this.sourceBuffer?.buffered?.length){const t=this.sourceBuffer.buffered.end(this.sourceBuffer.buffered.length-1)-15,e=this.sourceBuffer.buffered.start(0);t>e&&(this.sourceBuffer.remove(e,t),this.mediaSource?.setLiveSeekableRange(t,t+15))}}catch{}})))}async onMseBuffer(t){if("closed"!==this.mediaSource?.readyState)if(this.onFinishLoading(),this.sourceBuffer?.updating||this.bufLen>0){const e=new Uint8Array(t.value);this.buf.set(e,this.bufLen),this.bufLen+=e.byteLength}else try{this.sourceBuffer?.appendBuffer(t.value)}catch{}else this.closed||(this.closed=!0,this.dispatchEvent(new ErrorEvent("error",{message:"MediaSource closed"})),this.options.mode="webrtc",this.requestWebrtc())}requestMjpeg(){this.reset(),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mjpeg"}})}onMjpegBuffer(t){this.videoPlayer.controls=!1,this.videoPlayer.poster="data:image/jpeg;base64,"+this.btoaBinary(t.value),this.onFinishLoading()}requestMp4(){this.reset();const t=document.createElement("canvas");let e=null;this.videoPlayerMp4=document.createElement("video"),this.videoPlayerMp4.autoplay=!0,this.videoPlayerMp4.playsInline=!0,this.videoPlayerMp4.muted=!0,this.videoPlayerMp4.addEventListener("loadeddata",(()=>{this.videoPlayerMp4&&(e||(t.width=this.videoPlayerMp4.videoWidth,t.height=this.videoPlayerMp4.videoHeight,e=t.getContext("2d")),e?.drawImage(this.videoPlayerMp4,0,0,t.width,t.height),this.videoPlayer.controls=!1,this.videoPlayer.poster=t.toDataURL("image/jpeg"))}));const n=this.codecList.filter((t=>this.media.includes(t.indexOf("vc1")>0?"video":"audio"))).filter((t=>this.videoPlayer.canPlayType(`video/mp4; codecs="${t}"`))).join();console.log(this.cameraDevice.name,"Playable codecs (MP4):",n),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mp4",value:n}})}onMp4Buffer(t){this.onFinishLoading(),this.videoPlayerMp4&&(this.videoPlayerMp4.src="data:video/mp4;base64,"+this.btoaBinary(t.value))}requestHls(){this.reset();const t=this.parseCodecs((t=>this.videoPlayer.canPlayType(t)));console.log(this.cameraDevice.name,"Playable codecs (HLS):",t),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"hls",value:t}})}onHlsData(t){const e="http"+t.wsURL.substring(2,t.wsURL.indexOf("/ws"))+"/hls/",n=t.value.replace("hls/",e),r="data:application/vnd.apple.mpegurl;base64,"+btoa(n.toString());this.videoPlayer.src=r,this.onFinishLoading(),this.play()}onStreamInfo(t){const e=t.value,n=e?.producers[0];n&&(this.hasBackchannel=n.senders?.some((t=>"audio"===t.codec.codec_type))??!1,this.hasAudio=n.receivers?.some((t=>"audio"===t.codec.codec_type))??!1)}async play(){try{await this.videoPlayer.play()}catch(t){if(!this.videoPlayer.muted)return this.videoPlayer.muted=!0,this.play();this.logger.warn(this.cameraDevice.name,t)}}onFirstFrame(){this._firstFrameReceived||(this._firstFrameReceived=!0,this.dispatchEvent(new Event("onFirstFrame")),console.log(this.cameraDevice.name,"First frame received"))}onFinishLoading(){this._finishLoading||(this._finishLoading=!0,this.dispatchEvent(new Event("onFinishLoading")))}createCodecsList(){const t=["avc1.640029","avc1.64002A","avc1.640033","hvc1.1.6.L153.B0","mp4a.40.2","mp4a.40.5","flac","opus"],e="undefined"==typeof window?null:/Version\/(\d+).+Safari/.exec(navigator.userAgent);if(e?.[1]){const n=e[1]<"13"?"mp4a.40.2":e[1]<"14"?"flac":"opus";t.splice(t.indexOf(n))}this.codecList=t}parseCodecs(t){return this.codecList.filter((t=>this.media.includes(t.indexOf("vc1")>0?"video":"audio"))).filter((e=>t(`video/mp4; codecs="${e}"`))).join()}btoaBinary(t){const e=new Uint8Array(t),n=e.byteLength;let r="";for(let t=0;t<n;t++)r+=String.fromCharCode(e[t]);return window.btoa(r)}}class Oe extends Ee{socketService;socket;pluginName="@camera.ui/client";subject;_started=!1;get started(){return this._started}cameraDelegate=new ke(this.onRequest.bind(this));ptzDelegate=new Re(this.onRequest.bind(this));prebufferDelegate=new Pe(this.onRequest.bind(this));get sources(){return JSON.parse(JSON.stringify(this.cameraSubject.getValue().sources)).filter((t=>!t.internal)).map((t=>({...t,getPrebufferingState:e=>this.prebufferDelegate.getPrebufferingState(t.name,e),probeStream:(e,n=!1)=>this.onRequest("cameraFn","probeStream",[t._id,e,n]),getInternalSource:e=>this.internalSources.find((n=>n._id===`${t._id}-${e}`))})))}get internalSources(){return JSON.parse(JSON.stringify(this.cameraSubject.getValue().sources)).filter((t=>t.internal)).map((t=>({...t,probeStream:(e,n=!1)=>this.onRequest("cameraFn","probeStream",[t._id,e,n]),type:t.name.endsWith(" AAC")?"aac":t.name.endsWith(" OPUS")?"opus":"pcma"})))}constructor(t,e,n){super(t,n),this.socketService=e;const{socket:r}=this.socketService.getSocket(this.id,!0);this.socket=r,this.socket.connect(),this.subject=`${this.pluginName}.camera.${this.id}`,this.listenToMessages()}async start(){this._started||(this._started=!0,await this.refreshStates(),this.socket.emit("joinRoomStates",this.id))}stop(){this._started=!1,this.socket.emit("leaveRoomStates",this.id)}close(){this.cleanup()}connect(){return this.onRequest("cameraFn","connect")}disconnect(){return this.onRequest("cameraFn","disconnect")}createWebRTCSession(t){return new Te(this,this.socketService,this.logger,t)}async refreshStates(){const t=await this.onRequest("cameraFn","refreshStates");super.updateCamera(t.camera),super.updateCameraState(t.cameraState);for(const[e,n]of Object.entries(t.states))super.updateStateInternal(e,n,!0)}async cleanup(){this.stop(),this.removeAllListeners(),this.unsubscribe(),this.socket.removeAllListeners()}listenToMessages(){this.socket.emit("joinRoomDevice",this.id),this.socket.on("updateState",(t=>{t.cameraId===this.id&&super.updateStateInternal(t.stateName,t.data.newEvent,!0)})),this.socket.on("updateDevice",(t=>{if(t.cameraId===this.id)switch(t.type){case"removed":this.cleanup();break;case"updated":super.updateCamera(t.data);break;case"cameraState":super.updateCameraState(t.data)}}))}onRequest(t,e,n=[]){const r={requestId:Me(),targetId:this.subject,targetName:this.name,pluginId:this.pluginName,cameraId:this.id,type:"request",proxy:"camera",client:t,fn:e,args:n,timestamp:Date.now(),timeout:5e3};return new Promise(((t,e)=>{this.socket.emit("request",r,(n=>{n.error?e(n.error):t(n.response)}))}))}}class Ae{socketService;socket;logger;pluginName="@camera.ui/client";subject;constructor(t,e){this.socketService=t,this.socket=t.socket,this.logger=e,this.subject=`${this.pluginName}.coreManager`}async getFFmpegPath(){return this.onRequest("getFFmpegPath")}async getHwaccelInfo(t){return this.onRequest("getHwaccelInfo",[t])}async getServerAddresses(){return this.onRequest("getServerAddresses")}async getIceServers(){return this.onRequest("getIceServers")}onRequest(t,e){const n={requestId:Me(),targetId:this.subject,targetName:this.pluginName,pluginId:this.pluginName,type:"request",proxy:"core",client:"coreFn",fn:t,args:e??[],timestamp:Date.now(),timeout:5e3};return new Promise(((t,e)=>{this.socket.emit("request",n,(n=>{n.error?e(n.error):t(n.response)}))}))}}class Ce{socketService;socket;logger;pluginName="@camera.ui/client";subject;constructor(t,e){this.socketService=t,this.socket=t.socket,this.logger=e,this.subject=`${this.pluginName}.deviceManager`}async getCameraById(t){const e=await this.onRequest("getCameraById",[t]);if(e){const t=new Oe(e,this.socketService,this.logger);return await t.refreshStates(),t}}async getCameraByName(t){const e=await this.onRequest("getCameraByName",[t]);if(e){const t=new Oe(e,this.socketService,this.logger);return await t.refreshStates(),t}}onRequest(t,e){const n={requestId:Me(),targetId:this.subject,targetName:this.pluginName,pluginId:this.pluginName,type:"request",proxy:"device",client:"deviceFn",fn:t,args:e??[],timestamp:Date.now(),timeout:5e3};return new Promise(((t,e)=>{this.socket.emit("request",n,(n=>{n.error?e(n.error):t(n.response)}))}))}}const Be=Object.create(null);Be.open="0",Be.close="1",Be.ping="2",Be.pong="3",Be.message="4",Be.upgrade="5",Be.noop="6";const Le=Object.create(null);Object.keys(Be).forEach((t=>{Le[Be[t]]=t}));const Ie={type:"error",data:"parser error"},je="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),Ne="function"==typeof ArrayBuffer,De=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,qe=({type:t,data:e},n,r)=>je&&e instanceof Blob?n?r(e):Fe(e,r):Ne&&(e instanceof ArrayBuffer||De(e))?n?r(e):Fe(new Blob([e]),r):r(Be[t]+(e||"")),Fe=(t,e)=>{const n=new FileReader;return n.onload=function(){const t=n.result.split(",")[1];e("b"+(t||""))},n.readAsDataURL(t)};function Ue(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let Ve;const Ye="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)Ye["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(t)]=t;const ze="function"==typeof ArrayBuffer,Xe=(t,e)=>{if("string"!=typeof t)return{type:"message",data:We(t,e)};const n=t.charAt(0);return"b"===n?{type:"message",data:$e(t.substring(1),e)}:Le[n]?t.length>1?{type:Le[n],data:t.substring(1)}:{type:Le[n]}:Ie},$e=(t,e)=>{if(ze){const n=(t=>{let e,n,r,i,s,o=.75*t.length,a=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const h=new ArrayBuffer(o),u=new Uint8Array(h);for(e=0;e<a;e+=4)n=Ye[t.charCodeAt(e)],r=Ye[t.charCodeAt(e+1)],i=Ye[t.charCodeAt(e+2)],s=Ye[t.charCodeAt(e+3)],u[c++]=n<<2|r>>4,u[c++]=(15&r)<<4|i>>2,u[c++]=(3&i)<<6|63&s;return h})(t);return We(n,e)}return{base64:!0,data:t}},We=(t,e)=>"blob"===e?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,Ge=String.fromCharCode(30);let He;function Je(t){return t.reduce(((t,e)=>t+e.length),0)}function Ke(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let r=0;for(let i=0;i<e;i++)n[i]=t[0][r++],r===t[0].length&&(t.shift(),r=0);return t.length&&r<t[0].length&&(t[0]=t[0].slice(r)),n}function Qe(t){if(t)return function(t){for(var e in Qe.prototype)t[e]=Qe.prototype[e];return t}(t)}Qe.prototype.on=Qe.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},Qe.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},Qe.prototype.off=Qe.prototype.removeListener=Qe.prototype.removeAllListeners=Qe.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i=0;i<r.length;i++)if((n=r[i])===e||n.fn===e){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+t],this},Qe.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(n){r=0;for(var i=(n=n.slice(0)).length;r<i;++r)n[r].apply(this,e)}return this},Qe.prototype.emitReserved=Qe.prototype.emit,Qe.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},Qe.prototype.hasListeners=function(t){return!!this.listeners(t).length};const Ze="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),tn="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function en(t,...e){return e.reduce(((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e)),{})}const nn=tn.setTimeout,rn=tn.clearTimeout;function sn(t,e){e.useNativeTimers?(t.setTimeoutFn=nn.bind(tn),t.clearTimeoutFn=rn.bind(tn)):(t.setTimeoutFn=tn.setTimeout.bind(tn),t.clearTimeoutFn=tn.clearTimeout.bind(tn))}function on(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class an extends Error{constructor(t,e,n){super(t),this.description=e,this.context=n,this.type="TransportError"}}class cn extends Qe{constructor(t){super(),this.writable=!1,sn(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,e,n){return super.emitReserved("error",new an(t,e,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=Xe(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,e={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(e)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const e=function(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}(t);return e.length?"?"+e:""}}class hn extends cn{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",(function(){--t||e()}))),this.writable||(t++,this.once("drain",(function(){--t||e()})))}else e()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const n=t.split(Ge),r=[];for(let t=0;t<n.length;t++){const i=Xe(n[t],e);if(r.push(i),"error"===i.type)break}return r})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const n=t.length,r=new Array(n);let i=0;t.forEach(((t,s)=>{qe(t,!1,(t=>{r[s]=t,++i===n&&e(r.join(Ge))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",e=this.query||{};return!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=on()),this.supportsBinary||e.sid||(e.b64=1),this.createUri(t,e)}}let un=!1;try{un="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const ln=un;function pn(){}class fn extends hn{constructor(t){if(super(t),"undefined"!=typeof location){const e="https:"===location.protocol;let n=location.port;n||(n=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||n!==t.port}}doWrite(t,e){const n=this.request({method:"POST",data:t});n.on("success",e),n.on("error",((t,e)=>{this.onError("xhr post error",t,e)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,e)=>{this.onError("xhr poll error",t,e)})),this.pollXhr=t}}class dn extends Qe{constructor(t,e,n){super(),this.createRequest=t,sn(this,n),this._opts=n,this._method=n.method||"GET",this._uri=e,this._data=void 0!==n.data?n.data:null,this._create()}_create(){var t;const e=en(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");e.xdomain=!!this._opts.xd;const n=this._xhr=this.createRequest(e);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&n.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{n.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var t;3===n.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(n.getResponseHeader("set-cookie"))),4===n.readyState&&(200===n.status||1223===n.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof n.status?n.status:0)}),0))},n.send(this._data)}catch(t){return void this.setTimeoutFn((()=>{this._onError(t)}),0)}"undefined"!=typeof document&&(this._index=dn.requestsCount++,dn.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(void 0!==this._xhr&&null!==this._xhr){if(this._xhr.onreadystatechange=pn,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete dn.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}function gn(){for(let t in dn.requests)dn.requests.hasOwnProperty(t)&&dn.requests[t].abort()}dn.requestsCount=0,dn.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",gn):"function"==typeof addEventListener&&addEventListener("onpagehide"in tn?"pagehide":"unload",gn,!1));const yn=function(){const t=mn({xdomain:!1});return t&&null!==t.responseType}();function mn(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||ln))return new XMLHttpRequest}catch(t){}if(!e)try{return new(tn[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const bn="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class vn extends cn{get name(){return"websocket"}doOpen(){const t=this.uri(),e=this.opts.protocols,n=bn?{}:en(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,e,n)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],r=e===t.length-1;qe(n,this.supportsBinary,(t=>{try{this.doWrite(n,t)}catch(t){}r&&Ze((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=on()),this.supportsBinary||(e.b64=1),this.createUri(t,e)}}const wn=tn.WebSocket||tn.MozWebSocket,xn={websocket:class extends vn{createSocket(t,e,n){return bn?new wn(t,e,n):e?new wn(t,e):new wn(t)}doWrite(t,e){this.ws.send(e)}},webtransport:class extends cn{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this._transport.ready.then((()=>{this._transport.createBidirectionalStream().then((t=>{const e=function(t,e){He||(He=new TextDecoder);const n=[];let r=0,i=-1,s=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(0===r){if(Je(n)<1)break;const t=Ke(n,1);s=!(128&~t[0]),i=127&t[0],r=i<126?3:126===i?1:2}else if(1===r){if(Je(n)<2)break;const t=Ke(n,2);i=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),r=3}else if(2===r){if(Je(n)<8)break;const t=Ke(n,8),e=new DataView(t.buffer,t.byteOffset,t.length),s=e.getUint32(0);if(s>Math.pow(2,21)-1){a.enqueue(Ie);break}i=s*Math.pow(2,32)+e.getUint32(4),r=3}else{if(Je(n)<i)break;const t=Ke(n,i);a.enqueue(Xe(s?t:He.decode(t),e)),r=0}if(0===i||i>t){a.enqueue(Ie);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=t.readable.pipeThrough(e).getReader(),r=new TransformStream({transform(t,e){!function(t,e){je&&t.data instanceof Blob?t.data.arrayBuffer().then(Ue).then(e):Ne&&(t.data instanceof ArrayBuffer||De(t.data))?e(Ue(t.data)):qe(t,!1,(t=>{Ve||(Ve=new TextEncoder),e(Ve.encode(t))}))}(t,(n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const t=new DataView(i.buffer);t.setUint8(0,126),t.setUint16(1,r)}else{i=new Uint8Array(9);const t=new DataView(i.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(r))}t.data&&"string"!=typeof t.data&&(i[0]|=128),e.enqueue(i),e.enqueue(n)}))}});r.readable.pipeTo(t.writable),this._writer=r.writable.getWriter();const i=()=>{n.read().then((({done:t,value:e})=>{t||(this.onPacket(e),i())})).catch((t=>{}))};i();const s={type:"open"};this.query.sid&&(s.data=`{"sid":"${this.query.sid}"}`),this._writer.write(s).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],r=e===t.length-1;this._writer.write(n).then((()=>{r&&Ze((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends fn{constructor(t){super(t);const e=t&&t.forceBase64;this.supportsBinary=yn&&!e}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new dn(mn,this.uri(),t)}}},Sn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,_n=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function En(t){if(t.length>8e3)throw"URI too long";const e=t,n=t.indexOf("["),r=t.indexOf("]");-1!=n&&-1!=r&&(t=t.substring(0,n)+t.substring(n,r).replace(/:/g,";")+t.substring(r,t.length));let i=Sn.exec(t||""),s={},o=14;for(;o--;)s[_n[o]]=i[o]||"";return-1!=n&&-1!=r&&(s.source=e,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=function(t,e){const n=e.replace(/\/{2,9}/g,"/").split("/");return"/"!=e.slice(0,1)&&0!==e.length||n.splice(0,1),"/"==e.slice(-1)&&n.splice(n.length-1,1),n}(0,s.path),s.queryKey=function(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,e,r){e&&(n[e]=r)})),n}(0,s.query),s}const kn="function"==typeof addEventListener&&"function"==typeof removeEventListener,Pn=[];kn&&addEventListener("offline",(()=>{Pn.forEach((t=>t()))}),!1);class Rn extends Qe{constructor(t,e){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(e=t,t=null),t){const n=En(t);e.hostname=n.host,e.secure="https"===n.protocol||"wss"===n.protocol,e.port=n.port,n.query&&(e.query=n.query)}else e.host&&(e.hostname=En(e.host).host);sn(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},e.transports.forEach((t=>{const e=t.prototype.name;this.transports.push(e),this._transportsByName[e]=t})),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},n=t.split("&");for(let t=0,r=n.length;t<r;t++){let r=n[t].split("=");e[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return e}(this.opts.query)),kn&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},Pn.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const n=Object.assign({},this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](n)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const t=this.opts.rememberUpgrade&&Rn.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const e=this.createTransport(t);e.open(),this.setTransport(e)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",(t=>this._onClose("transport close",t)))}onOpen(){this.readyState="open",Rn.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const e=new Error("server error");e.code=t.data,this._onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let n=0;n<this.writeBuffer.length;n++){const r=this.writeBuffer[n].data;if(r&&(t+="string"==typeof(e=r)?function(t){let e=0,n=0;for(let r=0,i=t.length;r<i;r++)e=t.charCodeAt(r),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(r++,n+=4);return n}(e):Math.ceil(1.33*(e.byteLength||e.size))),n>0&&t>this._maxPayload)return this.writeBuffer.slice(0,n);t+=2}var e;return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,Ze((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),t}write(t,e,n){return this._sendPacket("message",t,e,n),this}send(t,e,n){return this._sendPacket("message",t,e,n),this}_sendPacket(t,e,n,r){if("function"==typeof e&&(r=e,e=void 0),"function"==typeof n&&(r=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const i={type:t,data:e,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),r&&this.once("flush",r),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},n=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?n():t()})):this.upgrading?n():t()),this}_onError(t){if(Rn.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),kn&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=Pn.indexOf(this._offlineEventListener);-1!==t&&Pn.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this._prevBufferLen=0}}}Rn.protocol=4;class Mn extends Rn{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let e=this.createTransport(t),n=!1;Rn.priorWebsocketSuccess=!1;const r=()=>{n||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(t=>{if(!n)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;Rn.priorWebsocketSuccess="websocket"===e.name,this.transport.pause((()=>{n||"closed"!==this.readyState&&(h(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}})))};function i(){n||(n=!0,h(),e.close(),e=null)}const s=t=>{const n=new Error("probe error: "+t);n.transport=e.name,i(),this.emitReserved("upgradeError",n)};function o(){s("transport closed")}function a(){s("socket closed")}function c(t){e&&t.name!==e.name&&i()}const h=()=>{e.removeListener("open",r),e.removeListener("error",s),e.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};e.once("open",r),e.once("error",s),e.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn((()=>{n||e.open()}),200):e.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const e=[];for(let n=0;n<t.length;n++)~this.transports.indexOf(t[n])&&e.push(t[n]);return e}}class Tn extends Mn{constructor(t,e={}){const n="object"==typeof t?t:e;(!n.transports||n.transports&&"string"==typeof n.transports[0])&&(n.transports=(n.transports||["polling","websocket","webtransport"]).map((t=>xn[t])).filter((t=>!!t))),super(t,n)}}const On="function"==typeof ArrayBuffer,An=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer,Cn=Object.prototype.toString,Bn="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Cn.call(Blob),Ln="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===Cn.call(File);function In(t){return On&&(t instanceof ArrayBuffer||An(t))||Bn&&t instanceof Blob||Ln&&t instanceof File}function jn(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,n=t.length;e<n;e++)if(jn(t[e]))return!0;return!1}if(In(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return jn(t.toJSON(),!0);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&jn(t[e]))return!0;return!1}function Nn(t){const e=[],n=t.data,r=t;return r.data=Dn(n,e),r.attachments=e.length,{packet:r,buffers:e}}function Dn(t,e){if(!t)return t;if(In(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}if(Array.isArray(t)){const n=new Array(t.length);for(let r=0;r<t.length;r++)n[r]=Dn(t[r],e);return n}if("object"==typeof t&&!(t instanceof Date)){const n={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=Dn(t[r],e));return n}return t}function qn(t,e){return t.data=Fn(t.data,e),delete t.attachments,t}function Fn(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=Fn(t[n],e);else if("object"==typeof t)for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=Fn(t[n],e));return t}const Un=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Vn=5;var Yn;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(Yn||(Yn={}));class zn{constructor(t){this.replacer=t}encode(t){return t.type!==Yn.EVENT&&t.type!==Yn.ACK||!jn(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Yn.EVENT?Yn.BINARY_EVENT:Yn.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let e=""+t.type;return t.type!==Yn.BINARY_EVENT&&t.type!==Yn.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=Nn(t),n=this.encodeAsString(e.packet),r=e.buffers;return r.unshift(n),r}}function Xn(t){return"[object Object]"===Object.prototype.toString.call(t)}class $n extends Qe{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t);const n=e.type===Yn.BINARY_EVENT;n||e.type===Yn.BINARY_ACK?(e.type=n?Yn.EVENT:Yn.ACK,this.reconstructor=new Wn(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!In(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const n={type:Number(t.charAt(0))};if(void 0===Yn[n.type])throw new Error("unknown packet type "+n.type);if(n.type===Yn.BINARY_EVENT||n.type===Yn.BINARY_ACK){const r=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const i=t.substring(r,e);if(i!=Number(i)||"-"!==t.charAt(e))throw new Error("Illegal attachments");n.attachments=Number(i)}if("/"===t.charAt(e+1)){const r=e+1;for(;++e&&","!==t.charAt(e)&&e!==t.length;);n.nsp=t.substring(r,e)}else n.nsp="/";const r=t.charAt(e+1);if(""!==r&&Number(r)==r){const r=e+1;for(;++e;){const n=t.charAt(e);if(null==n||Number(n)!=n){--e;break}if(e===t.length)break}n.id=Number(t.substring(r,e+1))}if(t.charAt(++e)){const r=this.tryParse(t.substr(e));if(!$n.isPayloadValid(n.type,r))throw new Error("invalid payload");n.data=r}return n}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(t){return!1}}static isPayloadValid(t,e){switch(t){case Yn.CONNECT:return Xn(e);case Yn.DISCONNECT:return void 0===e;case Yn.CONNECT_ERROR:return"string"==typeof e||Xn(e);case Yn.EVENT:case Yn.BINARY_EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===Un.indexOf(e[0]));case Yn.ACK:case Yn.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Wn{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=qn(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}function Gn(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const Hn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Jn extends Qe{constructor(t,e,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[Gn(t,"open",this.onopen.bind(this)),Gn(t,"packet",this.onpacket.bind(this)),Gn(t,"error",this.onerror.bind(this)),Gn(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){var n,r,i;if(Hn.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(e.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(e),this;const s={type:Yn.EVENT,data:e,options:{}};if(s.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),s.id=t}const o=null===(r=null===(n=this.io.engine)||void 0===n?void 0:n.transport)||void 0===r?void 0:r.writable,a=this.connected&&!(null===(i=this.io.engine)||void 0===i?void 0:i._hasPingExpired());return this.flags.volatile&&!o||(a?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(t,e){var n;const r=null!==(n=this.flags.timeout)&&void 0!==n?n:this._opts.ackTimeout;if(void 0===r)return void(this.acks[t]=e);const i=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))}),r),s=(...t)=>{this.io.clearTimeoutFn(i),e.apply(this,t)};s.withError=!0,this.acks[t]=s}emitWithAck(t,...e){return new Promise(((n,r)=>{const i=(t,e)=>t?r(t):n(e);i.withError=!0,e.push(i),this.emit(t,...e)}))}_addToQueue(t){let e;"function"==typeof t[t.length-1]&&(e=t.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push(((t,...r)=>{if(n===this._queue[0])return null!==t?n.tryCount>this._opts.retries&&(this._queue.shift(),e&&e(t)):(this._queue.shift(),e&&e(null,...r)),n.pending=!1,this._drainQueue()})),this._queue.push(n),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const e=this._queue[0];e.pending&&!t||(e.pending=!0,e.tryCount++,this.flags=e.flags,this.emit.apply(this,e.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Yn.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach((t=>{if(!this.sendBuffer.some((e=>String(e.id)===t))){const e=this.acks[t];delete this.acks[t],e.withError&&e.call(this,new Error("socket has been disconnected"))}}))}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Yn.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Yn.EVENT:case Yn.BINARY_EVENT:this.onevent(t);break;case Yn.ACK:case Yn.BINARY_ACK:this.onack(t);break;case Yn.DISCONNECT:this.ondisconnect();break;case Yn.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const e=this;let n=!1;return function(...r){n||(n=!0,e.packet({type:Yn.ACK,id:t,data:r}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(delete this.acks[t.id],e.withError&&t.data.unshift(null),e.apply(this,t.data))}onconnect(t,e){this.id=t,this.recovered=e&&this._pid===e,this._pid=e,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Yn.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const n of e)n.apply(this,t.data)}}}function Kn(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Kn.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=1&Math.floor(10*e)?t+n:t-n}return 0|Math.min(t,this.max)},Kn.prototype.reset=function(){this.attempts=0},Kn.prototype.setMin=function(t){this.ms=t},Kn.prototype.setMax=function(t){this.max=t},Kn.prototype.setJitter=function(t){this.jitter=t};class Qn extends Qe{constructor(t,e){var n;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(e=t,t=void 0),(e=e||{}).path=e.path||"/socket.io",this.opts=e,sn(this,e),this.reconnection(!1!==e.reconnection),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=e.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new Kn({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this._readyState="closed",this.uri=t;const r=e.parser||i;this.encoder=new r.Encoder,this.decoder=new r.Decoder,this._autoConnect=!1!==e.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new Tn(this.uri,this.opts);const e=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const r=Gn(e,"open",(function(){n.onopen(),t&&t()})),i=e=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",e),t?t(e):this.maybeReconnectOnOpen()},s=Gn(e,"error",i);if(!1!==this._timeout){const t=this._timeout,n=this.setTimeoutFn((()=>{r(),i(new Error("timeout")),e.close()}),t);this.opts.autoUnref&&n.unref(),this.subs.push((()=>{this.clearTimeoutFn(n)}))}return this.subs.push(r),this.subs.push(s),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Gn(t,"ping",this.onping.bind(this)),Gn(t,"data",this.ondata.bind(this)),Gn(t,"error",this.onerror.bind(this)),Gn(t,"close",this.onclose.bind(this)),Gn(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){Ze((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let n=this.nsps[t];return n?this._autoConnect&&!n.active&&n.connect():(n=new Jn(this,t,e),this.nsps[t]=n),n}_destroy(t){const e=Object.keys(this.nsps);for(const t of e)if(this.nsps[t].active)return;this._close()}_packet(t){const e=this.encoder.encode(t);for(let n=0;n<e.length;n++)this.engine.write(e[n],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,e){var n;this.cleanup(),null===(n=this.engine)||void 0===n||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()})))}),e);this.opts.autoUnref&&n.unref(),this.subs.push((()=>{this.clearTimeoutFn(n)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const Zn={};function tr(t,e){"object"==typeof t&&(e=t,t=void 0);const n=function(t,e="",n){let r=t;n=n||"undefined"!=typeof location&&location,null==t&&(t=n.protocol+"//"+n.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?n.protocol+t:n.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==n?n.protocol+"//"+t:"https://"+t),r=En(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const i=-1!==r.host.indexOf(":")?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+i+":"+r.port+e,r.href=r.protocol+"://"+i+(n&&n.port===r.port?"":":"+r.port),r}(t,(e=e||{}).path||"/socket.io"),r=n.source,i=n.id,s=n.path,o=Zn[i]&&s in Zn[i].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new Qn(r,e):(Zn[i]||(Zn[i]=new Qn(r,e)),a=Zn[i]),n.query&&!e.query&&(e.query=n.queryKey),a.socket(n.path,e)}Object.assign(tr,{Manager:Qn,Socket:Jn,io:tr,connect:tr});class er{socket;token;endpoint;socketList=new Map;constructor(t,e){this.endpoint=t.replace("https://","wss://").replace("http://","ws://"),this.token=e,this.socket=this.getSocket("default").socket,this.socket.connect()}close(){this.socket.emit("end"),this.socket.removeAllListeners(),this.socket.disconnect()}getSocket(t,e){return this.createManager(e)}createManager(t){const e=new Qn(this.endpoint,{reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:1e3,reconnectionDelayMax:5e3,randomizationFactor:.5,timeout:2e4,autoConnect:!0,transports:["websocket","polling"],rejectUnauthorized:!1,secure:!0,forceNew:t}),n=e.socket("/proxy",{auth:{token:`Bearer ${this.token}`}});return{manager:e,socket:n}}}class nr{api;socketService;config;logger;token;deviceManager;coreManager;constructor(t){this.config=t,this.logger=t.logger??{...console,attention:console.warn,success:console.log},this.api=new s(t.endpoint)}async connect(){return this.deviceManager&&this.coreManager||(this.cleanUpClient(),await this.login(),this.token=this.token??this.config.token,this.socketService=new er(this.config.endpoint,this.token),this.coreManager=new Ae(this.socketService,this.logger),this.deviceManager=new Ce(this.socketService,this.logger),this.checkSession()),{coreManager:this.coreManager,deviceManager:this.deviceManager}}async disconnect(){this.socketService?.close(),this.cleanUpClient(),this.config.username&&this.config.password&&await this.api.post("/auth/logout",void 0,{headers:{Authorization:`Bearer ${this.token}`}})}async updateCredentials(t){this.config={...this.config,...t},this.socketService&&await this.disconnect(),await this.connect()}async login(){if(this.config.username&&this.config.password)try{const t=await this.api.post("/auth/login",{username:this.config.username,password:this.config.password}),e=await t.json();this.token=e.access_token}catch(t){throw 401===t.response?.status?new Error("Invalid credentials"):new Error(`Failed to get token: ${t.message}`)}else if(this.config.token&&!this.config.skipCheck)try{await this.api.get("/auth/check",{headers:{Authorization:`Bearer ${this.config.token}`}})}catch(t){throw new Error(`Invalid token: ${t.message}`)}this.token=this.token??this.config.token}getDeviceManager(){return this.deviceManager}checkSession(){this.socketService?.socket.removeListener("invalidToken"),this.socketService?.socket.on("invalidToken",(async t=>{t===this.token&&await this.disconnect()}))}cleanUpClient(){this.deviceManager=void 0}}var rr=r.j;export{rr as CameraUiClient};
|
|
2
|
+
var t={855:t=>{const e="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,n=()=>e.now(),r=t=>t===1/0||(t=>t&&t===Math.floor(t)&&t>0&&isFinite(t))(t);class i{constructor({max:t=1/0,ttl:e,updateAgeOnGet:n=!1,checkAgeOnGet:i=!1,noUpdateTTL:s=!1,dispose:o,noDisposeOnSet:a=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,void 0!==e&&!r(e))throw new TypeError("ttl must be positive integer or Infinity if set");if(!r(t))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=e,this.max=t,this.updateAgeOnGet=!!n,this.checkAgeOnGet=!!i,this.noUpdateTTL=!!s,this.noDisposeOnSet=!!a,void 0!==o){if("function"!=typeof o)throw new TypeError("dispose must be function if set");this.dispose=o}this.timer=void 0,this.timerExpiration=void 0}setTimer(t,e){if(this.timerExpiration<t)return;this.timer&&clearTimeout(this.timer);const r=setTimeout((()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(const t in this.expirations){this.setTimer(t,t-n());break}}),e);r.unref&&r.unref(),this.timerExpiration=t,this.timer=r}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return process.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){const t=this.dispose!==i.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(const[e,n]of t)this.dispose(n,e,"delete")}setTTL(t,e=this.ttl){const r=this.expirationMap.get(t);if(void 0!==r){const e=this.expirations[r];!e||e.length<=1?delete this.expirations[r]:this.expirations[r]=e.filter((e=>e!==t))}if(e!==1/0){const r=Math.floor(n()+e);this.expirationMap.set(t,r),this.expirations[r]||(this.expirations[r]=[],this.setTimer(r,e)),this.expirations[r].push(t)}else this.expirationMap.set(t,1/0)}set(t,e,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:s=this.noDisposeOnSet}={}){if(!r(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(t)){i||this.setTTL(t,n);const r=this.data.get(t);r!==e&&(this.data.set(t,e),s||this.dispose(r,t,"set"))}else this.setTTL(t,n),this.data.set(t,e);for(;this.size>this.max;)this.purgeToCapacity();return this}has(t){return this.data.has(t)}getRemainingTTL(t){const e=this.expirationMap.get(t);return e===1/0?e:void 0!==e?Math.max(0,Math.ceil(e-n())):0}get(t,{updateAgeOnGet:e=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:r=this.checkAgeOnGet}={}){const i=this.data.get(t);if(!r||0!==this.getRemainingTTL(t))return e&&this.setTTL(t,n),i;this.delete(t)}dispose(t,e){}delete(t){const e=this.expirationMap.get(t);if(void 0!==e){const n=this.data.get(t);this.data.delete(t),this.expirationMap.delete(t);const r=this.expirations[e];return r&&(r.length<=1?delete this.expirations[e]:this.expirations[e]=r.filter((e=>e!==t))),this.dispose(n,t,"delete"),0===this.size&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(const t in this.expirations){const e=this.expirations[t];if(!(this.size-e.length>=this.max)){const t=this.size-this.max,n=[];for(const r of e.splice(0,t))n.push([r,this.data.get(r)]),this.data.delete(r),this.expirationMap.delete(r);for(const[t,e]of n)this.dispose(e,t,"evict");return}{delete this.expirations[t];const n=[];for(const t of e)n.push([t,this.data.get(t)]),this.data.delete(t),this.expirationMap.delete(t);for(const[t,e]of n)this.dispose(e,t,"evict")}}}get size(){return this.data.size}purgeStale(){const t=Math.ceil(n());for(const e in this.expirations){if("Infinity"===e||e>t)return;const n=[...this.expirations[e]||[]],r=[];delete this.expirations[e];for(const t of n)r.push([t,this.data.get(t)]),this.data.delete(t),this.expirationMap.delete(t);for(const[t,e]of r)this.dispose(e,t,"stale")}0===this.size&&this.cancelTimer()}*entries(){for(const t in this.expirations)for(const e of this.expirations[t])yield[e,this.data.get(e)]}*keys(){for(const t in this.expirations)for(const e of this.expirations[t])yield e}*values(){for(const t in this.expirations)for(const e of this.expirations[t])yield this.data.get(e)}[Symbol.iterator](){return this.entries()}}t.exports=i},73:function(t){t.exports=function(){function t(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}var e=function(t,e){this.next=null,this.key=t,this.data=e,this.left=null,this.right=null};function n(t,e){return t>e?1:t<e?-1:0}function r(t,n,r){for(var i=new e(null,null),s=i,o=i;;){var a=r(t,n.key);if(a<0){if(null===n.left)break;if(r(t,n.left.key)<0){var c=n.left;if(n.left=c.right,c.right=n,null===(n=c).left)break}o.left=n,o=n,n=n.left}else{if(!(a>0))break;if(null===n.right)break;if(r(t,n.right.key)>0&&(c=n.right,n.right=c.left,c.left=n,null===(n=c).right))break;s.right=n,s=n,n=n.right}}return s.right=n.left,o.left=n.right,n.left=i.right,n.right=i.left,n}function i(t,n,i,s){var o=new e(t,n);if(null===i)return o.left=o.right=null,o;var a=s(t,(i=r(t,i,s)).key);return a<0?(o.left=i.left,o.right=i,i.left=null):a>=0&&(o.right=i.right,o.left=i,i.right=null),o}function s(t,e,n){var i=null,s=null;if(e){var o=n((e=r(t,e,n)).key,t);0===o?(i=e.left,s=e.right):o<0?(s=e.right,e.right=null,i=e):(i=e.left,e.left=null,s=e)}return{left:i,right:s}}function o(t,e,n,r,i){if(t){r(e+(n?"└── ":"├── ")+i(t)+"\n");var s=e+(n?" ":"│ ");t.left&&o(t.left,s,!1,r,i),t.right&&o(t.right,s,!0,r,i)}}var a=function(){function a(t){void 0===t&&(t=n),this._root=null,this._size=0,this._comparator=t}return a.prototype.insert=function(t,e){return this._size++,this._root=i(t,e,this._root,this._comparator)},a.prototype.add=function(t,n){var i=new e(t,n);null===this._root&&(i.left=i.right=null,this._size++,this._root=i);var s=this._comparator,o=r(t,this._root,s),a=s(t,o.key);return 0===a?this._root=o:(a<0?(i.left=o.left,i.right=o,o.left=null):a>0&&(i.right=o.right,i.left=o,o.right=null),this._size++,this._root=i),this._root},a.prototype.remove=function(t){this._root=this._remove(t,this._root,this._comparator)},a.prototype._remove=function(t,e,n){var i;return null===e?null:0===n(t,(e=r(t,e,n)).key)?(null===e.left?i=e.right:(i=r(t,e.left,n)).right=e.right,this._size--,i):e},a.prototype.pop=function(){var t=this._root;if(t){for(;t.left;)t=t.left;return this._root=r(t.key,this._root,this._comparator),this._root=this._remove(t.key,this._root,this._comparator),{key:t.key,data:t.data}}return null},a.prototype.findStatic=function(t){for(var e=this._root,n=this._comparator;e;){var r=n(t,e.key);if(0===r)return e;e=r<0?e.left:e.right}return null},a.prototype.find=function(t){return this._root&&(this._root=r(t,this._root,this._comparator),0!==this._comparator(t,this._root.key))?null:this._root},a.prototype.contains=function(t){for(var e=this._root,n=this._comparator;e;){var r=n(t,e.key);if(0===r)return!0;e=r<0?e.left:e.right}return!1},a.prototype.forEach=function(t,e){for(var n=this._root,r=[],i=!1;!i;)null!==n?(r.push(n),n=n.left):0!==r.length?(n=r.pop(),t.call(e,n),n=n.right):i=!0;return this},a.prototype.range=function(t,e,n,r){for(var i=[],s=this._comparator,o=this._root;0!==i.length||o;)if(o)i.push(o),o=o.left;else{if(s((o=i.pop()).key,e)>0)break;if(s(o.key,t)>=0&&n.call(r,o))return this;o=o.right}return this},a.prototype.keys=function(){var t=[];return this.forEach((function(e){var n=e.key;return t.push(n)})),t},a.prototype.values=function(){var t=[];return this.forEach((function(e){var n=e.data;return t.push(n)})),t},a.prototype.min=function(){return this._root?this.minNode(this._root).key:null},a.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},a.prototype.minNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.left;)t=t.left;return t},a.prototype.maxNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.right;)t=t.right;return t},a.prototype.at=function(t){for(var e=this._root,n=!1,r=0,i=[];!n;)if(e)i.push(e),e=e.left;else if(i.length>0){if(e=i.pop(),r===t)return e;r++,e=e.right}else n=!0;return null},a.prototype.next=function(t){var e=this._root,n=null;if(t.right){for(n=t.right;n.left;)n=n.left;return n}for(var r=this._comparator;e;){var i=r(t.key,e.key);if(0===i)break;i<0?(n=e,e=e.left):e=e.right}return n},a.prototype.prev=function(t){var e=this._root,n=null;if(null!==t.left){for(n=t.left;n.right;)n=n.right;return n}for(var r=this._comparator;e;){var i=r(t.key,e.key);if(0===i)break;i<0?e=e.left:(n=e,e=e.right)}return n},a.prototype.clear=function(){return this._root=null,this._size=0,this},a.prototype.toList=function(){return function(t){for(var n=t,r=[],i=!1,s=new e(null,null),o=s;!i;)n?(r.push(n),n=n.left):r.length>0?n=(n=o=o.next=r.pop()).right:i=!0;return o.next=null,s.next}(this._root)},a.prototype.load=function(t,n,r){void 0===n&&(n=[]),void 0===r&&(r=!1);var i=t.length,s=this._comparator;if(r&&u(t,n,0,i-1,s),null===this._root)this._root=c(t,n,0,i),this._size=i;else{var o=function(t,n,r){for(var i=new e(null,null),s=i,o=t,a=n;null!==o&&null!==a;)r(o.key,a.key)<0?(s.next=o,o=o.next):(s.next=a,a=a.next),s=s.next;return null!==o?s.next=o:null!==a&&(s.next=a),i.next}(this.toList(),function(t,n){for(var r=new e(null,null),i=r,s=0;s<t.length;s++)i=i.next=new e(t[s],n[s]);return i.next=null,r.next}(t,n),s);i=this._size+i,this._root=h({head:o},0,i)}return this},a.prototype.isEmpty=function(){return null===this._root},Object.defineProperty(a.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),a.prototype.toString=function(t){void 0===t&&(t=function(t){return String(t.key)});var e=[];return o(this._root,"",!0,(function(t){return e.push(t)}),t),e.join("")},a.prototype.update=function(t,e,n){var o=this._comparator,a=s(t,this._root,o),c=a.left,h=a.right;o(t,e)<0?h=i(e,n,h,o):c=i(e,n,c,o),this._root=function(t,e,n){return null===e?t:(null===t||((e=r(t.key,e,n)).left=t),e)}(c,h,o)},a.prototype.split=function(t){return s(t,this._root,this._comparator)},a.prototype[Symbol.iterator]=function(){var e,n,r;return t(this,(function(t){switch(t.label){case 0:e=this._root,n=[],r=!1,t.label=1;case 1:return r?[3,6]:null===e?[3,2]:(n.push(e),e=e.left,[3,5]);case 2:return 0===n.length?[3,4]:[4,e=n.pop()];case 3:return t.sent(),e=e.right,[3,5];case 4:r=!0,t.label=5;case 5:return[3,1];case 6:return[2]}}))},a}();function c(t,n,r,i){var s=i-r;if(s>0){var o=r+Math.floor(s/2),a=t[o],h=n[o],u=new e(a,h);return u.left=c(t,n,r,o),u.right=c(t,n,o+1,i),u}return null}function h(t,e,n){var r=n-e;if(r>0){var i=e+Math.floor(r/2),s=h(t,e,i),o=t.head;return o.left=s,t.head=t.head.next,o.right=h(t,i+1,n),o}return null}function u(t,e,n,r,i){if(!(n>=r)){for(var s=t[n+r>>1],o=n-1,a=r+1;;){do{o++}while(i(t[o],s)<0);do{a--}while(i(t[a],s)>0);if(o>=a)break;var c=t[o];t[o]=t[a],t[a]=c,c=e[o],e[o]=e[a],e[a]=c}u(t,e,n,a,i),u(t,e,a+1,r,i)}}const l=(t,e)=>t.ll.x<=e.x&&e.x<=t.ur.x&&t.ll.y<=e.y&&e.y<=t.ur.y,p=(t,e)=>{if(e.ur.x<t.ll.x||t.ur.x<e.ll.x||e.ur.y<t.ll.y||t.ur.y<e.ll.y)return null;const n=t.ll.x<e.ll.x?e.ll.x:t.ll.x,r=t.ur.x<e.ur.x?t.ur.x:e.ur.x;return{ll:{x:n,y:t.ll.y<e.ll.y?e.ll.y:t.ll.y},ur:{x:r,y:t.ur.y<e.ur.y?t.ur.y:e.ur.y}}};let f=Number.EPSILON;void 0===f&&(f=Math.pow(2,-52));const d=f*f,g=(t,e)=>{if(-f<t&&t<f&&-f<e&&e<f)return 0;const n=t-e;return n*n<d*t*e?0:t<e?-1:1};class y{constructor(){this.tree=new a,this.round(0)}round(t){const e=this.tree.add(t),n=this.tree.prev(e);if(null!==n&&0===g(e.key,n.key))return this.tree.remove(t),n.key;const r=this.tree.next(e);return null!==r&&0===g(e.key,r.key)?(this.tree.remove(t),r.key):t}}const m=new class{constructor(){this.reset()}reset(){this.xRounder=new y,this.yRounder=new y}round(t,e){return{x:this.xRounder.round(t),y:this.yRounder.round(e)}}},b=11102230246251565e-32,v=134217729,w=(3+8*b)*b;function x(t,e,n,r,i){let s,o,a,c,h=e[0],u=r[0],l=0,p=0;u>h==u>-h?(s=h,h=e[++l]):(s=u,u=r[++p]);let f=0;if(l<t&&p<n)for(u>h==u>-h?(o=h+s,a=s-(o-h),h=e[++l]):(o=u+s,a=s-(o-u),u=r[++p]),s=o,0!==a&&(i[f++]=a);l<t&&p<n;)u>h==u>-h?(o=s+h,c=o-s,a=s-(o-c)+(h-c),h=e[++l]):(o=s+u,c=o-s,a=s-(o-c)+(u-c),u=r[++p]),s=o,0!==a&&(i[f++]=a);for(;l<t;)o=s+h,c=o-s,a=s-(o-c)+(h-c),h=e[++l],s=o,0!==a&&(i[f++]=a);for(;p<n;)o=s+u,c=o-s,a=s-(o-c)+(u-c),u=r[++p],s=o,0!==a&&(i[f++]=a);return 0===s&&0!==f||(i[f++]=s),f}function S(t){return new Float64Array(t)}const _=22204460492503146e-32,E=11093356479670487e-47,k=S(4),P=S(8),R=S(12),M=S(16),T=S(4);function O(t,e,n,r,i,s){const o=(e-s)*(n-i),a=(t-i)*(r-s),c=o-a,h=Math.abs(o+a);return Math.abs(c)>=33306690738754716e-32*h?c:-function(t,e,n,r,i,s,o){let a,c,h,u,l,p,f,d,g,y,m,b,S,O,A,C,B,L;const I=t-i,j=n-i,N=e-s,D=r-s;O=I*D,p=v*I,f=p-(p-I),d=I-f,p=v*D,g=p-(p-D),y=D-g,A=d*y-(O-f*g-d*g-f*y),C=N*j,p=v*N,f=p-(p-N),d=N-f,p=v*j,g=p-(p-j),y=j-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,k[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,k[1]=S-(m+l)+(l-C),L=b+m,l=L-b,k[2]=b-(L-l)+(m-l),k[3]=L;let q=function(t,e){let n=e[0];for(let r=1;r<t;r++)n+=e[r];return n}(4,k),F=_*o;if(q>=F||-q>=F)return q;if(l=t-I,a=t-(I+l)+(l-i),l=n-j,h=n-(j+l)+(l-i),l=e-N,c=e-(N+l)+(l-s),l=r-D,u=r-(D+l)+(l-s),0===a&&0===c&&0===h&&0===u)return q;if(F=E*o+w*Math.abs(q),q+=I*u+D*a-(N*h+j*c),q>=F||-q>=F)return q;O=a*D,p=v*a,f=p-(p-a),d=a-f,p=v*D,g=p-(p-D),y=D-g,A=d*y-(O-f*g-d*g-f*y),C=c*j,p=v*c,f=p-(p-c),d=c-f,p=v*j,g=p-(p-j),y=j-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,T[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,T[1]=S-(m+l)+(l-C),L=b+m,l=L-b,T[2]=b-(L-l)+(m-l),T[3]=L;const U=x(4,k,4,T,P);O=I*u,p=v*I,f=p-(p-I),d=I-f,p=v*u,g=p-(p-u),y=u-g,A=d*y-(O-f*g-d*g-f*y),C=N*h,p=v*N,f=p-(p-N),d=N-f,p=v*h,g=p-(p-h),y=h-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,T[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,T[1]=S-(m+l)+(l-C),L=b+m,l=L-b,T[2]=b-(L-l)+(m-l),T[3]=L;const V=x(U,P,4,T,R);O=a*u,p=v*a,f=p-(p-a),d=a-f,p=v*u,g=p-(p-u),y=u-g,A=d*y-(O-f*g-d*g-f*y),C=c*h,p=v*c,f=p-(p-c),d=c-f,p=v*h,g=p-(p-h),y=h-g,B=d*y-(C-f*g-d*g-f*y),m=A-B,l=A-m,T[0]=A-(m+l)+(l-B),b=O+m,l=b-O,S=O-(b-l)+(m-l),m=S-C,l=S-m,T[1]=S-(m+l)+(l-C),L=b+m,l=L-b,T[2]=b-(L-l)+(m-l),T[3]=L;const Y=x(V,R,4,T,M);return M[Y-1]}(t,e,n,r,i,s,h)}const A=(t,e)=>t.x*e.y-t.y*e.x,C=(t,e)=>t.x*e.x+t.y*e.y,B=(t,e,n)=>{const r=O(t.x,t.y,e.x,e.y,n.x,n.y);return r>0?-1:r<0?1:0},L=t=>Math.sqrt(C(t,t)),I=(t,e,n)=>{const r={x:e.x-t.x,y:e.y-t.y},i={x:n.x-t.x,y:n.y-t.y};return A(i,r)/L(i)/L(r)},j=(t,e,n)=>{const r={x:e.x-t.x,y:e.y-t.y},i={x:n.x-t.x,y:n.y-t.y};return C(i,r)/L(i)/L(r)},N=(t,e,n)=>0===e.y?null:{x:t.x+e.x/e.y*(n-t.y),y:n},D=(t,e,n)=>0===e.x?null:{x:n,y:t.y+e.y/e.x*(n-t.x)};class q{static compare(t,e){const n=q.comparePoints(t.point,e.point);return 0!==n?n:(t.point!==e.point&&t.link(e),t.isLeft!==e.isLeft?t.isLeft?1:-1:U.compare(t.segment,e.segment))}static comparePoints(t,e){return t.x<e.x?-1:t.x>e.x?1:t.y<e.y?-1:t.y>e.y?1:0}constructor(t,e){void 0===t.events?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=e}link(t){if(t.point===this.point)throw new Error("Tried to link already linked events");const e=t.point.events;for(let t=0,n=e.length;t<n;t++){const n=e[t];this.point.events.push(n),n.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let e=0;e<t;e++){const n=this.point.events[e];if(void 0===n.segment.consumedBy)for(let r=e+1;r<t;r++){const t=this.point.events[r];void 0===t.consumedBy&&n.otherSE.point.events===t.otherSE.point.events&&n.segment.consume(t.segment)}}}getAvailableLinkedEvents(){const t=[];for(let e=0,n=this.point.events.length;e<n;e++){const n=this.point.events[e];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&t.push(n)}return t}getLeftmostComparator(t){const e=new Map,n=n=>{const r=n.otherSE;e.set(n,{sine:I(this.point,t.point,r.point),cosine:j(this.point,t.point,r.point)})};return(t,r)=>{e.has(t)||n(t),e.has(r)||n(r);const{sine:i,cosine:s}=e.get(t),{sine:o,cosine:a}=e.get(r);return i>=0&&o>=0?s<a?1:s>a?-1:0:i<0&&o<0?s<a?-1:s>a?1:0:o<i?-1:o>i?1:0}}}let F=0;class U{static compare(t,e){const n=t.leftSE.point.x,r=e.leftSE.point.x,i=t.rightSE.point.x,s=e.rightSE.point.x;if(s<n)return 1;if(i<r)return-1;const o=t.leftSE.point.y,a=e.leftSE.point.y,c=t.rightSE.point.y,h=e.rightSE.point.y;if(n<r){if(a<o&&a<c)return 1;if(a>o&&a>c)return-1;const n=t.comparePoint(e.leftSE.point);if(n<0)return 1;if(n>0)return-1;const r=e.comparePoint(t.rightSE.point);return 0!==r?r:-1}if(n>r){if(o<a&&o<h)return-1;if(o>a&&o>h)return 1;const n=e.comparePoint(t.leftSE.point);if(0!==n)return n;const r=t.comparePoint(e.rightSE.point);return r<0?1:r>0?-1:1}if(o<a)return-1;if(o>a)return 1;if(i<s){const n=e.comparePoint(t.rightSE.point);if(0!==n)return n}if(i>s){const n=t.comparePoint(e.rightSE.point);if(n<0)return 1;if(n>0)return-1}if(i!==s){const t=c-o,e=i-n,u=h-a,l=s-r;if(t>e&&u<l)return 1;if(t<e&&u>l)return-1}return i>s?1:i<s||c<h?-1:c>h?1:t.id<e.id?-1:t.id>e.id?1:0}constructor(t,e,n,r){this.id=++F,this.leftSE=t,t.segment=this,t.otherSE=e,this.rightSE=e,e.segment=this,e.otherSE=t,this.rings=n,this.windings=r}static fromRing(t,e,n){let r,i,s;const o=q.comparePoints(t,e);if(o<0)r=t,i=e,s=1;else{if(!(o>0))throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);r=e,i=t,s=-1}const a=new q(r,!0),c=new q(i,!1);return new U(a,c,[n],[s])}replaceRightSE(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const t=this.leftSE.point.y,e=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t<e?t:e},ur:{x:this.rightSE.point.x,y:t>e?t:e}}}vector(){return{x:this.rightSE.point.x-this.leftSE.point.x,y:this.rightSE.point.y-this.leftSE.point.y}}isAnEndpoint(t){return t.x===this.leftSE.point.x&&t.y===this.leftSE.point.y||t.x===this.rightSE.point.x&&t.y===this.rightSE.point.y}comparePoint(t){if(this.isAnEndpoint(t))return 0;const e=this.leftSE.point,n=this.rightSE.point,r=this.vector();if(e.x===n.x)return t.x===e.x?0:t.x<e.x?1:-1;const i=(t.y-e.y)/r.y,s=e.x+i*r.x;if(t.x===s)return 0;const o=(t.x-e.x)/r.x,a=e.y+o*r.y;return t.y===a?0:t.y<a?-1:1}getIntersection(t){const e=this.bbox(),n=t.bbox(),r=p(e,n);if(null===r)return null;const i=this.leftSE.point,s=this.rightSE.point,o=t.leftSE.point,a=t.rightSE.point,c=l(e,o)&&0===this.comparePoint(o),h=l(n,i)&&0===t.comparePoint(i),u=l(e,a)&&0===this.comparePoint(a),f=l(n,s)&&0===t.comparePoint(s);if(h&&c)return f&&!u?s:!f&&u?a:null;if(h)return u&&i.x===a.x&&i.y===a.y?null:i;if(c)return f&&s.x===o.x&&s.y===o.y?null:o;if(f&&u)return null;if(f)return s;if(u)return a;const d=((t,e,n,r)=>{if(0===e.x)return D(n,r,t.x);if(0===r.x)return D(t,e,n.x);if(0===e.y)return N(n,r,t.y);if(0===r.y)return N(t,e,n.y);const i=A(e,r);if(0==i)return null;const s={x:n.x-t.x,y:n.y-t.y},o=A(s,e)/i,a=A(s,r)/i;return{x:(t.x+a*e.x+(n.x+o*r.x))/2,y:(t.y+a*e.y+(n.y+o*r.y))/2}})(i,this.vector(),o,t.vector());return null===d?null:l(r,d)?m.round(d.x,d.y):null}split(t){const e=[],n=void 0!==t.events,r=new q(t,!0),i=new q(t,!1),s=this.rightSE;this.replaceRightSE(i),e.push(i),e.push(r);const o=new U(r,s,this.rings.slice(),this.windings.slice());return q.comparePoints(o.leftSE.point,o.rightSE.point)>0&&o.swapEvents(),q.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),i.checkForConsuming()),e}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let t=0,e=this.windings.length;t<e;t++)this.windings[t]*=-1}consume(t){let e=this,n=t;for(;e.consumedBy;)e=e.consumedBy;for(;n.consumedBy;)n=n.consumedBy;const r=U.compare(e,n);if(0!==r){if(r>0){const t=e;e=n,n=t}if(e.prev===n){const t=e;e=n,n=t}for(let t=0,r=n.rings.length;t<r;t++){const r=n.rings[t],i=n.windings[t],s=e.rings.indexOf(r);-1===s?(e.rings.push(r),e.windings.push(i)):e.windings[s]+=i}n.rings=null,n.windings=null,n.consumedBy=e,n.leftSE.consumedBy=e.leftSE,n.rightSE.consumedBy=e.rightSE}}prevInResult(){return void 0!==this._prevInResult||(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null),this._prevInResult}beforeState(){if(void 0!==this._beforeState)return this._beforeState;if(this.prev){const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}afterState(){if(void 0!==this._afterState)return this._afterState;const t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};const e=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let t=0,r=this.rings.length;t<r;t++){const r=this.rings[t],i=this.windings[t],s=e.indexOf(r);-1===s?(e.push(r),n.push(i)):n[s]+=i}const i=[],s=[];for(let t=0,r=e.length;t<r;t++){if(0===n[t])continue;const r=e[t],o=r.poly;if(-1===s.indexOf(o))if(r.isExterior)i.push(o);else{-1===s.indexOf(o)&&s.push(o);const t=i.indexOf(r.poly);-1!==t&&i.splice(t,1)}}for(let t=0,e=i.length;t<e;t++){const e=i[t].multiPoly;-1===r.indexOf(e)&&r.push(e)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;const t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(K.type){case"union":{const n=0===t.length,r=0===e.length;this._isInResult=n!==r;break}case"intersection":{let n,r;t.length<e.length?(n=t.length,r=e.length):(n=e.length,r=t.length),this._isInResult=r===K.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(t.length-e.length);this._isInResult=n%2==1;break}case"difference":{const n=t=>1===t.length&&t[0].isSubject;this._isInResult=n(t)!==n(e);break}default:throw new Error(`Unrecognized operation type found ${K.type}`)}return this._isInResult}}class V{constructor(t,e,n){if(!Array.isArray(t)||0===t.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=e,this.isExterior=n,this.segments=[],"number"!=typeof t[0][0]||"number"!=typeof t[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const r=m.round(t[0][0],t[0][1]);this.bbox={ll:{x:r.x,y:r.y},ur:{x:r.x,y:r.y}};let i=r;for(let e=1,n=t.length;e<n;e++){if("number"!=typeof t[e][0]||"number"!=typeof t[e][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");let n=m.round(t[e][0],t[e][1]);n.x===i.x&&n.y===i.y||(this.segments.push(U.fromRing(i,n,this)),n.x<this.bbox.ll.x&&(this.bbox.ll.x=n.x),n.y<this.bbox.ll.y&&(this.bbox.ll.y=n.y),n.x>this.bbox.ur.x&&(this.bbox.ur.x=n.x),n.y>this.bbox.ur.y&&(this.bbox.ur.y=n.y),i=n)}r.x===i.x&&r.y===i.y||this.segments.push(U.fromRing(i,r,this))}getSweepEvents(){const t=[];for(let e=0,n=this.segments.length;e<n;e++){const n=this.segments[e];t.push(n.leftSE),t.push(n.rightSE)}return t}}class Y{constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new V(t[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let e=1,n=t.length;e<n;e++){const n=new V(t[e],this,!1);n.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=n.bbox.ur.y),this.interiorRings.push(n)}this.multiPoly=e}getSweepEvents(){const t=this.exteriorRing.getSweepEvents();for(let e=0,n=this.interiorRings.length;e<n;e++){const n=this.interiorRings[e].getSweepEvents();for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t}}class z{constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof t[0][0][0]&&(t=[t])}catch(t){}this.polys=[],this.bbox={ll:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY},ur:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY}};for(let e=0,n=t.length;e<n;e++){const n=new Y(t[e],this);n.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=n.bbox.ur.y),this.polys.push(n)}this.isSubject=e}getSweepEvents(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const n=this.polys[e].getSweepEvents();for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t}}class X{static factory(t){const e=[];for(let n=0,r=t.length;n<r;n++){const r=t[n];if(!r.isInResult()||r.ringOut)continue;let i=null,s=r.leftSE,o=r.rightSE;const a=[s],c=s.point,h=[];for(;i=s,s=o,a.push(s),s.point!==c;)for(;;){const t=s.getAvailableLinkedEvents();if(0===t.length){const t=a[0].point,e=a[a.length-1].point;throw new Error(`Unable to complete output ring starting at [${t.x}, ${t.y}]. Last matching segment found ends at [${e.x}, ${e.y}].`)}if(1===t.length){o=t[0].otherSE;break}let n=null;for(let t=0,e=h.length;t<e;t++)if(h[t].point===s.point){n=t;break}if(null!==n){const t=h.splice(n)[0],r=a.splice(t.index);r.unshift(r[0].otherSE),e.push(new X(r.reverse()));continue}h.push({index:a.length,point:s.point});const r=s.getLeftmostComparator(i);o=t.sort(r)[0].otherSE;break}e.push(new X(a))}return e}constructor(t){this.events=t;for(let e=0,n=t.length;e<n;e++)t[e].segment.ringOut=this;this.poly=null}getGeom(){let t=this.events[0].point;const e=[t];for(let n=1,r=this.events.length-1;n<r;n++){const r=this.events[n].point,i=this.events[n+1].point;0!==B(r,t,i)&&(e.push(r),t=r)}if(1===e.length)return null;const n=e[0],r=e[1];0===B(n,t,r)&&e.shift(),e.push(e[0]);const i=this.isExteriorRing()?1:-1,s=this.isExteriorRing()?0:e.length-1,o=this.isExteriorRing()?e.length:-1,a=[];for(let t=s;t!=o;t+=i)a.push([e[t].x,e[t].y]);return a}isExteriorRing(){if(void 0===this._isExteriorRing){const t=this.enclosingRing();this._isExteriorRing=!t||!t.isExteriorRing()}return this._isExteriorRing}enclosingRing(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let t=this.events[0];for(let e=1,n=this.events.length;e<n;e++){const n=this.events[e];q.compare(t,n)>0&&(t=n)}let e=t.segment.prevInResult(),n=e?e.prevInResult():null;for(;;){if(!e)return null;if(!n)return e.ringOut;if(n.ringOut!==e.ringOut)return n.ringOut.enclosingRing()!==e.ringOut?e.ringOut:e.ringOut.enclosingRing();e=n.prevInResult(),n=e?e.prevInResult():null}}}class ${constructor(t){this.exteriorRing=t,t.poly=this,this.interiorRings=[]}addInterior(t){this.interiorRings.push(t),t.poly=this}getGeom(){const t=[this.exteriorRing.getGeom()];if(null===t[0])return null;for(let e=0,n=this.interiorRings.length;e<n;e++){const n=this.interiorRings[e].getGeom();null!==n&&t.push(n)}return t}}class W{constructor(t){this.rings=t,this.polys=this._composePolys(t)}getGeom(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const n=this.polys[e].getGeom();null!==n&&t.push(n)}return t}_composePolys(t){const e=[];for(let n=0,r=t.length;n<r;n++){const r=t[n];if(!r.poly)if(r.isExteriorRing())e.push(new $(r));else{const t=r.enclosingRing();t.poly||e.push(new $(t)),t.poly.addInterior(r)}}return e}}class G{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:U.compare;this.queue=t,this.tree=new a(e),this.segments=[]}process(t){const e=t.segment,n=[];if(t.consumedBy)return t.isLeft?this.queue.remove(t.otherSE):this.tree.remove(e),n;const r=t.isLeft?this.tree.add(e):this.tree.find(e);if(!r)throw new Error(`Unable to find segment #${e.id} [${e.leftSE.point.x}, ${e.leftSE.point.y}] -> [${e.rightSE.point.x}, ${e.rightSE.point.y}] in SweepLine tree.`);let i,s,o=r,a=r;for(;void 0===i;)o=this.tree.prev(o),null===o?i=null:void 0===o.key.consumedBy&&(i=o.key);for(;void 0===s;)a=this.tree.next(a),null===a?s=null:void 0===a.key.consumedBy&&(s=a.key);if(t.isLeft){let r=null;if(i){const t=i.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(r=t),!i.isAnEndpoint(t))){const e=this._splitSafely(i,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}}let o=null;if(s){const t=s.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(o=t),!s.isAnEndpoint(t))){const e=this._splitSafely(s,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}}if(null!==r||null!==o){let t=null;t=null===r?o:null===o||q.comparePoints(r,o)<=0?r:o,this.queue.remove(e.rightSE),n.push(e.rightSE);const i=e.split(t);for(let t=0,e=i.length;t<e;t++)n.push(i[t])}n.length>0?(this.tree.remove(e),n.push(t)):(this.segments.push(e),e.prev=i)}else{if(i&&s){const t=i.getIntersection(s);if(null!==t){if(!i.isAnEndpoint(t)){const e=this._splitSafely(i,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}if(!s.isAnEndpoint(t)){const e=this._splitSafely(s,t);for(let t=0,r=e.length;t<r;t++)n.push(e[t])}}}this.tree.remove(e)}return n}_splitSafely(t,e){this.tree.remove(t);const n=t.rightSE;this.queue.remove(n);const r=t.split(e);return r.push(n),void 0===t.consumedBy&&this.tree.add(t),r}}const H="undefined"!=typeof process&&process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE||1e6,J="undefined"!=typeof process&&process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS||1e6;const K=new class{run(t,e,n){K.type=t,m.reset();const r=[new z(e,!0)];for(let t=0,e=n.length;t<e;t++)r.push(new z(n[t],!1));if(K.numMultiPolys=r.length,"difference"===K.type){const t=r[0];let e=1;for(;e<r.length;)null!==p(r[e].bbox,t.bbox)?e++:r.splice(e,1)}if("intersection"===K.type)for(let t=0,e=r.length;t<e;t++){const e=r[t];for(let n=t+1,i=r.length;n<i;n++)if(null===p(e.bbox,r[n].bbox))return[]}const i=new a(q.compare);for(let t=0,e=r.length;t<e;t++){const e=r[t].getSweepEvents();for(let t=0,n=e.length;t<n;t++)if(i.insert(e[t]),i.size>H)throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).")}const s=new G(i);let o=i.size,c=i.pop();for(;c;){const t=c.key;if(i.size===o){const e=t.segment;throw new Error(`Unable to pop() ${t.isLeft?"left":"right"} SweepEvent [${t.point.x}, ${t.point.y}] from segment #${e.id} [${e.leftSE.point.x}, ${e.leftSE.point.y}] -> [${e.rightSE.point.x}, ${e.rightSE.point.y}] from queue.`)}if(i.size>H)throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");if(s.segments.length>J)throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");const e=s.process(t);for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0===n.consumedBy&&i.insert(n)}o=i.size,c=i.pop()}m.reset();const h=X.factory(s.segments);return new W(h).getGeom()}};var Q={union:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("union",t,n)},intersection:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("intersection",t,n)},xor:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("xor",t,n)},difference:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return K.run("difference",t,n)}};return Q}()}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var s=e[r]={exports:{}};return t[r].call(s.exports,s,s.exports,n),s.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};n.d(r,{j:()=>nr});var i={};n.r(i),n.d(i,{Decoder:()=>$n,Encoder:()=>zn,PacketType:()=>Yn,protocol:()=>Vn});class s{baseURL;abortControllers=new Set;constructor(t){this.baseURL=`${t}/api`}async request(t,e,n,r={}){const i=new AbortController;this.abortControllers.add(i);const s=setTimeout((()=>{i.abort(),this.abortControllers.delete(i)}),15e3);try{const s=await fetch(`${this.baseURL}${e}`,{method:t,headers:{"Content-Type":"application/json",...r.headers},body:n?JSON.stringify(n):void 0,signal:i.signal,...r});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s}finally{clearTimeout(s),this.abortControllers.delete(i)}}get(t,e){return this.request("GET",t,void 0,e)}post(t,e,n){return this.request("POST",t,e,n)}}process.env.CAMERA_UI_RUNMODE,process.env.CAMERA_UI_RUNMODE,process.env.CAMERA_UI_RUNMODE;class o{subscriptions=[];additionalSubscriptions=[];addSubscriptions(...t){this.subscriptions.push(...t)}addAdditionalSubscriptions(...t){this.additionalSubscriptions.push(...t)}unsubscribe(){this.subscriptions.forEach((t=>t.unsubscribe()))}unsubscribeAdditional(){this.additionalSubscriptions.forEach((t=>t.unsubscribe()))}}function a(t,e,n=!1){if(t===e)return!0;if((void 0===t||void 0===e||null===t||null===e)&&(t||e))return!1;const r=t?.constructor.name,i=e?.constructor.name;if(r!==i)return!1;if("Array"===r&&"Array"===i){if(t.length!==e.length)return!1;if(n){const r=[...e];return t.every((t=>{const e=r.findIndex((e=>a(t,e,n)));return-1!==e&&(r.splice(e,1),!0)}))}{let r=!0;for(let i=0;i<t.length;i++)if(!a(t[i],e[i],n)){r=!1;break}return r}}if("Object"===r&&"Object"===i){let r=!0;const i=Object.keys(t),s=Object.keys(e);if(i.length!==s.length)return!1;for(let s=0;s<i.length;s++)if(t[i[s]]&&e[i[s]]){if(t[i[s]]===e[i[s]])continue;if(!t[i[s]]||"Array"!==t[i[s]].constructor.name&&"Object"!==t[i[s]].constructor.name){if(t[i[s]]!==e[i[s]]){r=!1;break}}else if(r=a(t[i[s]],e[i[s]],n),!r)break}else if(t[i[s]]&&!e[i[s]]||!t[i[s]]&&e[i[s]]){r=!1;break}return r}return t===e}function c(t){return JSON.parse(JSON.stringify(t))}var h=n(855),u=n.n(h),l=function(t,e){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},l(t,e)};function p(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}l(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function f(t,e){var n,r,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function d(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function g(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,s=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=s.next()).done;)o.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}return o}function y(t,e,n){if(n||2===arguments.length)for(var r,i=0,s=e.length;i<s;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function m(t){return this instanceof m?(this.v=t,this):new m(t)}function b(t){return"function"==typeof t}function v(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var w=v((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function x(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var S=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var t,e,n,r,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var o=d(s),a=o.next();!a.done;a=o.next())a.value.remove(this)}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}else s.remove(this);var c=this.initialTeardown;if(b(c))try{c()}catch(t){i=t instanceof w?t.errors:[t]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var u=d(h),l=u.next();!l.done;l=u.next()){var p=l.value;try{k(p)}catch(t){i=null!=i?i:[],t instanceof w?i=y(y([],g(i)),g(t.errors)):i.push(t)}}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(i)throw new w(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)k(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&x(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&x(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}(),_=S.EMPTY;function E(t){return t instanceof S||t&&"closed"in t&&b(t.remove)&&b(t.add)&&b(t.unsubscribe)}function k(t){b(t)?t():t.unsubscribe()}var P={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},R={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=R.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,y([t,e],g(n))):setTimeout.apply(void 0,y([t,e],g(n)))},clearTimeout:function(t){var e=R.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function M(t){R.setTimeout((function(){var e=P.onUnhandledError;if(!e)throw t;e(t)}))}function T(){}var O=A("C",void 0,void 0);function A(t,e,n){return{kind:t,value:e,error:n}}var C=null;function B(t){if(P.useDeprecatedSynchronousErrorHandling){var e=!C;if(e&&(C={errorThrown:!1,error:null}),t(),e){var n=C,r=n.errorThrown,i=n.error;if(C=null,r)throw i}}else t()}var L=function(t){function e(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,E(e)&&e.add(n)):n.destination=U,n}return p(e,t),e.create=function(t,e,n){return new D(t,e,n)},e.prototype.next=function(t){this.isStopped?F(function(t){return A("N",t,void 0)}(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?F(A("E",void 0,t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?F(O,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(S),I=Function.prototype.bind;function j(t,e){return I.call(t,e)}var N=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){q(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){q(t)}else q(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){q(t)}},t}(),D=function(t){function e(e,n,r){var i,s,o=t.call(this)||this;return b(e)||!e?i={next:null!=e?e:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:o&&P.useDeprecatedNextContext?((s=Object.create(e)).unsubscribe=function(){return o.unsubscribe()},i={next:e.next&&j(e.next,s),error:e.error&&j(e.error,s),complete:e.complete&&j(e.complete,s)}):i=e,o.destination=new N(i),o}return p(e,t),e}(L);function q(t){var e;P.useDeprecatedSynchronousErrorHandling?(e=t,P.useDeprecatedSynchronousErrorHandling&&C&&(C.errorThrown=!0,C.error=e)):M(t)}function F(t,e){var n=P.onStoppedNotification;n&&R.setTimeout((function(){return n(t,e)}))}var U={closed:!0,next:T,error:function(t){throw t},complete:T},V="function"==typeof Symbol&&Symbol.observable||"@@observable";function Y(t){return t}var z=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(t,e,n){var r=this,i=function(t){return t&&t instanceof L||function(t){return t&&b(t.next)&&b(t.error)&&b(t.complete)}(t)&&E(t)}(t)?t:new D(t,e,n);return B((function(){var t=r,e=t.operator,n=t.source;i.add(e?e.call(i,n):n?r._subscribe(i):r._trySubscribe(i))})),i},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var n=this;return new(e=X(e))((function(e,r){var i=new D({next:function(e){try{t(e)}catch(t){r(t),i.unsubscribe()}},error:r,complete:e});n.subscribe(i)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[V]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(0===(n=t).length?Y:1===n.length?n[0]:function(t){return n.reduce((function(t,e){return e(t)}),t)})(this);var n},t.prototype.toPromise=function(t){var e=this;return new(t=X(t))((function(t,n){var r;e.subscribe((function(t){return r=t}),(function(t){return n(t)}),(function(){return t(r)}))}))},t.create=function(e){return new t(e)},t}();function X(t){var e;return null!==(e=null!=t?t:P.Promise)&&void 0!==e?e:Promise}var $=v((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),W=function(t){function e(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return p(e,t),e.prototype.lift=function(t){var e=new G(this,this);return e.operator=t,e},e.prototype._throwIfClosed=function(){if(this.closed)throw new $},e.prototype.next=function(t){var e=this;B((function(){var n,r;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var i=d(e.currentObservers),s=i.next();!s.done;s=i.next())s.value.next(t)}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}}))},e.prototype.error=function(t){var e=this;B((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var n=e.observers;n.length;)n.shift().error(t)}}))},e.prototype.complete=function(){var t=this;B((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var e=this,n=this,r=n.hasError,i=n.isStopped,s=n.observers;return r||i?_:(this.currentObservers=null,s.push(t),new S((function(){e.currentObservers=null,x(s,t)})))},e.prototype._checkFinalizedStatuses=function(t){var e=this,n=e.hasError,r=e.thrownError,i=e.isStopped;n?t.error(r):i&&t.complete()},e.prototype.asObservable=function(){var t=new z;return t.source=this,t},e.create=function(t,e){return new G(t,e)},e}(z),G=function(t){function e(e,n){var r=t.call(this)||this;return r.destination=e,r.source=n,r}return p(e,t),e.prototype.next=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===n||n.call(e,t)},e.prototype.error=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===n||n.call(e,t)},e.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},e.prototype._subscribe=function(t){var e,n;return null!==(n=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==n?n:_},e}(W),H=function(t){function e(e){var n=t.call(this)||this;return n._value=e,n}return p(e,t),Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(e){var n=t.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},e.prototype.getValue=function(){var t=this,e=t.hasError,n=t.thrownError,r=t._value;if(e)throw n;return this._throwIfClosed(),r},e.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},e}(W),J={now:function(){return(J.delegate||Date).now()},delegate:void 0},K=function(t){function e(e,n,r){void 0===e&&(e=1/0),void 0===n&&(n=1/0),void 0===r&&(r=J);var i=t.call(this)||this;return i._bufferSize=e,i._windowTime=n,i._timestampProvider=r,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=n===1/0,i._bufferSize=Math.max(1,e),i._windowTime=Math.max(1,n),i}return p(e,t),e.prototype.next=function(e){var n=this,r=n.isStopped,i=n._buffer,s=n._infiniteTimeWindow,o=n._timestampProvider,a=n._windowTime;r||(i.push(e),!s&&i.push(o.now()+a)),this._trimBuffer(),t.prototype.next.call(this,e)},e.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var e=this._innerSubscribe(t),n=this._infiniteTimeWindow,r=this._buffer.slice(),i=0;i<r.length&&!t.closed;i+=n?1:2)t.next(r[i]);return this._checkFinalizedStatuses(t),e},e.prototype._trimBuffer=function(){var t=this,e=t._bufferSize,n=t._timestampProvider,r=t._buffer,i=t._infiniteTimeWindow,s=(i?1:2)*e;if(e<1/0&&s<r.length&&r.splice(0,r.length-s),!i){for(var o=n.now(),a=0,c=1;c<r.length&&r[c]<=o;c+=2)a=c;a&&r.splice(0,a+1)}},e}(W);function Q(t){return function(e){if(function(t){return b(null==t?void 0:t.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function Z(t,e,n,r,i){return new tt(t,e,n,r,i)}var tt=function(t){function e(e,n,r,i,s,o){var a=t.call(this,e)||this;return a.onFinalize=s,a.shouldUnsubscribe=o,a._next=n?function(t){try{n(t)}catch(t){e.error(t)}}:t.prototype._next,a._error=i?function(t){try{i(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,a._complete=r?function(){try{r()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,a}return p(e,t),e.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},e}(L);function et(){return Q((function(t,e){var n,r=!1;t.subscribe(Z(e,(function(t){var i=n;n=t,r&&e.next([i,t]),r=!0})))}))}function nt(t,e){return Q((function(n,r){var i=0;n.subscribe(Z(r,(function(n){return t.call(e,n,i++)&&r.next(n)})))}))}function rt(t,e){return Q((function(n,r){var i=0;n.subscribe(Z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var it=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t},st="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ot(t){if(t instanceof z)return t;if(null!=t){if(function(t){return b(t[V])}(t))return i=t,new z((function(t){var e=i[V]();if(b(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(it(t))return r=t,new z((function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()}));if(function(t){return b(null==t?void 0:t.then)}(t))return n=t,new z((function(t){n.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,M)}));if(function(t){return Symbol.asyncIterator&&b(null==t?void 0:t[Symbol.asyncIterator])}(t))return at(t);if(function(t){return b(null==t?void 0:t[st])}(t))return e=t,new z((function(t){var n,r;try{for(var i=d(e),s=i.next();!s.done;s=i.next()){var o=s.value;if(t.next(o),t.closed)return}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}t.complete()}));if(function(t){return b(null==t?void 0:t.getReader)}(t))return at(function(t){return function(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(t,e||[]),s=[];return r=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),o("next"),o("throw"),o("return",(function(t){return function(e){return Promise.resolve(e).then(t,h)}})),r[Symbol.asyncIterator]=function(){return this},r;function o(t,e){i[t]&&(r[t]=function(e){return new Promise((function(n,r){s.push([t,e,n,r])>1||a(t,e)}))},e&&(r[t]=e(r[t])))}function a(t,e){try{(n=i[t](e)).value instanceof m?Promise.resolve(n.value.v).then(c,h):u(s[0][2],n)}catch(t){u(s[0][3],t)}var n}function c(t){a("next",t)}function h(t){a("throw",t)}function u(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}(this,arguments,(function(){var e,n,r;return f(this,(function(i){switch(i.label){case 0:e=t.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,m(e.read())];case 3:return n=i.sent(),r=n.value,n.done?[4,m(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,m(r)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}(t))}var e,n,r,i;throw function(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}(t)}function at(t){return new z((function(e){(function(t,e){var n,r,i,s,o,a,c,h;return o=this,a=void 0,h=function(){var o,a;return f(this,(function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=d(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,i){!function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)}(r,i,(e=t[n](e)).done,e.value)}))}}}(t),c.label=1;case 1:return[4,n.next()];case 2:if((r=c.sent()).done)return[3,4];if(o=r.value,e.next(o),e.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),i={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(s=n.return)?[4,s.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))},new((c=void 0)||(c=Promise))((function(t,e){function n(t){try{i(h.next(t))}catch(t){e(t)}}function r(t){try{i(h.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):function(t){return t instanceof c?t:new c((function(e){e(t)}))}(e.value).then(n,r)}i((h=h.apply(o,a||[])).next())}))})(t,e).catch((function(t){return e.error(t)}))}))}function ct(t){void 0===t&&(t={});var e=t.connector,n=void 0===e?function(){return new W}:e,r=t.resetOnError,i=void 0===r||r,s=t.resetOnComplete,o=void 0===s||s,a=t.resetOnRefCountZero,c=void 0===a||a;return function(t){var e,r,s,a=0,h=!1,u=!1,l=function(){null==r||r.unsubscribe(),r=void 0},p=function(){l(),e=s=void 0,h=u=!1},f=function(){var t=e;p(),null==t||t.unsubscribe()};return Q((function(t,d){a++,u||h||l();var g=s=null!=s?s:n();d.add((function(){0!=--a||u||h||(r=ht(f,c))})),g.subscribe(d),!e&&a>0&&(e=new D({next:function(t){return g.next(t)},error:function(t){u=!0,l(),r=ht(p,i,t),g.error(t)},complete:function(){h=!0,l(),r=ht(p,o),g.complete()}}),ot(t).subscribe(e))}))(t)}}function ht(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!0!==e){if(!1!==e){var i=new D({next:function(){i.unsubscribe(),t()}});return ot(e.apply(void 0,y([],g(n)))).subscribe(i)}}else t()}function ut(t,e,n){return void 0===n&&(n=1/0),b(e)?ut((function(n,r){return rt((function(t,i){return e(n,t,r,i)}))(ot(t(n,r)))}),n):("number"==typeof e&&(n=e),Q((function(e,r){return function(t,e,n,r,i,s,o,a){var c=[],h=0,u=0,l=!1,p=function(){!l||c.length||h||e.complete()},f=function(t){return h<r?d(t):c.push(t)},d=function(t){h++;var i=!1;ot(n(t,u++)).subscribe(Z(e,(function(t){e.next(t)}),(function(){i=!0}),void 0,(function(){if(i)try{h--;for(var t=function(){var t=c.shift();d(t)};c.length&&h<r;)t();p()}catch(t){e.error(t)}})))};return t.subscribe(Z(e,f,(function(){l=!0,p()}))),function(){}}(e,r,t,n)})))}function lt(t,e){return t===e}function pt(t,e,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=e||{},r.geometry=t,r}function ft(t,e,n={}){for(const e of t){if(e.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(e[e.length-1].length!==e[0].length)throw new Error("First and last Position are not equivalent.");for(let t=0;t<e[e.length-1].length;t++)if(e[e.length-1][t]!==e[0][t])throw new Error("First and last Position are not equivalent.")}return pt({type:"Polygon",coordinates:t},e,n)}function dt(t,e={}){const n={type:"FeatureCollection"};return e.id&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.features=t,n}function gt(t){return!isNaN(t)&&null!==t&&!Array.isArray(t)}function yt(t,e,n){if(null!==t)for(var r,i,s,o,a,c,h,u,l=0,p=0,f=t.type,d="FeatureCollection"===f,g="Feature"===f,y=d?t.features.length:1,m=0;m<y;m++){a=(u=!!(h=d?t.features[m].geometry:g?t.geometry:t)&&"GeometryCollection"===h.type)?h.geometries.length:1;for(var b=0;b<a;b++){var v=0,w=0;if(null!==(o=u?h.geometries[b]:h)){c=o.coordinates;var x=o.type;switch(l=!n||"Polygon"!==x&&"MultiPolygon"!==x?0:1,x){case null:break;case"Point":if(!1===e(c,p,m,v,w))return!1;p++,v++;break;case"LineString":case"MultiPoint":for(r=0;r<c.length;r++){if(!1===e(c[r],p,m,v,w))return!1;p++,"MultiPoint"===x&&v++}"LineString"===x&&v++;break;case"Polygon":case"MultiLineString":for(r=0;r<c.length;r++){for(i=0;i<c[r].length-l;i++){if(!1===e(c[r][i],p,m,v,w))return!1;p++}"MultiLineString"===x&&v++,"Polygon"===x&&w++}"Polygon"===x&&v++;break;case"MultiPolygon":for(r=0;r<c.length;r++){for(w=0,i=0;i<c[r].length;i++){for(s=0;s<c[r][i].length-l;s++){if(!1===e(c[r][i][s],p,m,v,w))return!1;p++}w++}v++}break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(!1===yt(o.geometries[r],e,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function mt(t,e){var n,r,i,s,o,a,c,h,u,l,p=0,f="FeatureCollection"===t.type,d="Feature"===t.type,g=f?t.features.length:1;for(n=0;n<g;n++){for(a=f?t.features[n].geometry:d?t.geometry:t,h=f?t.features[n].properties:d?t.properties:{},u=f?t.features[n].bbox:d?t.bbox:void 0,l=f?t.features[n].id:d?t.id:void 0,o=(c=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,i=0;i<o;i++)if(null!==(s=c?a.geometries[i]:a))switch(s.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===e(s,p,h,u,l))return!1;break;case"GeometryCollection":for(r=0;r<s.geometries.length;r++)if(!1===e(s.geometries[r],p,h,u,l))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===e(null,p,h,u,l))return!1;p++}}function bt(t,e){mt(t,(function(t,n,r,i,s){var o,a=null===t?null:t.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return!1!==e(pt(t,r,{bbox:i,id:s}),n,0)&&void 0}switch(a){case"MultiPoint":o="Point";break;case"MultiLineString":o="LineString";break;case"MultiPolygon":o="Polygon"}for(var c=0;c<t.coordinates.length;c++){var h=t.coordinates[c];if(!1===e(pt({type:o,coordinates:h},r),n,c))return!1}}))}function vt(t,e={}){if(null!=t.bbox&&!0!==e.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return yt(t,(t=>{n[0]>t[0]&&(n[0]=t[0]),n[1]>t[1]&&(n[1]=t[1]),n[2]<t[0]&&(n[2]=t[0]),n[3]<t[1]&&(n[3]=t[1])})),n}function wt(t,e={}){const n=Number(t[0]),r=Number(t[1]),i=Number(t[2]),s=Number(t[3]);if(6===t.length)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const o=[n,r];return ft([[o,[i,r],[i,s],[n,s],o]],e.properties,{bbox:t,id:e.id})}Math.PI;var xt=n(73);function St(t,e={}){const n=[];if(mt(t,(t=>{n.push(t.coordinates)})),n.length<2)throw new Error("Must have at least 2 geometries");const r=xt.union(n[0],...n.slice(1));return 0===r.length?null:1===r.length?ft(r[0],e.properties):function(t,e,n={}){return pt({type:"MultiPolygon",coordinates:t},e,n)}(r,e.properties)}function _t(t,e,n=0,r=t.length-1,i=kt){for(;r>n;){if(r-n>600){const s=r-n+1,o=e-n+1,a=Math.log(s),c=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*c*(s-c)/s)*(o-s/2<0?-1:1);_t(t,e,Math.max(n,Math.floor(e-o*c/s+h)),Math.min(r,Math.floor(e+(s-o)*c/s+h)),i)}const s=t[e];let o=n,a=r;for(Et(t,n,e),i(t[r],s)>0&&Et(t,n,r);o<a;){for(Et(t,o,a),o++,a--;i(t[o],s)<0;)o++;for(;i(t[a],s)>0;)a--}0===i(t[n],s)?Et(t,n,a):(a++,Et(t,a,r)),a<=e&&(n=a+1),e<=a&&(r=a-1)}}function Et(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function kt(t,e){return t<e?-1:t>e?1:0}class Pt{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const n=[];if(!Nt(t,e))return n;const r=this.toBBox,i=[];for(;e;){for(let s=0;s<e.children.length;s++){const o=e.children[s],a=e.leaf?r(o):o;Nt(t,a)&&(e.leaf?n.push(o):jt(t,a)?this._all(o,n):i.push(o))}e=i.pop()}return n}collides(t){let e=this.data;if(!Nt(t,e))return!1;const n=[];for(;e;){for(let r=0;r<e.children.length;r++){const i=e.children[r],s=e.leaf?this.toBBox(i):i;if(Nt(t,s)){if(e.leaf||jt(t,s))return!0;n.push(i)}}e=n.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Dt([]),this}remove(t,e){if(!t)return this;let n=this.data;const r=this.toBBox(t),i=[],s=[];let o,a,c;for(;n||i.length;){if(n||(n=i.pop(),a=i[i.length-1],o=s.pop(),c=!0),n.leaf){const r=Rt(t,n.children,e);if(-1!==r)return n.children.splice(r,1),i.push(n),this._condense(i),this}c||n.leaf||!jt(n,r)?a?(o++,n=a.children[o],c=!1):n=null:(i.push(n),s.push(o),o=0,a=n,n=n.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,r){const i=n-e+1;let s,o=this._maxEntries;if(i<=o)return s=Dt(t.slice(e,n+1)),Mt(s,this.toBBox),s;r||(r=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/Math.pow(o,r-1))),s=Dt([]),s.leaf=!1,s.height=r;const a=Math.ceil(i/o),c=a*Math.ceil(Math.sqrt(o));qt(t,e,n,c,this.compareMinX);for(let i=e;i<=n;i+=c){const e=Math.min(i+c-1,n);qt(t,i,e,a,this.compareMinY);for(let n=i;n<=e;n+=a){const i=Math.min(n+a-1,e);s.children.push(this._build(t,n,i,r-1))}}return Mt(s,this.toBBox),s}_chooseSubtree(t,e,n,r){for(;r.push(e),!e.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let a=0;a<e.children.length;a++){const c=e.children[a],h=Bt(c),u=(i=t,s=c,(Math.max(s.maxX,i.maxX)-Math.min(s.minX,i.minX))*(Math.max(s.maxY,i.maxY)-Math.min(s.minY,i.minY))-h);u<o?(o=u,r=h<r?h:r,n=c):u===o&&h<r&&(r=h,n=c)}e=n||e.children[0]}var i,s;return e}_insert(t,e,n){const r=n?t:this.toBBox(t),i=[],s=this._chooseSubtree(r,this.data,e,i);for(s.children.push(t),Ot(s,r);e>=0&&i[e].children.length>this._maxEntries;)this._split(i,e),e--;this._adjustParentBBoxes(r,i,e)}_split(t,e){const n=t[e],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);const s=this._chooseSplitIndex(n,i,r),o=Dt(n.children.splice(s,n.children.length-s));o.height=n.height,o.leaf=n.leaf,Mt(n,this.toBBox),Mt(o,this.toBBox),e?t[e-1].children.push(o):this._splitRoot(n,o)}_splitRoot(t,e){this.data=Dt([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Mt(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let r,i=1/0,s=1/0;for(let o=e;o<=n-e;o++){const e=Tt(t,0,o,this.toBBox),a=Tt(t,o,n,this.toBBox),c=It(e,a),h=Bt(e)+Bt(a);c<i?(i=c,r=o,s=h<s?h:s):c===i&&h<s&&(s=h,r=o)}return r||n-e}_chooseSplitAxis(t,e,n){const r=t.leaf?this.compareMinX:At,i=t.leaf?this.compareMinY:Ct;this._allDistMargin(t,e,n,r)<this._allDistMargin(t,e,n,i)&&t.children.sort(r)}_allDistMargin(t,e,n,r){t.children.sort(r);const i=this.toBBox,s=Tt(t,0,e,i),o=Tt(t,n-e,n,i);let a=Lt(s)+Lt(o);for(let r=e;r<n-e;r++){const e=t.children[r];Ot(s,t.leaf?i(e):e),a+=Lt(s)}for(let r=n-e-1;r>=e;r--){const e=t.children[r];Ot(o,t.leaf?i(e):e),a+=Lt(o)}return a}_adjustParentBBoxes(t,e,n){for(let r=n;r>=0;r--)Ot(e[r],t)}_condense(t){for(let e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children,e.splice(e.indexOf(t[n]),1)):this.clear():Mt(t[n],this.toBBox)}}function Rt(t,e,n){if(!n)return e.indexOf(t);for(let r=0;r<e.length;r++)if(n(t,e[r]))return r;return-1}function Mt(t,e){Tt(t,0,t.children.length,e,t)}function Tt(t,e,n,r,i){i||(i=Dt(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=e;s<n;s++){const e=t.children[s];Ot(i,t.leaf?r(e):e)}return i}function Ot(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function At(t,e){return t.minX-e.minX}function Ct(t,e){return t.minY-e.minY}function Bt(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Lt(t){return t.maxX-t.minX+(t.maxY-t.minY)}function It(t,e){const n=Math.max(t.minX,e.minX),r=Math.max(t.minY,e.minY),i=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,i-n)*Math.max(0,s-r)}function jt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Nt(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Dt(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function qt(t,e,n,r,i){const s=[e,n];for(;s.length;){if((n=s.pop())-(e=s.pop())<=r)continue;const o=e+Math.ceil((n-e)/r/2)*r;_t(t,o,e,n,i),s.push(e,o,o,n)}}function Ft(t){return wt(t)}function Ut(t){return t[0]<t[2]&&t[1]<t[3]}function Vt(t,e){const[n,r,i,s]=t,[o,a,c,h]=e,u=Math.max(n,o),l=Math.max(r,a),p=Math.min(i,c),f=Math.min(s,h);if(p<u||f<l)return 0;const d=(p-u)*(f-l);return d/((i-n)*(s-r)+(c-o)*(h-a)-d)}function Yt(t,e=.01,n=100){if(0===t.length)return[];const r=new Pt,i=t.map((t=>({minX:t.boundingBox[0],minY:t.boundingBox[1],maxX:t.boundingBox[2],maxY:t.boundingBox[3],detection:{...t,id:t.id??Math.random().toString(36).slice(2,9)}})));r.load(i);const s=[],o=new Set;for(const t of i){if(o.has(t.detection.id))continue;const i={...t.detection};let c=i.confidence;const h=[Ft(i.boundingBox)],u=Math.max(n,10),l=r.search({minX:t.minX-u,minY:t.minY-u,maxX:t.maxX+u,maxY:t.maxY+u});for(const r of l){if(r.detection.id===i.id||o.has(r.detection.id)||r.detection.label!==i.label)continue;const s=Vt(i.boundingBox,r.detection.boundingBox),a=Math.abs(t.minX-r.minX)<=n&&Math.abs(t.minY-r.minY)<=n;if(s>e||a){const t=Ft(r.detection.boundingBox);h.push(t),o.add(r.detection.id),c=Math.max(c,r.detection.confidence)}}if(h.length>1){const t=St(dt(h));if(t){const e=(a=vt(t),[Math.max(0,Math.round(a[0])),Math.max(0,Math.round(a[1])),Math.min(1e3,Math.round(a[2])),Math.min(1e3,Math.round(a[3]))]);Ut(e)&&(i.boundingBox=e,i.confidence=c)}}Ut(i.boundingBox)&&s.push(i),o.add(i.id)}var a;return s}const zt=function(t,e){for(var n=0,r=0,i=0,s=0,o=0,a=0,c=0,h=0,u=null,l=null,p=t[0],f=t[1],d=e.length;n<d;n++){r=0;var g=e[n].length-1,y=e[n];if((u=y[0])[0]!==y[g][0]&&u[1]!==y[g][1])throw new Error("First and last coordinates in a ring must be the same");for(o=u[0]-p,a=u[1]-f;r<g;r++)if(h=(l=y[r+1])[1]-f,a<0&&h<0||a>0&&h>0)a=h,o=(u=l)[0]-p;else{if(c=l[0]-t[0],h>0&&a<=0){if((s=o*h-c*a)>0)i+=1;else if(0===s)return 0}else if(a>0&&h<=0){if((s=o*h-c*a)<0)i+=1;else if(0===s)return 0}else if(0===h&&a<0){if(0==(s=o*h-c*a))return 0}else if(0===a&&h<0){if(0==(s=o*h-c*a))return 0}else if(0===a&&0===h){if(c<=0&&o>=0)return 0;if(o<=0&&c>=0)return 0}u=l,a=h,o=c}}return i%2!=0};function Xt(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if("Feature"===t.type&&null!==t.geometry&&"Point"===t.geometry.type)return[...t.geometry.coordinates];if("Point"===t.type)return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function $t(t){return"Feature"===t.type?t.geometry:t}function Wt(t,e,n={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const r=Xt(t),i=$t(e),s=i.type,o=e.bbox;let a=i.coordinates;if(o&&!1===function(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}(r,o))return!1;"Polygon"===s&&(a=[a]);let c=!1;for(var h=0;h<a.length;++h){const t=zt(r,a[h]);if(0===t)return!n.ignoreBoundary;t&&(c=!0)}return c}function Gt(t,e,n={}){const r=Xt(t),i=function(t){if(Array.isArray(t))return t;if("Feature"===t.type){if(null!==t.geometry)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}(e);for(let t=0;t<i.length-1;t++){let e=!1;if(n.ignoreEndVertices&&(0===t&&(e="start"),t===i.length-2&&(e="end"),0===t&&t+1===i.length-1&&(e="both")),Ht(i[t],i[t+1],r,e,void 0===n.epsilon?null:n.epsilon))return!0}return!1}function Ht(t,e,n,r,i){const s=n[0],o=n[1],a=t[0],c=t[1],h=e[0],u=e[1],l=h-a,p=u-c,f=(n[0]-a)*p-(n[1]-c)*l;if(null!==i){if(Math.abs(f)>i)return!1}else if(0!==f)return!1;return r?"start"===r?Math.abs(l)>=Math.abs(p)?l>0?a<s&&s<=h:h<=s&&s<a:p>0?c<o&&o<=u:u<=o&&o<c:"end"===r?Math.abs(l)>=Math.abs(p)?l>0?a<=s&&s<h:h<s&&s<=a:p>0?c<=o&&o<u:u<o&&o<=c:"both"===r&&(Math.abs(l)>=Math.abs(p)?l>0?a<s&&s<h:h<s&&s<a:p>0?c<o&&o<u:u<o&&o<c):Math.abs(l)>=Math.abs(p)?l>0?a<=s&&s<=h:h<=s&&s<=a:p>0?c<=o&&o<=u:u<=o&&o<=c}function Jt(t,e){const n=$t(t),r=$t(e),i=n.type,s=r.type,o=n.coordinates,a=r.coordinates;switch(i){case"Point":if("Point"===s)return Zt(o,a);throw new Error("feature2 "+s+" geometry not supported");case"MultiPoint":switch(s){case"Point":return function(t,e){let n,r=!1;for(n=0;n<t.coordinates.length;n++)if(Zt(t.coordinates[n],e.coordinates)){r=!0;break}return r}(n,r);case"MultiPoint":return function(t,e){for(const n of e.coordinates){let e=!1;for(const r of t.coordinates)if(Zt(n,r)){e=!0;break}if(!e)return!1}return!0}(n,r);default:throw new Error("feature2 "+s+" geometry not supported")}case"LineString":switch(s){case"Point":return Gt(r,n,{ignoreEndVertices:!0});case"LineString":return function(t,e){let n=!1;for(const r of e.coordinates)if(Gt({type:"Point",coordinates:r},t,{ignoreEndVertices:!0})&&(n=!0),!Gt({type:"Point",coordinates:r},t,{ignoreEndVertices:!1}))return!1;return n}(n,r);case"MultiPoint":return function(t,e){let n=!1;for(const r of e.coordinates)if(Gt(r,t,{ignoreEndVertices:!0})&&(n=!0),!Gt(r,t))return!1;return!!n}(n,r);default:throw new Error("feature2 "+s+" geometry not supported")}case"Polygon":switch(s){case"Point":return Wt(r,n,{ignoreBoundary:!0});case"LineString":return function(t,e){let n=!1,r=0;if(!Qt(vt(t),vt(e)))return!1;for(;r<e.coordinates.length-1;r++)if(Wt({type:"Point",coordinates:(i=e.coordinates[r],s=e.coordinates[r+1],[(i[0]+s[0])/2,(i[1]+s[1])/2])},t,{ignoreBoundary:!0})){n=!0;break}var i,s;return n}(n,r);case"Polygon":return Kt(n,r);case"MultiPoint":return function(t,e){for(const n of e.coordinates)if(!Wt(n,t,{ignoreBoundary:!0}))return!1;return!0}(n,r);default:throw new Error("feature2 "+s+" geometry not supported")}case"MultiPolygon":if("Polygon"===s)return function(t,e){return t.coordinates.some((t=>Kt({type:"Polygon",coordinates:t},e)))}(n,r);throw new Error("feature2 "+s+" geometry not supported");default:throw new Error("feature1 "+i+" geometry not supported")}}function Kt(t,e){if("Feature"===t.type&&null===t.geometry)return!1;if("Feature"===e.type&&null===e.geometry)return!1;if(!Qt(vt(t),vt(e)))return!1;const n=$t(e).coordinates;for(const e of n)for(const n of e)if(!Wt(n,t))return!1;return!0}function Qt(t,e){return!(t[0]>e[0]||t[2]<e[2]||t[1]>e[1]||t[3]<e[3])}function Zt(t,e){return t[0]===e[0]&&t[1]===e[1]}class te{constructor(t=[],e=ee){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,r=e[t];for(;t>0;){const i=t-1>>1,s=e[i];if(n(r,s)>=0)break;e[t]=s,t=i}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,i=e[t];for(;t<r;){let r=1+(t<<1),s=e[r];const o=r+1;if(o<this.length&&n(e[o],s)<0&&(r=o,s=e[o]),n(s,i)>=0)break;e[t]=s,t=r}e[t]=i}}function ee(t,e){return t<e?-1:t>e?1:0}function ne(t,e){return t.p.x>e.p.x?1:t.p.x<e.p.x?-1:t.p.y!==e.p.y?t.p.y>e.p.y?1:-1:1}function re(t,e){return t.rightSweepEvent.p.x>e.rightSweepEvent.p.x?1:t.rightSweepEvent.p.x<e.rightSweepEvent.p.x?-1:t.rightSweepEvent.p.y!==e.rightSweepEvent.p.y?t.rightSweepEvent.p.y<e.rightSweepEvent.p.y?1:-1:1}class ie{constructor(t,e,n,r){this.p={x:t[0],y:t[1]},this.featureId=e,this.ringId=n,this.eventId=r,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(t){return this.p.x===t.p.x&&this.p.y===t.p.y}}let se=0,oe=0,ae=0;function ce(t,e){const n="Feature"===t.type?t.geometry:t;let r=n.coordinates;"Polygon"!==n.type&&"MultiLineString"!==n.type||(r=[r]),"LineString"===n.type&&(r=[[r]]);for(let t=0;t<r.length;t++)for(let n=0;n<r[t].length;n++){let i=r[t][n][0],s=null;oe+=1;for(let o=0;o<r[t][n].length-1;o++){s=r[t][n][o+1];const a=new ie(i,se,oe,ae),c=new ie(s,se,oe,ae+1);a.otherEvent=c,c.otherEvent=a,ne(a,c)>0?(c.isLeftEndpoint=!0,a.isLeftEndpoint=!1):(a.isLeftEndpoint=!0,c.isLeftEndpoint=!1),e.push(a),e.push(c),i=s,ae+=1}}se+=1}class he{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}}function ue(t,e){if(null===t||null===e)return!1;if(t.leftSweepEvent.ringId===e.leftSweepEvent.ringId&&(t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.rightSweepEvent)||t.leftSweepEvent.isSamePoint(e.leftSweepEvent)||t.leftSweepEvent.isSamePoint(e.rightSweepEvent)))return!1;const n=t.leftSweepEvent.p.x,r=t.leftSweepEvent.p.y,i=t.rightSweepEvent.p.x,s=t.rightSweepEvent.p.y,o=e.leftSweepEvent.p.x,a=e.leftSweepEvent.p.y,c=e.rightSweepEvent.p.x,h=e.rightSweepEvent.p.y,u=(h-a)*(i-n)-(c-o)*(s-r);if(0===u)return!1;const l=((c-o)*(r-a)-(h-a)*(n-o))/u,p=((i-n)*(r-a)-(s-r)*(n-o))/u;return l>=0&&l<=1&&p>=0&&p<=1&&[n+l*(i-n),r+l*(s-r)]}var le=function(t,e){const n=new te([],ne);return function(t,e){if("FeatureCollection"===t.type){const n=t.features;for(let t=0;t<n.length;t++)ce(n[t],e)}else ce(t,e)}(t,n),function(t,e){e=e||!1;const n=[],r=new te([],re);for(;t.length;){const i=t.pop();if(i.isLeftEndpoint){const t=new he(i);for(let s=0;s<r.data.length;s++){const o=r.data[s];if(e&&o.leftSweepEvent.featureId===i.featureId)continue;const a=ue(t,o);!1!==a&&n.push(a)}r.push(t)}else!1===i.isLeftEndpoint&&r.pop()}return n}(n,e)};function pe(t,e,n={}){const{removeDuplicates:r=!0,ignoreSelfIntersections:i=!1}=n;let s=[];"FeatureCollection"===t.type?s=s.concat(t.features):"Feature"===t.type?s.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||s.push(pt(t)),"FeatureCollection"===e.type?s=s.concat(e.features):"Feature"===e.type?s.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||s.push(pt(e));const o=le(dt(s),i);let a=[];if(r){const t={};o.forEach((e=>{const n=e.join(",");t[n]||(t[n]=!0,a.push(e))}))}else a=o;return dt(a.map((t=>function(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!gt(t[0])||!gt(t[1]))throw new Error("coordinates must contain numbers");return pt({type:"Point",coordinates:t},e,n)}(t))))}function fe(t,e={}){const n=$t(t);switch(e.properties||"Feature"!==t.type||(e.properties=t.properties),n.type){case"Polygon":return function(t,e={}){return de($t(t).coordinates,e.properties?e.properties:"Feature"===t.type?t.properties:{})}(n,e);case"MultiPolygon":return function(t,e={}){const n=$t(t).coordinates,r=e.properties?e.properties:"Feature"===t.type?t.properties:{},i=[];return n.forEach((t=>{i.push(de(t,r))})),dt(i)}(n,e);default:throw new Error("invalid poly")}}function de(t,e){return t.length>1?function(t,e,n={}){return pt({type:"MultiLineString",coordinates:t},e,n)}(t,e):function(t,e,n={}){if(t.length<2)throw new Error("coordinates must be an array of two or more positions");return pt({type:"LineString",coordinates:t},e,n)}(t[0],e)}function ge(t,e){for(let n=0;n<t.coordinates.length-1;n++)if(me(t.coordinates[n],t.coordinates[n+1],e.coordinates))return!0;return!1}function ye(t,e,n){for(const n of e.coordinates)if(Wt(n,t))return!0;return pe(e,fe(t),{ignoreSelfIntersections:n}).features.length>0}function me(t,e,n){const r=n[0]-t[0],i=n[1]-t[1],s=e[0]-t[0],o=e[1]-t[1];return 0==r*o-i*s&&(Math.abs(s)>=Math.abs(o)?s>0?t[0]<=n[0]&&n[0]<=e[0]:e[0]<=n[0]&&n[0]<=t[0]:o>0?t[1]<=n[1]&&n[1]<=e[1]:e[1]<=n[1]&&n[1]<=t[1])}function be(t,e,n={}){var r;const i=null!=(r=n.ignoreSelfIntersections)&&r;let s=!1;return bt(t,(t=>{bt(e,(e=>{if(!0===s)return!0;s=!function(t,e,n={}){var r;const i=null!=(r=n.ignoreSelfIntersections)&&r;let s=!0;return bt(t,(t=>{bt(e,(e=>{if(!1===s)return!1;s=function(t,e,n){switch(t.type){case"Point":switch(e.type){case"Point":return r=t.coordinates,i=e.coordinates,!(r[0]===i[0]&&r[1]===i[1]);case"LineString":return!ge(e,t);case"Polygon":return!Wt(t,e)}break;case"LineString":switch(e.type){case"Point":return!ge(t,e);case"LineString":return!function(t,e,n){return pe(t,e,{ignoreSelfIntersections:n}).features.length>0}(t,e,n);case"Polygon":return!ye(e,t,n)}break;case"Polygon":switch(e.type){case"Point":return!Wt(e,t);case"LineString":return!ye(t,e,n);case"Polygon":return!function(t,e,n){for(const n of t.coordinates[0])if(Wt(n,e))return!0;for(const n of e.coordinates[0])if(Wt(n,t))return!0;return pe(fe(t),fe(e),{ignoreSelfIntersections:n}).features.length>0}(e,t,n)}}var r,i;return!1}(t.geometry,e.geometry,i)}))})),s}(t.geometry,e.geometry,{ignoreSelfIntersections:i})}))})),s}const ve=(t,e)=>{const{origWidth:n,origHeight:r}=e,i=t.points.map((([t,e])=>[t*n/100,e*r/100]));return i.length>0&&!we(i[0],i[i.length-1])&&i.push(i[0]),{...t,points:i}},we=(t,e)=>t[0]===e[0]&&t[1]===e[1],xe=t=>{const{origWidth:e,origHeight:n,inputWidth:r,inputHeight:i}=t;let[s,o,a,c]=t.boundingBox;return s=s*e/r,o=o*n/i,a=a*e/r,c=c*n/i,s=Math.max(0,Math.min(s,e)),o=Math.max(0,Math.min(o,n)),a=Math.max(0,Math.min(a,e)),c=Math.max(0,Math.min(c,n)),{...t,boundingBox:[s,o,a,c]}},Se=(t,e,n)=>{const r=[];for(const i of t)_e(xe(i),e,n)&&e.some((t=>!t.classes.length||t.classes.includes(i.label)))&&r.push(i);return r},_e=(t,e,n)=>{if(t.confidence<n.object.confidence)return!1;if(0===e.length)return!0;const[r,i,s,o]=t.boundingBox,a=wt([r,i,s,o]);for(const n of e){const e=ve(n,t),r=ft([e.points]);if(e.classes.length>0&&!e.classes.includes(t.label))continue;const i=be(a,r),s=Jt(r,a);if(e.isPrivacyMask){if(i||s)return!1}else if("include"===e.filter){if("contain"===e.type){if(s)return!0}else if("intersect"===e.type&&(i||s))return!0}else if("exclude"===e.filter)if("contain"===e.type){if(!s)return!0}else if("intersect"===e.type&&!i&&!s)return!0}return!1};class Ee extends o{logger;snapshotCache;cameraSubject;cameraState=new H(!1);lightState=new H(this.getLightState({state:!1},!0));motionState=new H(this.getMotionState({detections:[],state:!1},!0));audioState=new H(this.getAudioState({state:!1,db:0},!0));objectState=new H(this.getObjectState({detections:[]},!0));doorbellState=new H(this.getDoorbellState({state:!1},!0));sirenState=new H(this.getSirenState({state:!1,level:0},!0));batteryState=new H(this.getBatteryState({level:100,charging:!1,lowBattery:!1},!0));onConnected=this.createStateObservable(this.cameraState);onLightSwitched=this.createStateObservable(this.lightState);onMotionDetected=this.createStateObservable(this.motionState);onAudioDetected=this.createStateObservable(this.audioState);onObjectDetected=this.createStateObservable(this.objectState);onDoorbellPressed=this.createStateObservable(this.doorbellState);onSirenDetected=this.createStateObservable(this.sirenState);onBatteryChanged=this.createStateObservable(this.batteryState);get cameraObject(){return c(this.cameraSubject.getValue())}get id(){return this.cameraSubject.getValue()._id}get nativeId(){return this.cameraSubject.getValue().nativeId}get pluginId(){return this.cameraSubject.getValue().pluginId}get connected(){return this.cameraState.getValue()}get disabled(){return this.cameraSubject.getValue().disabled}get name(){return this.cameraSubject.getValue().name}get type(){return this.cameraSubject.getValue().type}get info(){return c(this.cameraSubject.getValue().info)}get isCloud(){return this.cameraSubject.getValue().isCloud}get hasLight(){return this.cameraSubject.getValue().hasLight}get hasSiren(){return this.cameraSubject.getValue().hasSiren}get hasBinarySensor(){return this.cameraSubject.getValue().hasBinarySensor}get hasBattery(){return this.cameraSubject.getValue().hasBattery}get hasMotionDetector(){return this.cameraSubject.getValue().hasMotionDetector}get extendedMotionDetector(){return this.cameraSubject.getValue().extendedMotionDetector}get hasAudioDetector(){return this.cameraSubject.getValue().hasAudioDetector}get hasObjectDetector(){return this.cameraSubject.getValue().hasObjectDetector}get hasPtz(){return this.cameraSubject.getValue().hasPtz}get hasPrebuffer(){return this.cameraSubject.getValue().hasPrebuffer}get snapshotTTL(){return this.cameraSubject.getValue().snapshotTTL}get activityZones(){return c(this.cameraSubject.getValue().activityZones)}get activitySettings(){return c(this.cameraSubject.getValue().activitySettings)}get frameWorkerSettings(){return c(this.cameraSubject.getValue().frameWorkerSettings)}get streamSource(){return this.highResolutionSource??this.midResolutionSource??this.lowResolutionSource}get snapshotSource(){const t=this.sources.find((t=>t.roles.includes("snapshot")&&!t.internal));if(t)return{_id:t._id,name:t.name,roles:t.roles,urls:t.urls,internal:t.internal}}get highResolutionSource(){return this.sources.find((t=>t.roles.includes("high-resolution")&&!t.internal))}get midResolutionSource(){return this.sources.find((t=>t.roles.includes("mid-resolution")&&!t.internal))}get lowResolutionSource(){return this.sources.find((t=>t.roles.includes("low-resolution")&&!t.internal))}get ptz(){return this.ptzDelegate}constructor(t,e){super(),this.logger=e,this.cameraSubject=new H(t),this.updateCamera(t),this.snapshotCache=new(u())({max:100,ttl:1e3*this.snapshotTTL}),"native"===t.pluginId&&this.cameraState.next(!0)}getValue(t){switch(t){case"light":return c(this.lightState.getValue());case"motion":return c(this.motionState.getValue());case"audio":return c(this.audioState.getValue());case"object":return c(this.objectState.getValue());case"doorbell":return c(this.doorbellState.getValue());case"siren":return c(this.sirenState.getValue());case"battery":return c(this.batteryState.getValue());default:throw new Error(`Unknown state: ${t}`)}}async snapshot(t){this.snapshotCache.purgeStale();const e=this.snapshotSource??this.streamSource,n=e.urls.www.jpegSnapshot,r=this.snapshotCache.get(e._id);if(!t&&r)return r;try{if("native"!==this.cameraObject.pluginId){const t=await this.cameraDelegate.snapshot();if(t&&t.byteLength>0)return this.snapshotCache.set(e._id,t),t}const t=new AbortController,r=setTimeout((()=>t.abort()),5e3),i=await fetch(n,{signal:t.signal});if(clearTimeout(r),!i.ok)throw new Error("Status Code: "+i.status);const s=await i.arrayBuffer();return s.byteLength>0&&this.snapshotCache.set(e._id,s),s}catch{return}}onStateChange(t){return this[`${t}State`].pipe(et(),nt((([e,n])=>"boolean"==typeof e||"boolean"==typeof n?e!==n:this.stateChanged(e,n,t))),rt((([t,e])=>({oldState:t,newState:e}))),ct({connector:()=>new K(1)}))}onPropertyChange(t){return this.cameraSubject.pipe(et(),ut((([e,n])=>(Array.isArray(t)?t:[t]).map((t=>({property:t,oldData:e[t],newData:n[t]}))))),nt((({oldData:t,newData:e})=>!a(t,e,!0))),ct({connector:()=>new K(1)}))}removeAllListeners(){this.lightState.complete(),this.motionState.complete(),this.audioState.complete(),this.objectState.complete(),this.doorbellState.complete(),this.sirenState.complete(),this.batteryState.complete(),this.cameraSubject.complete(),this.cameraState.complete()}updateCamera(t){t.snapshotTTL!==this.snapshotTTL&&this.snapshotCache.clear(),this.cameraSubject.next(t)}updateCameraState(t){this.cameraState.next(t)}updateStateInternal(t,e,n,r){let i,s=!1;if(n)s=!0,i=e;else{const n=this.checkStateInternal(t,e,r);s=n.changed,i=n.event}if(s)switch(t){case"light":this.lightState.next(this.getLightState(i));break;case"motion":this.motionState.next(this.getMotionState(i));break;case"audio":this.audioState.next(this.getAudioState(i));break;case"object":this.objectState.next(this.getObjectState(i));break;case"doorbell":this.doorbellState.next(this.getDoorbellState(i));break;case"siren":this.sirenState.next(this.getSirenState(i));break;case"battery":this.batteryState.next(this.getBatteryState(i));break;default:throw new Error(`Unknown state: ${t}`)}}checkStateInternal(t,e,n){let r,i=!1;switch(t){case"audio":const s=e;r=this.getAudioState(s),i=this.stateChanged(this.getValue("audio"),r,"audio");break;case"light":const o=e;r=this.getLightState(o),i=this.stateChanged(this.getValue("light"),r,"light");break;case"motion":const a=e;void 0!==a.state&&(a.detections=[]),n||(a.detections=Yt(a.detections),a.detections=Se(a.detections,this.activityZones,this.activitySettings)),r=this.getMotionState(a),i=this.stateChanged(this.getValue("motion"),r,"motion");break;case"object":const c=e;n||(c.detections=Yt(c.detections),c.detections=Se(c.detections,this.activityZones,this.activitySettings)),r=this.getObjectState(c),i=this.stateChanged(this.getValue("object"),r,"object");break;case"doorbell":const h=e;r=this.getDoorbellState(h),i=this.stateChanged(this.getValue("doorbell"),r,"doorbell");break;case"siren":const u=e;r=this.getSirenState(u),i=this.stateChanged(this.getValue("siren"),r,"siren");break;case"battery":const l=e;r=this.getBatteryState(l),i=this.stateChanged(this.getValue("battery"),r,"battery");break;default:throw new Error(`Unknown state: ${t}`)}return{changed:i,event:r}}stateChanged(t,e,n){if(void 0===t||void 0===e||void 0===n)return!1;if("audio"==n){if(!this.hasAudioDetector)return!1;const n=t,r=e;return n.state!==r.state||n.db!==r.db}if("motion"==n){if(!this.hasMotionDetector)return!1;const n=t,r=e;return void 0!==r.state?n.state!==r.state:!a(n.detections,r.detections,!0)}if("object"==n){if(!this.hasObjectDetector)return!1;const n=e;return!a(t.detections,n.detections,!0)}if("siren"==n){if(!this.hasSiren)return!1;const n=t,r=e;return n.state!==r.state||n.level!==r.level}if("battery"==n){if(!this.hasBattery)return!1;const n=t,r=e;return n.level!==r.level||n.lowBattery!==r.lowBattery||n.charging!==r.charging}if("doorbell"==n){if(!this.hasBinarySensor)return!1;const n=e;return t.state!==n.state}if("light"==n){if(!this.hasLight)return!1;const n=e;return t.state!==n.state}return!1}getAudioState(t,e=!1){let n,r;if(!e){const t=this.getValue("audio");t.state||void 0!==t.db?n=t:(t.lastEvent?.state||void 0!==t.lastEvent?.db)&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,db:e.db??n?.db??0,lastEvent:n||(e.state?e:void 0)}}return r}getMotionState(t,e=!1){let n,r;if(!e){const t=this.getValue("motion");t.state||t.detections.length>0?n=t:(t.lastEvent?.state||t.lastEvent&&t.lastEvent.detections.length>0)&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.detections.length||e.state?e:void 0)}}return r}getObjectState(t,e=!1){let n,r;if(!e){const t=this.getValue("object");t.detections.length>0?n=t:t.lastEvent&&t.lastEvent?.detections.length>0&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.detections.length?e:void 0)}}return r}getDoorbellState(t,e=!1){let n,r;if(!e){const t=this.getValue("doorbell");t.state?n=t:t.lastEvent?.state&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.state?e:void 0)}}return r}getLightState(t,e=!1){let n,r;if(!e){const t=this.getValue("light");t.state?n=t:t.lastEvent?.state&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,lastEvent:n||(e.state?e:void 0)}}return r}getSirenState(t,e=!1){let n,r;if(!e){const t=this.getValue("siren");t.state||void 0!==t.level?n=t:(t.lastEvent?.state||void 0!==t.lastEvent?.level)&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,level:e.level??n?.level??0,lastEvent:n||(e.state?e:void 0)}}return r}getBatteryState(t,e=!1){let n,r;if(!e){const t=this.getValue("battery");void 0!==t.level||t.lowBattery||t.charging?n=t:(void 0!==t.lastEvent?.level||t.lastEvent?.lowBattery||t.lastEvent?.charging)&&(n=t.lastEvent),n&&delete n.lastEvent}if(this.isStateEvent(t))r=t;else{const e={...t,timestamp:Date.now()};r={...e,charging:t.charging??n?.charging??!1,lowBattery:t.lowBattery??n?.lowBattery??!1,lastEvent:n??e}}return r}isStateEvent(t){return"timestamp"in t}createStateObservable(t){return t.pipe((void 0===n&&(n=Y),e=null!=e?e:lt,Q((function(t,r){var i,s=!0;t.subscribe(Z(r,(function(t){var o=n(t);!s&&e(i,o)||(s=!1,i=o,r.next(t))})))}))),ct({connector:()=>new K(1)}));var e,n}}class ke{delegate;onRequest;constructor(t){this.onRequest=t}async snapshot(){return this.delegate?this.delegate.snapshot():this._onRequest("snapshot",[],5e3)}_onRequest(t,e,n){return this.onRequest("cameraDelegate",t,e,n)}}class Pe{delegate;onRequest;constructor(t){this.onRequest=t}async getPrebufferingState(t,e){return this.delegate?this.delegate.getPrebufferingState(t,e):this._onRequest("prebufferDelegate","getPrebufferingState",[t,e])}_onRequest(t,e,n,r){return this.onRequest(t,e,n,r)}}class Re{delegate;onRequest;constructor(t){this.onRequest=t}async moveAbsolute(t,e,n){return this.delegate?this.delegate.moveAbsolute(t,e,n):this._onRequest("moveAbsolute",[t,e,n])}async moveRelative(t,e,n){return this.delegate?this.delegate.moveRelative(t,e,n):this._onRequest("moveRelative",[t,e,n])}async moveContinuous(t,e,n){return this.delegate?this.delegate.moveContinuous(t,e,n):this._onRequest("moveContinuous",[t,e,n])}async stop(){return this.delegate?this.delegate.stop():this._onRequest("stop",[])}_onRequest(t,e,n){return this.onRequest("ptzDelegate",t,e,n)}}const Me=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}));class Te extends EventTarget{cameraDevice;socketService;logger;options;videoPlayer;socket;streamId;hasBackchannel=!1;hasAudio=!0;closed=!1;micTransceiver=null;pc=null;buf=new Uint8Array(2097152);mediaSource=null;sourceBuffer=null;bufLen=0;mseCodecs="";videoPlayerMp4;media=["video","audio","microphone"];codecList=[];reconnectTimeout;_finishLoading=!1;_firstFrameReceived=!1;animationFrameId;get mode(){return this.options.mode}webrtcReconnectTimeout;constructor(t,e,n,r){super(),this.options=r,this.videoPlayer=r.videoElement,this.cameraDevice=t,this.socketService=e,this.logger=n;const{socket:i}=this.socketService.getSocket(`${t.id}-go2rtcSession`,!0);this.socket=i,this.socket.connect(),this.streamId=Me(),this.createCodecsList()}connect(t){t&&(this.options.mode=t),console.log(this.cameraDevice.name,`Connecting... (${this.options.mode})`),this.socket.on("ws-open",this.onWsOpen.bind(this)),this.socket.on("ws-close",this.onWsClose.bind(this)),this.socket.on("ws-message",this.onWsMessage.bind(this)),this.socket.emit("ws-open",{id:this.streamId,cameraSource:this.options.sourceName,mode:this.options.mode})}disconnect(){console.log(this.cameraDevice.name,"Disconnecting..."),this.socket.removeListener("ws-open",this.onWsOpen.bind(this)),this.socket.removeListener("ws-close",this.onWsClose.bind(this)),this.socket.removeListener("ws-message",this.onWsMessage.bind(this)),this.socket.emit("ws-close",{id:this.streamId})}async reconnect(t){console.log(this.cameraDevice.name,"Reconnecting..."),this.dispatchEvent(new Event("reconnect")),this.close(),await new Promise((t=>setTimeout(t,100))),this.connect(t)}reset(){this._finishLoading=!1,this._firstFrameReceived=!1,this.pc?.getTransceivers().forEach((t=>t.sender?.track?.stop())),this.pc?.close(),this.pc=null,this.videoPlayerMp4?.remove(),this.videoPlayerMp4=void 0,this.videoPlayer.srcObject=null,this.videoPlayer.src="",this.videoPlayer.poster="",void 0!==this.animationFrameId&&("cancelVideoFrameCallback"in this.videoPlayer?this.videoPlayer.cancelVideoFrameCallback(this.animationFrameId):cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}close(){console.log(this.cameraDevice.name,"Closing..."),this.closed=!0,this.reset(),this.disconnect(),this.socket.emit("end"),this.socket.removeAllListeners()}onWsOpen({id:t}){if(t===this.streamId)switch(console.log(this.cameraDevice.name,"Connected"),this.options.mode){case"webrtc":case"webrtc/tcp":console.log(this.cameraDevice.name,"Requesting WebRTC session..."),this.requestWebrtc();break;case"mse":console.log(this.cameraDevice.name,"Requesting MSE session..."),this.requestMse();break;case"hls":console.log(this.cameraDevice.name,"Requesting HLS session..."),this.requestHls();break;case"mp4":console.log(this.cameraDevice.name,"Requesting MP4 session..."),this.requestMp4();break;case"mjpeg":console.log(this.cameraDevice.name,"Requesting MJPEG session..."),this.requestMjpeg();break;default:console.log(this.cameraDevice.name,"Unknown mode:",this.options.mode),this.dispatchEvent(new ErrorEvent("error",{message:"Unknown mode: "+this.options.mode}))}}onWsClose({id:t}){t===this.streamId&&(this.closed||void 0===this.options.reconnectInterval||(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=setTimeout((()=>{this.reconnect()}),this.options.reconnectInterval)))}onWsMessage({id:t,data:e}){if(t===this.streamId&&e.type){switch(e.type){case"mse":this.onMseData(e);break;case"hls":this.onHlsData(e);break;case"webrtc/candidate":case"webrtc/answer":this.onWebrtcData(e);break;case"mse-binary":this.onMseBuffer(e);break;case"mjpeg-binary":this.onMjpegBuffer(e);break;case"mp4-binary":this.onMp4Buffer(e);break;case"stream-info":this.onStreamInfo(e);break;case"error":this.dispatchEvent(new ErrorEvent("error",{error:e,message:e.value}))}!this._firstFrameReceived&&["mse-binary","mjpeg-binary","mp4-binary"].includes(e.type)&&this.onFirstFrame()}}async requestWebrtc(){this.reset(),this.pc=new RTCPeerConnection({bundlePolicy:"max-bundle",iceServers:[{urls:"stun:stun.l.google.com:19302"}],sdpSemantics:"unified-plan"}),this.pc.onicecandidate=t=>{if(console.log(this.cameraDevice.name,"onicecandidate",t.candidate),"webrtc/tcp"===this.options.mode&&"udp"===t.candidate?.protocol)return;const e=t.candidate?.toJSON().candidate??"";this.socket.emit("stream-payload",{id:this.streamId,data:{type:"webrtc/candidate",value:e}})},this.pc.onconnectionstatechange=()=>{if(console.log(this.cameraDevice.name,"onconnectionstatechange:",this.pc?.connectionState),"connected"===this.pc?.connectionState){const t=this.pc?.getTransceivers().filter((t=>"recvonly"===t.currentDirection)).map((t=>t.receiver.track));this.videoPlayer.srcObject=new MediaStream(t),this.onFinishLoading(),this.play(),this.disconnect()}else"failed"!==this.pc?.connectionState&&"disconnected"!==this.pc?.connectionState||(clearTimeout(this.webrtcReconnectTimeout),this.webrtcReconnectTimeout=setTimeout((()=>{"failed"!==this.pc?.connectionState&&"disconnected"!==this.pc?.connectionState||this.reconnect()}),1e3))},this.pc.oniceconnectionstatechange=()=>{console.log(this.cameraDevice.name,"iceconnectionstatechange",this.pc?.iceConnectionState)},this.pc.onicecandidateerror=t=>{console.log(this.cameraDevice.name,"onicecandidateerror",t)},this.pc.onsignalingstatechange=()=>{console.log(this.cameraDevice.name,"onsignalingstatechange",this.pc?.signalingState)},this.pc.onicegatheringstatechange=()=>{console.log(this.cameraDevice.name,"onicegatheringstatechange",this.pc?.iceGatheringState)},this.pc.onnegotiationneeded=t=>{console.log(this.cameraDevice.name,"onnegotiationneeded",t)},this.pc.addTransceiver("video",{direction:"recvonly"}),this.pc.addTransceiver("audio",{direction:"recvonly"}),this.micTransceiver=this.pc.addTransceiver("audio",{direction:"sendonly"});const t=await this.pc.createOffer();await this.pc.setLocalDescription(t),console.log(this.cameraDevice.name,"Offer:",t.sdp),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"webrtc/offer",value:t.sdp}})}async onWebrtcData(t){try{switch(t.type){case"webrtc/candidate":if(console.log(this.cameraDevice.name,"remote candidate:",t.value),"webrtc/tcp"===this.options.mode&&t.value.indexOf(" udp ")>0)return;await(this.pc?.addIceCandidate({candidate:t.value,sdpMid:"0"}));break;case"webrtc/answer":if(console.log(this.cameraDevice.name,"Answer:",t.value),await(this.pc?.setRemoteDescription({type:"answer",sdp:t.value})),!this._firstFrameReceived&&this.pc){const t=this.pc.getReceivers().find((t=>"video"===t.track.kind))?.track;if(t)if("requestVideoFrameCallback"in t)this.animationFrameId=t.requestVideoFrameCallback((()=>{this.onFirstFrame()}));else{const t=()=>{this.videoPlayer.readyState>=2&&this.videoPlayer.videoWidth>0?this.onFirstFrame():this.animationFrameId=requestAnimationFrame(t)};this.animationFrameId=requestAnimationFrame(t)}}break;case"error":if(console.log(this.cameraDevice.name,"WebRTC Error:",t.value),t.value.indexOf("webrtc/offer")<0)return;this.pc?.close()}}catch(t){this.dispatchEvent(new ErrorEvent("error",{error:t,message:t.message}))}}requestMse(){if(this.reset(),"ManagedMediaSource"in window){console.log(this.cameraDevice.name,"Using ManagedMediaSource");const t=window.ManagedMediaSource;this.mediaSource=new t,this.mediaSource.addEventListener("sourceopen",(()=>{this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mse",value:this.parseCodecs(t.isTypeSupported.bind(this))}})}),{once:!0}),this.videoPlayer.disableRemotePlayback=!0,this.videoPlayer.srcObject=this.mediaSource}else console.log(this.cameraDevice.name,"Using MediaSource"),this.mediaSource=new MediaSource,this.mediaSource.addEventListener("sourceopen",(()=>{URL.revokeObjectURL(this.videoPlayer.src),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mse",value:this.parseCodecs(MediaSource.isTypeSupported.bind(this))}})}),{once:!0}),this.videoPlayer.src=URL.createObjectURL(this.mediaSource),this.videoPlayer.srcObject=null;this.play(),this.mseCodecs=""}onMseData(t){this.mediaSource&&(this.mseCodecs=t.value,this.bufLen=0,this.buf=new Uint8Array(2097152),this.sourceBuffer=this.mediaSource.addSourceBuffer(t.value),this.sourceBuffer.mode="segments",this.sourceBuffer.addEventListener("updateend",(()=>{if(!this.sourceBuffer?.updating)try{if(this.bufLen>0){const t=this.buf.slice(0,this.bufLen);this.bufLen=0,this.sourceBuffer?.appendBuffer(t)}else if(this.sourceBuffer?.buffered?.length){const t=this.sourceBuffer.buffered.end(this.sourceBuffer.buffered.length-1)-15,e=this.sourceBuffer.buffered.start(0);t>e&&(this.sourceBuffer.remove(e,t),this.mediaSource?.setLiveSeekableRange(t,t+15))}}catch{}})))}async onMseBuffer(t){if("closed"!==this.mediaSource?.readyState)if(this.onFinishLoading(),this.sourceBuffer?.updating||this.bufLen>0){const e=new Uint8Array(t.value);this.buf.set(e,this.bufLen),this.bufLen+=e.byteLength}else try{this.sourceBuffer?.appendBuffer(t.value)}catch{}else this.closed||(this.closed=!0,this.dispatchEvent(new ErrorEvent("error",{message:"MediaSource closed"})),this.options.mode="webrtc",this.requestWebrtc())}requestMjpeg(){this.reset(),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mjpeg"}})}onMjpegBuffer(t){this.videoPlayer.controls=!1,this.videoPlayer.poster="data:image/jpeg;base64,"+this.btoaBinary(t.value),this.onFinishLoading()}requestMp4(){this.reset();const t=document.createElement("canvas");let e=null;this.videoPlayerMp4=document.createElement("video"),this.videoPlayerMp4.autoplay=!0,this.videoPlayerMp4.playsInline=!0,this.videoPlayerMp4.muted=!0,this.videoPlayerMp4.addEventListener("loadeddata",(()=>{this.videoPlayerMp4&&(e||(t.width=this.videoPlayerMp4.videoWidth,t.height=this.videoPlayerMp4.videoHeight,e=t.getContext("2d")),e?.drawImage(this.videoPlayerMp4,0,0,t.width,t.height),this.videoPlayer.controls=!1,this.videoPlayer.poster=t.toDataURL("image/jpeg"))}));const n=this.codecList.filter((t=>this.media.includes(t.indexOf("vc1")>0?"video":"audio"))).filter((t=>this.videoPlayer.canPlayType(`video/mp4; codecs="${t}"`))).join();console.log(this.cameraDevice.name,"Playable codecs (MP4):",n),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"mp4",value:n}})}onMp4Buffer(t){this.onFinishLoading(),this.videoPlayerMp4&&(this.videoPlayerMp4.src="data:video/mp4;base64,"+this.btoaBinary(t.value))}requestHls(){this.reset();const t=this.parseCodecs((t=>this.videoPlayer.canPlayType(t)));console.log(this.cameraDevice.name,"Playable codecs (HLS):",t),this.socket.emit("stream-payload",{id:this.streamId,data:{type:"hls",value:t}})}onHlsData(t){const e="http"+t.wsURL.substring(2,t.wsURL.indexOf("/ws"))+"/hls/",n=t.value.replace("hls/",e),r="data:application/vnd.apple.mpegurl;base64,"+btoa(n.toString());this.videoPlayer.src=r,this.onFinishLoading(),this.play()}onStreamInfo(t){const e=t.value,n=e?.producers[0];n&&(this.hasBackchannel=n.senders?.some((t=>"audio"===t.codec.codec_type))??!1,this.hasAudio=n.receivers?.some((t=>"audio"===t.codec.codec_type))??!1)}async play(){try{await this.videoPlayer.play()}catch(t){if(!this.videoPlayer.muted)return this.videoPlayer.muted=!0,this.play();this.logger.warn(this.cameraDevice.name,t)}}onFirstFrame(){this._firstFrameReceived||(this._firstFrameReceived=!0,this.dispatchEvent(new Event("onFirstFrame")),console.log(this.cameraDevice.name,"First frame received"))}onFinishLoading(){this._finishLoading||(this._finishLoading=!0,this.dispatchEvent(new Event("onFinishLoading")))}createCodecsList(){const t=["avc1.640029","avc1.64002A","avc1.640033","hvc1.1.6.L153.B0","mp4a.40.2","mp4a.40.5","flac","opus"],e="undefined"==typeof window?null:/Version\/(\d+).+Safari/.exec(navigator.userAgent);if(e?.[1]){const n=e[1]<"13"?"mp4a.40.2":e[1]<"14"?"flac":"opus";t.splice(t.indexOf(n))}this.codecList=t}parseCodecs(t){return this.codecList.filter((t=>this.media.includes(t.indexOf("vc1")>0?"video":"audio"))).filter((e=>t(`video/mp4; codecs="${e}"`))).join()}btoaBinary(t){const e=new Uint8Array(t),n=e.byteLength;let r="";for(let t=0;t<n;t++)r+=String.fromCharCode(e[t]);return window.btoa(r)}}class Oe extends Ee{socketService;socket;pluginName="@camera.ui/client";subject;_started=!1;get started(){return this._started}cameraDelegate=new ke(this.onRequest.bind(this));ptzDelegate=new Re(this.onRequest.bind(this));prebufferDelegate=new Pe(this.onRequest.bind(this));get sources(){return JSON.parse(JSON.stringify(this.cameraSubject.getValue().sources)).filter((t=>!t.internal)).map((t=>({...t,getPrebufferingState:e=>this.prebufferDelegate.getPrebufferingState(t.name,e),probeStream:(e,n=!1)=>this.onRequest("cameraFn","probeStream",[t._id,e,n]),getInternalSource:e=>this.internalSources.find((n=>n._id===`${t._id}-${e}`))})))}get internalSources(){return JSON.parse(JSON.stringify(this.cameraSubject.getValue().sources)).filter((t=>t.internal)).map((t=>({...t,probeStream:(e,n=!1)=>this.onRequest("cameraFn","probeStream",[t._id,e,n]),type:t.name.endsWith(" AAC")?"aac":t.name.endsWith(" OPUS")?"opus":"pcma"})))}constructor(t,e,n){super(t,n),this.socketService=e;const{socket:r}=this.socketService.getSocket(this.id,!0);this.socket=r,this.socket.connect(),this.subject=`${this.pluginName}.camera.${this.id}`,this.listenToMessages()}async start(){this._started||(this._started=!0,await this.refreshStates(),this.socket.emit("joinRoomStates",this.id))}stop(){this._started=!1,this.socket.emit("leaveRoomStates",this.id)}close(){this.cleanup()}connect(){return this.onRequest("cameraFn","connect")}disconnect(){return this.onRequest("cameraFn","disconnect")}createWebRTCSession(t){return new Te(this,this.socketService,this.logger,t)}async refreshStates(){const t=await this.onRequest("cameraFn","refreshStates");super.updateCamera(t.camera),super.updateCameraState(t.cameraState);for(const[e,n]of Object.entries(t.states))super.updateStateInternal(e,n,!0)}async cleanup(){this.stop(),this.removeAllListeners(),this.unsubscribe(),this.socket.removeAllListeners()}listenToMessages(){this.socket.emit("joinRoomDevice",this.id),this.socket.on("updateState",(t=>{t.cameraId===this.id&&super.updateStateInternal(t.stateName,t.data.newEvent,!0)})),this.socket.on("updateDevice",(t=>{if(t.cameraId===this.id)switch(t.type){case"removed":this.cleanup();break;case"updated":super.updateCamera(t.data);break;case"cameraState":super.updateCameraState(t.data)}}))}onRequest(t,e,n=[]){const r={requestId:Me(),targetId:this.subject,targetName:this.name,pluginId:this.pluginName,cameraId:this.id,type:"request",proxy:"camera",client:t,fn:e,args:n,timestamp:Date.now(),timeout:5e3};return new Promise(((t,e)=>{this.socket.emit("request",r,(n=>{n.error?e(n.error):t(n.response)}))}))}}class Ae{socketService;socket;logger;pluginName="@camera.ui/client";subject;constructor(t,e){this.socketService=t,this.socket=t.socket,this.logger=e,this.subject=`${this.pluginName}.coreManager`}async getFFmpegPath(){return this.onRequest("getFFmpegPath")}async getHwaccelInfo(t){return this.onRequest("getHwaccelInfo",[t])}async getServerAddresses(){return this.onRequest("getServerAddresses")}async getIceServers(){return this.onRequest("getIceServers")}onRequest(t,e){const n={requestId:Me(),targetId:this.subject,targetName:this.pluginName,pluginId:this.pluginName,type:"request",proxy:"core",client:"coreFn",fn:t,args:e??[],timestamp:Date.now(),timeout:5e3};return new Promise(((t,e)=>{this.socket.emit("request",n,(n=>{n.error?e(n.error):t(n.response)}))}))}}class Ce{socketService;socket;logger;pluginName="@camera.ui/client";subject;constructor(t,e){this.socketService=t,this.socket=t.socket,this.logger=e,this.subject=`${this.pluginName}.deviceManager`}async getCameraById(t){const e=await this.onRequest("getCameraById",[t]);if(e){const t=new Oe(e,this.socketService,this.logger);return await t.refreshStates(),t}}async getCameraByName(t){const e=await this.onRequest("getCameraByName",[t]);if(e){const t=new Oe(e,this.socketService,this.logger);return await t.refreshStates(),t}}onRequest(t,e){const n={requestId:Me(),targetId:this.subject,targetName:this.pluginName,pluginId:this.pluginName,type:"request",proxy:"device",client:"deviceFn",fn:t,args:e??[],timestamp:Date.now(),timeout:5e3};return new Promise(((t,e)=>{this.socket.emit("request",n,(n=>{n.error?e(n.error):t(n.response)}))}))}}const Be=Object.create(null);Be.open="0",Be.close="1",Be.ping="2",Be.pong="3",Be.message="4",Be.upgrade="5",Be.noop="6";const Le=Object.create(null);Object.keys(Be).forEach((t=>{Le[Be[t]]=t}));const Ie={type:"error",data:"parser error"},je="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),Ne="function"==typeof ArrayBuffer,De=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,qe=({type:t,data:e},n,r)=>je&&e instanceof Blob?n?r(e):Fe(e,r):Ne&&(e instanceof ArrayBuffer||De(e))?n?r(e):Fe(new Blob([e]),r):r(Be[t]+(e||"")),Fe=(t,e)=>{const n=new FileReader;return n.onload=function(){const t=n.result.split(",")[1];e("b"+(t||""))},n.readAsDataURL(t)};function Ue(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let Ve;const Ye="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)Ye["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(t)]=t;const ze="function"==typeof ArrayBuffer,Xe=(t,e)=>{if("string"!=typeof t)return{type:"message",data:We(t,e)};const n=t.charAt(0);return"b"===n?{type:"message",data:$e(t.substring(1),e)}:Le[n]?t.length>1?{type:Le[n],data:t.substring(1)}:{type:Le[n]}:Ie},$e=(t,e)=>{if(ze){const n=(t=>{let e,n,r,i,s,o=.75*t.length,a=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const h=new ArrayBuffer(o),u=new Uint8Array(h);for(e=0;e<a;e+=4)n=Ye[t.charCodeAt(e)],r=Ye[t.charCodeAt(e+1)],i=Ye[t.charCodeAt(e+2)],s=Ye[t.charCodeAt(e+3)],u[c++]=n<<2|r>>4,u[c++]=(15&r)<<4|i>>2,u[c++]=(3&i)<<6|63&s;return h})(t);return We(n,e)}return{base64:!0,data:t}},We=(t,e)=>"blob"===e?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,Ge=String.fromCharCode(30);let He;function Je(t){return t.reduce(((t,e)=>t+e.length),0)}function Ke(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let r=0;for(let i=0;i<e;i++)n[i]=t[0][r++],r===t[0].length&&(t.shift(),r=0);return t.length&&r<t[0].length&&(t[0]=t[0].slice(r)),n}function Qe(t){if(t)return function(t){for(var e in Qe.prototype)t[e]=Qe.prototype[e];return t}(t)}Qe.prototype.on=Qe.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},Qe.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},Qe.prototype.off=Qe.prototype.removeListener=Qe.prototype.removeAllListeners=Qe.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i=0;i<r.length;i++)if((n=r[i])===e||n.fn===e){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+t],this},Qe.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(n){r=0;for(var i=(n=n.slice(0)).length;r<i;++r)n[r].apply(this,e)}return this},Qe.prototype.emitReserved=Qe.prototype.emit,Qe.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},Qe.prototype.hasListeners=function(t){return!!this.listeners(t).length};const Ze="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),tn="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function en(t,...e){return e.reduce(((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e)),{})}const nn=tn.setTimeout,rn=tn.clearTimeout;function sn(t,e){e.useNativeTimers?(t.setTimeoutFn=nn.bind(tn),t.clearTimeoutFn=rn.bind(tn)):(t.setTimeoutFn=tn.setTimeout.bind(tn),t.clearTimeoutFn=tn.clearTimeout.bind(tn))}function on(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class an extends Error{constructor(t,e,n){super(t),this.description=e,this.context=n,this.type="TransportError"}}class cn extends Qe{constructor(t){super(),this.writable=!1,sn(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,e,n){return super.emitReserved("error",new an(t,e,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=Xe(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,e={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(e)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const e=function(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}(t);return e.length?"?"+e:""}}class hn extends cn{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",(function(){--t||e()}))),this.writable||(t++,this.once("drain",(function(){--t||e()})))}else e()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const n=t.split(Ge),r=[];for(let t=0;t<n.length;t++){const i=Xe(n[t],e);if(r.push(i),"error"===i.type)break}return r})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const n=t.length,r=new Array(n);let i=0;t.forEach(((t,s)=>{qe(t,!1,(t=>{r[s]=t,++i===n&&e(r.join(Ge))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",e=this.query||{};return!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=on()),this.supportsBinary||e.sid||(e.b64=1),this.createUri(t,e)}}let un=!1;try{un="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const ln=un;function pn(){}class fn extends hn{constructor(t){if(super(t),"undefined"!=typeof location){const e="https:"===location.protocol;let n=location.port;n||(n=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||n!==t.port}}doWrite(t,e){const n=this.request({method:"POST",data:t});n.on("success",e),n.on("error",((t,e)=>{this.onError("xhr post error",t,e)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,e)=>{this.onError("xhr poll error",t,e)})),this.pollXhr=t}}class dn extends Qe{constructor(t,e,n){super(),this.createRequest=t,sn(this,n),this._opts=n,this._method=n.method||"GET",this._uri=e,this._data=void 0!==n.data?n.data:null,this._create()}_create(){var t;const e=en(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");e.xdomain=!!this._opts.xd;const n=this._xhr=this.createRequest(e);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&n.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{n.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var t;3===n.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(n.getResponseHeader("set-cookie"))),4===n.readyState&&(200===n.status||1223===n.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof n.status?n.status:0)}),0))},n.send(this._data)}catch(t){return void this.setTimeoutFn((()=>{this._onError(t)}),0)}"undefined"!=typeof document&&(this._index=dn.requestsCount++,dn.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(void 0!==this._xhr&&null!==this._xhr){if(this._xhr.onreadystatechange=pn,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete dn.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}function gn(){for(let t in dn.requests)dn.requests.hasOwnProperty(t)&&dn.requests[t].abort()}dn.requestsCount=0,dn.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",gn):"function"==typeof addEventListener&&addEventListener("onpagehide"in tn?"pagehide":"unload",gn,!1));const yn=function(){const t=mn({xdomain:!1});return t&&null!==t.responseType}();function mn(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||ln))return new XMLHttpRequest}catch(t){}if(!e)try{return new(tn[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const bn="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class vn extends cn{get name(){return"websocket"}doOpen(){const t=this.uri(),e=this.opts.protocols,n=bn?{}:en(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,e,n)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],r=e===t.length-1;qe(n,this.supportsBinary,(t=>{try{this.doWrite(n,t)}catch(t){}r&&Ze((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=on()),this.supportsBinary||(e.b64=1),this.createUri(t,e)}}const wn=tn.WebSocket||tn.MozWebSocket,xn={websocket:class extends vn{createSocket(t,e,n){return bn?new wn(t,e,n):e?new wn(t,e):new wn(t)}doWrite(t,e){this.ws.send(e)}},webtransport:class extends cn{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this._transport.ready.then((()=>{this._transport.createBidirectionalStream().then((t=>{const e=function(t,e){He||(He=new TextDecoder);const n=[];let r=0,i=-1,s=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(0===r){if(Je(n)<1)break;const t=Ke(n,1);s=!(128&~t[0]),i=127&t[0],r=i<126?3:126===i?1:2}else if(1===r){if(Je(n)<2)break;const t=Ke(n,2);i=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),r=3}else if(2===r){if(Je(n)<8)break;const t=Ke(n,8),e=new DataView(t.buffer,t.byteOffset,t.length),s=e.getUint32(0);if(s>Math.pow(2,21)-1){a.enqueue(Ie);break}i=s*Math.pow(2,32)+e.getUint32(4),r=3}else{if(Je(n)<i)break;const t=Ke(n,i);a.enqueue(Xe(s?t:He.decode(t),e)),r=0}if(0===i||i>t){a.enqueue(Ie);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=t.readable.pipeThrough(e).getReader(),r=new TransformStream({transform(t,e){!function(t,e){je&&t.data instanceof Blob?t.data.arrayBuffer().then(Ue).then(e):Ne&&(t.data instanceof ArrayBuffer||De(t.data))?e(Ue(t.data)):qe(t,!1,(t=>{Ve||(Ve=new TextEncoder),e(Ve.encode(t))}))}(t,(n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const t=new DataView(i.buffer);t.setUint8(0,126),t.setUint16(1,r)}else{i=new Uint8Array(9);const t=new DataView(i.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(r))}t.data&&"string"!=typeof t.data&&(i[0]|=128),e.enqueue(i),e.enqueue(n)}))}});r.readable.pipeTo(t.writable),this._writer=r.writable.getWriter();const i=()=>{n.read().then((({done:t,value:e})=>{t||(this.onPacket(e),i())})).catch((t=>{}))};i();const s={type:"open"};this.query.sid&&(s.data=`{"sid":"${this.query.sid}"}`),this._writer.write(s).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],r=e===t.length-1;this._writer.write(n).then((()=>{r&&Ze((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends fn{constructor(t){super(t);const e=t&&t.forceBase64;this.supportsBinary=yn&&!e}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new dn(mn,this.uri(),t)}}},Sn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,_n=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function En(t){if(t.length>8e3)throw"URI too long";const e=t,n=t.indexOf("["),r=t.indexOf("]");-1!=n&&-1!=r&&(t=t.substring(0,n)+t.substring(n,r).replace(/:/g,";")+t.substring(r,t.length));let i=Sn.exec(t||""),s={},o=14;for(;o--;)s[_n[o]]=i[o]||"";return-1!=n&&-1!=r&&(s.source=e,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=function(t,e){const n=e.replace(/\/{2,9}/g,"/").split("/");return"/"!=e.slice(0,1)&&0!==e.length||n.splice(0,1),"/"==e.slice(-1)&&n.splice(n.length-1,1),n}(0,s.path),s.queryKey=function(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,e,r){e&&(n[e]=r)})),n}(0,s.query),s}const kn="function"==typeof addEventListener&&"function"==typeof removeEventListener,Pn=[];kn&&addEventListener("offline",(()=>{Pn.forEach((t=>t()))}),!1);class Rn extends Qe{constructor(t,e){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(e=t,t=null),t){const n=En(t);e.hostname=n.host,e.secure="https"===n.protocol||"wss"===n.protocol,e.port=n.port,n.query&&(e.query=n.query)}else e.host&&(e.hostname=En(e.host).host);sn(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},e.transports.forEach((t=>{const e=t.prototype.name;this.transports.push(e),this._transportsByName[e]=t})),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},n=t.split("&");for(let t=0,r=n.length;t<r;t++){let r=n[t].split("=");e[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return e}(this.opts.query)),kn&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},Pn.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const n=Object.assign({},this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](n)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const t=this.opts.rememberUpgrade&&Rn.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const e=this.createTransport(t);e.open(),this.setTransport(e)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",(t=>this._onClose("transport close",t)))}onOpen(){this.readyState="open",Rn.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const e=new Error("server error");e.code=t.data,this._onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let n=0;n<this.writeBuffer.length;n++){const r=this.writeBuffer[n].data;if(r&&(t+="string"==typeof(e=r)?function(t){let e=0,n=0;for(let r=0,i=t.length;r<i;r++)e=t.charCodeAt(r),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(r++,n+=4);return n}(e):Math.ceil(1.33*(e.byteLength||e.size))),n>0&&t>this._maxPayload)return this.writeBuffer.slice(0,n);t+=2}var e;return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,Ze((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),t}write(t,e,n){return this._sendPacket("message",t,e,n),this}send(t,e,n){return this._sendPacket("message",t,e,n),this}_sendPacket(t,e,n,r){if("function"==typeof e&&(r=e,e=void 0),"function"==typeof n&&(r=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const i={type:t,data:e,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),r&&this.once("flush",r),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},n=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?n():t()})):this.upgrading?n():t()),this}_onError(t){if(Rn.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),kn&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=Pn.indexOf(this._offlineEventListener);-1!==t&&Pn.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this._prevBufferLen=0}}}Rn.protocol=4;class Mn extends Rn{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let e=this.createTransport(t),n=!1;Rn.priorWebsocketSuccess=!1;const r=()=>{n||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(t=>{if(!n)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;Rn.priorWebsocketSuccess="websocket"===e.name,this.transport.pause((()=>{n||"closed"!==this.readyState&&(h(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}})))};function i(){n||(n=!0,h(),e.close(),e=null)}const s=t=>{const n=new Error("probe error: "+t);n.transport=e.name,i(),this.emitReserved("upgradeError",n)};function o(){s("transport closed")}function a(){s("socket closed")}function c(t){e&&t.name!==e.name&&i()}const h=()=>{e.removeListener("open",r),e.removeListener("error",s),e.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};e.once("open",r),e.once("error",s),e.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn((()=>{n||e.open()}),200):e.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const e=[];for(let n=0;n<t.length;n++)~this.transports.indexOf(t[n])&&e.push(t[n]);return e}}class Tn extends Mn{constructor(t,e={}){const n="object"==typeof t?t:e;(!n.transports||n.transports&&"string"==typeof n.transports[0])&&(n.transports=(n.transports||["polling","websocket","webtransport"]).map((t=>xn[t])).filter((t=>!!t))),super(t,n)}}const On="function"==typeof ArrayBuffer,An=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer,Cn=Object.prototype.toString,Bn="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Cn.call(Blob),Ln="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===Cn.call(File);function In(t){return On&&(t instanceof ArrayBuffer||An(t))||Bn&&t instanceof Blob||Ln&&t instanceof File}function jn(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,n=t.length;e<n;e++)if(jn(t[e]))return!0;return!1}if(In(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return jn(t.toJSON(),!0);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&jn(t[e]))return!0;return!1}function Nn(t){const e=[],n=t.data,r=t;return r.data=Dn(n,e),r.attachments=e.length,{packet:r,buffers:e}}function Dn(t,e){if(!t)return t;if(In(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}if(Array.isArray(t)){const n=new Array(t.length);for(let r=0;r<t.length;r++)n[r]=Dn(t[r],e);return n}if("object"==typeof t&&!(t instanceof Date)){const n={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=Dn(t[r],e));return n}return t}function qn(t,e){return t.data=Fn(t.data,e),delete t.attachments,t}function Fn(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=Fn(t[n],e);else if("object"==typeof t)for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=Fn(t[n],e));return t}const Un=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Vn=5;var Yn;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(Yn||(Yn={}));class zn{constructor(t){this.replacer=t}encode(t){return t.type!==Yn.EVENT&&t.type!==Yn.ACK||!jn(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Yn.EVENT?Yn.BINARY_EVENT:Yn.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let e=""+t.type;return t.type!==Yn.BINARY_EVENT&&t.type!==Yn.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=Nn(t),n=this.encodeAsString(e.packet),r=e.buffers;return r.unshift(n),r}}function Xn(t){return"[object Object]"===Object.prototype.toString.call(t)}class $n extends Qe{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t);const n=e.type===Yn.BINARY_EVENT;n||e.type===Yn.BINARY_ACK?(e.type=n?Yn.EVENT:Yn.ACK,this.reconstructor=new Wn(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!In(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const n={type:Number(t.charAt(0))};if(void 0===Yn[n.type])throw new Error("unknown packet type "+n.type);if(n.type===Yn.BINARY_EVENT||n.type===Yn.BINARY_ACK){const r=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const i=t.substring(r,e);if(i!=Number(i)||"-"!==t.charAt(e))throw new Error("Illegal attachments");n.attachments=Number(i)}if("/"===t.charAt(e+1)){const r=e+1;for(;++e&&","!==t.charAt(e)&&e!==t.length;);n.nsp=t.substring(r,e)}else n.nsp="/";const r=t.charAt(e+1);if(""!==r&&Number(r)==r){const r=e+1;for(;++e;){const n=t.charAt(e);if(null==n||Number(n)!=n){--e;break}if(e===t.length)break}n.id=Number(t.substring(r,e+1))}if(t.charAt(++e)){const r=this.tryParse(t.substr(e));if(!$n.isPayloadValid(n.type,r))throw new Error("invalid payload");n.data=r}return n}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(t){return!1}}static isPayloadValid(t,e){switch(t){case Yn.CONNECT:return Xn(e);case Yn.DISCONNECT:return void 0===e;case Yn.CONNECT_ERROR:return"string"==typeof e||Xn(e);case Yn.EVENT:case Yn.BINARY_EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===Un.indexOf(e[0]));case Yn.ACK:case Yn.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Wn{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=qn(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}function Gn(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const Hn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Jn extends Qe{constructor(t,e,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[Gn(t,"open",this.onopen.bind(this)),Gn(t,"packet",this.onpacket.bind(this)),Gn(t,"error",this.onerror.bind(this)),Gn(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){var n,r,i;if(Hn.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(e.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(e),this;const s={type:Yn.EVENT,data:e,options:{}};if(s.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),s.id=t}const o=null===(r=null===(n=this.io.engine)||void 0===n?void 0:n.transport)||void 0===r?void 0:r.writable,a=this.connected&&!(null===(i=this.io.engine)||void 0===i?void 0:i._hasPingExpired());return this.flags.volatile&&!o||(a?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(t,e){var n;const r=null!==(n=this.flags.timeout)&&void 0!==n?n:this._opts.ackTimeout;if(void 0===r)return void(this.acks[t]=e);const i=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))}),r),s=(...t)=>{this.io.clearTimeoutFn(i),e.apply(this,t)};s.withError=!0,this.acks[t]=s}emitWithAck(t,...e){return new Promise(((n,r)=>{const i=(t,e)=>t?r(t):n(e);i.withError=!0,e.push(i),this.emit(t,...e)}))}_addToQueue(t){let e;"function"==typeof t[t.length-1]&&(e=t.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push(((t,...r)=>{if(n===this._queue[0])return null!==t?n.tryCount>this._opts.retries&&(this._queue.shift(),e&&e(t)):(this._queue.shift(),e&&e(null,...r)),n.pending=!1,this._drainQueue()})),this._queue.push(n),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const e=this._queue[0];e.pending&&!t||(e.pending=!0,e.tryCount++,this.flags=e.flags,this.emit.apply(this,e.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Yn.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach((t=>{if(!this.sendBuffer.some((e=>String(e.id)===t))){const e=this.acks[t];delete this.acks[t],e.withError&&e.call(this,new Error("socket has been disconnected"))}}))}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Yn.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Yn.EVENT:case Yn.BINARY_EVENT:this.onevent(t);break;case Yn.ACK:case Yn.BINARY_ACK:this.onack(t);break;case Yn.DISCONNECT:this.ondisconnect();break;case Yn.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const e=this;let n=!1;return function(...r){n||(n=!0,e.packet({type:Yn.ACK,id:t,data:r}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(delete this.acks[t.id],e.withError&&t.data.unshift(null),e.apply(this,t.data))}onconnect(t,e){this.id=t,this.recovered=e&&this._pid===e,this._pid=e,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Yn.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const n of e)n.apply(this,t.data)}}}function Kn(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Kn.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=1&Math.floor(10*e)?t+n:t-n}return 0|Math.min(t,this.max)},Kn.prototype.reset=function(){this.attempts=0},Kn.prototype.setMin=function(t){this.ms=t},Kn.prototype.setMax=function(t){this.max=t},Kn.prototype.setJitter=function(t){this.jitter=t};class Qn extends Qe{constructor(t,e){var n;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(e=t,t=void 0),(e=e||{}).path=e.path||"/socket.io",this.opts=e,sn(this,e),this.reconnection(!1!==e.reconnection),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=e.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new Kn({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this._readyState="closed",this.uri=t;const r=e.parser||i;this.encoder=new r.Encoder,this.decoder=new r.Decoder,this._autoConnect=!1!==e.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new Tn(this.uri,this.opts);const e=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const r=Gn(e,"open",(function(){n.onopen(),t&&t()})),i=e=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",e),t?t(e):this.maybeReconnectOnOpen()},s=Gn(e,"error",i);if(!1!==this._timeout){const t=this._timeout,n=this.setTimeoutFn((()=>{r(),i(new Error("timeout")),e.close()}),t);this.opts.autoUnref&&n.unref(),this.subs.push((()=>{this.clearTimeoutFn(n)}))}return this.subs.push(r),this.subs.push(s),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Gn(t,"ping",this.onping.bind(this)),Gn(t,"data",this.ondata.bind(this)),Gn(t,"error",this.onerror.bind(this)),Gn(t,"close",this.onclose.bind(this)),Gn(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){Ze((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let n=this.nsps[t];return n?this._autoConnect&&!n.active&&n.connect():(n=new Jn(this,t,e),this.nsps[t]=n),n}_destroy(t){const e=Object.keys(this.nsps);for(const t of e)if(this.nsps[t].active)return;this._close()}_packet(t){const e=this.encoder.encode(t);for(let n=0;n<e.length;n++)this.engine.write(e[n],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,e){var n;this.cleanup(),null===(n=this.engine)||void 0===n||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()})))}),e);this.opts.autoUnref&&n.unref(),this.subs.push((()=>{this.clearTimeoutFn(n)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const Zn={};function tr(t,e){"object"==typeof t&&(e=t,t=void 0);const n=function(t,e="",n){let r=t;n=n||"undefined"!=typeof location&&location,null==t&&(t=n.protocol+"//"+n.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?n.protocol+t:n.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==n?n.protocol+"//"+t:"https://"+t),r=En(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const i=-1!==r.host.indexOf(":")?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+i+":"+r.port+e,r.href=r.protocol+"://"+i+(n&&n.port===r.port?"":":"+r.port),r}(t,(e=e||{}).path||"/socket.io"),r=n.source,i=n.id,s=n.path,o=Zn[i]&&s in Zn[i].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new Qn(r,e):(Zn[i]||(Zn[i]=new Qn(r,e)),a=Zn[i]),n.query&&!e.query&&(e.query=n.queryKey),a.socket(n.path,e)}Object.assign(tr,{Manager:Qn,Socket:Jn,io:tr,connect:tr});class er{socket;token;endpoint;socketList=new Map;constructor(t,e){this.endpoint=t.replace("https://","wss://").replace("http://","ws://"),this.token=e,this.socket=this.getSocket("default").socket,this.socket.connect()}close(){this.socket.emit("end"),this.socket.removeAllListeners(),this.socket.disconnect()}getSocket(t,e){return this.createManager(e)}createManager(t){const e=new Qn(this.endpoint,{reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:1e3,reconnectionDelayMax:5e3,randomizationFactor:.5,timeout:2e4,autoConnect:!0,transports:["websocket","polling"],rejectUnauthorized:!1,secure:!0,forceNew:t}),n=e.socket("/proxy",{auth:{token:`Bearer ${this.token}`}});return{manager:e,socket:n}}}class nr{api;socketService;config;logger;token;deviceManager;coreManager;constructor(t){this.config=t,this.logger=t.logger??{...console,attention:console.warn,success:console.log},this.api=new s(t.endpoint)}async connect(){return this.deviceManager&&this.coreManager||(this.cleanUpClient(),await this.login(),this.token=this.token??this.config.token,this.socketService=new er(this.config.endpoint,this.token),this.coreManager=new Ae(this.socketService,this.logger),this.deviceManager=new Ce(this.socketService,this.logger),this.checkSession()),{coreManager:this.coreManager,deviceManager:this.deviceManager}}async disconnect(){this.socketService?.close(),this.cleanUpClient(),this.config.username&&this.config.password&&await this.api.post("/auth/logout",void 0,{headers:{Authorization:`Bearer ${this.token}`}})}async updateCredentials(t){this.config={...this.config,...t},this.socketService&&await this.disconnect(),await this.connect()}async login(){if(this.config.username&&this.config.password)try{const t=await this.api.post("/auth/login",{username:this.config.username,password:this.config.password}),e=await t.json();this.token=e.access_token}catch(t){throw 401===t.response?.status?new Error("Invalid credentials"):new Error(`Failed to get token: ${t.message}`)}else if(this.config.token&&!this.config.skipCheck)try{await this.api.get("/auth/check",{headers:{Authorization:`Bearer ${this.config.token}`}})}catch(t){throw new Error(`Invalid token: ${t.message}`)}this.token=this.token??this.config.token}getDeviceManager(){return this.deviceManager}checkSession(){this.socketService?.socket.removeListener("invalidToken"),this.socketService?.socket.on("invalidToken",(async t=>{t===this.token&&await this.disconnect()}))}cleanUpClient(){this.deviceManager=void 0}}var rr=r.j;export{rr as CameraUiClient};
|
|
@@ -180,7 +180,7 @@ export interface BaseState<T extends LightState | AudioState | MotionState | Obj
|
|
|
180
180
|
lastEvent?: Omit<T, 'lastEvent'>;
|
|
181
181
|
}
|
|
182
182
|
export interface MotionSetEvent {
|
|
183
|
-
state
|
|
183
|
+
state: boolean;
|
|
184
184
|
detections: Detection[];
|
|
185
185
|
}
|
|
186
186
|
export interface AudioSetEvent {
|
|
@@ -381,6 +381,7 @@ export interface RTSPSession extends Subscribed {
|
|
|
381
381
|
readonly onVideoRtp: Subject<RtpPacket>;
|
|
382
382
|
readonly onAudioRtp: Subject<RtpPacket>;
|
|
383
383
|
reservePort(bufferPorts?: number): Promise<number>;
|
|
384
|
+
startStream(): Promise<void>;
|
|
384
385
|
startTranscoding(ffmpegOptions: FfmpegOptions): Promise<void>;
|
|
385
386
|
transcodeReturnAudio(ffmpegOptions: ReturnAudioFFmpegOptions): Promise<void>;
|
|
386
387
|
stop(): void;
|
|
@@ -587,10 +588,12 @@ export interface JsonSchemaArray extends JsonBaseSchema {
|
|
|
587
588
|
}
|
|
588
589
|
export interface JsonSchemaButton extends JsonBaseSchema {
|
|
589
590
|
type: 'button';
|
|
591
|
+
color?: string;
|
|
590
592
|
}
|
|
591
593
|
export interface JsonSchemaObjectButton {
|
|
592
594
|
label: string;
|
|
593
595
|
onSubmit: string;
|
|
596
|
+
color?: string;
|
|
594
597
|
}
|
|
595
598
|
export interface JsonSchemaObjectWithButtons extends JsonSchemaObject {
|
|
596
599
|
buttons: JsonSchemaObjectButton[];
|
|
@@ -37,7 +37,7 @@ export declare const userPreferencesCamviewViewsLayout: zod.ZodObject<{
|
|
|
37
37
|
cameraId: string;
|
|
38
38
|
index: number;
|
|
39
39
|
}[];
|
|
40
|
-
viewSize:
|
|
40
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
41
41
|
}, {
|
|
42
42
|
name: string;
|
|
43
43
|
type: "dnd" | "view";
|
|
@@ -45,7 +45,7 @@ export declare const userPreferencesCamviewViewsLayout: zod.ZodObject<{
|
|
|
45
45
|
cameraId: string;
|
|
46
46
|
index: number;
|
|
47
47
|
}[];
|
|
48
|
-
viewSize:
|
|
48
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
49
49
|
_id?: string | undefined;
|
|
50
50
|
}>;
|
|
51
51
|
export declare const patchPreferencesCamviewViewsLayout: zod.ZodOptional<zod.ZodObject<{
|
|
@@ -67,14 +67,14 @@ export declare const patchPreferencesCamviewViewsLayout: zod.ZodOptional<zod.Zod
|
|
|
67
67
|
cameraId: string;
|
|
68
68
|
index: number;
|
|
69
69
|
}[] | undefined;
|
|
70
|
-
viewSize?:
|
|
70
|
+
viewSize?: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26 | undefined;
|
|
71
71
|
}, {
|
|
72
72
|
name?: string | undefined;
|
|
73
73
|
cameras?: {
|
|
74
74
|
cameraId: string;
|
|
75
75
|
index: number;
|
|
76
76
|
}[] | undefined;
|
|
77
|
-
viewSize?:
|
|
77
|
+
viewSize?: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26 | undefined;
|
|
78
78
|
}>>;
|
|
79
79
|
export declare const userPreferencesCamview: zod.ZodObject<{
|
|
80
80
|
views: zod.ZodArray<zod.ZodObject<{
|
|
@@ -100,7 +100,7 @@ export declare const userPreferencesCamview: zod.ZodObject<{
|
|
|
100
100
|
cameraId: string;
|
|
101
101
|
index: number;
|
|
102
102
|
}[];
|
|
103
|
-
viewSize:
|
|
103
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
104
104
|
}, {
|
|
105
105
|
name: string;
|
|
106
106
|
type: "dnd" | "view";
|
|
@@ -108,7 +108,7 @@ export declare const userPreferencesCamview: zod.ZodObject<{
|
|
|
108
108
|
cameraId: string;
|
|
109
109
|
index: number;
|
|
110
110
|
}[];
|
|
111
|
-
viewSize:
|
|
111
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
112
112
|
_id?: string | undefined;
|
|
113
113
|
}>, "many">;
|
|
114
114
|
}, "strip", zod.ZodTypeAny, {
|
|
@@ -120,7 +120,7 @@ export declare const userPreferencesCamview: zod.ZodObject<{
|
|
|
120
120
|
cameraId: string;
|
|
121
121
|
index: number;
|
|
122
122
|
}[];
|
|
123
|
-
viewSize:
|
|
123
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
124
124
|
}[];
|
|
125
125
|
}, {
|
|
126
126
|
views: {
|
|
@@ -130,7 +130,7 @@ export declare const userPreferencesCamview: zod.ZodObject<{
|
|
|
130
130
|
cameraId: string;
|
|
131
131
|
index: number;
|
|
132
132
|
}[];
|
|
133
|
-
viewSize:
|
|
133
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
134
134
|
_id?: string | undefined;
|
|
135
135
|
}[];
|
|
136
136
|
}>;
|
|
@@ -260,7 +260,7 @@ export declare const userPreferences: zod.ZodObject<{
|
|
|
260
260
|
cameraId: string;
|
|
261
261
|
index: number;
|
|
262
262
|
}[];
|
|
263
|
-
viewSize:
|
|
263
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
264
264
|
}, {
|
|
265
265
|
name: string;
|
|
266
266
|
type: "dnd" | "view";
|
|
@@ -268,7 +268,7 @@ export declare const userPreferences: zod.ZodObject<{
|
|
|
268
268
|
cameraId: string;
|
|
269
269
|
index: number;
|
|
270
270
|
}[];
|
|
271
|
-
viewSize:
|
|
271
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
272
272
|
_id?: string | undefined;
|
|
273
273
|
}>, "many">;
|
|
274
274
|
}, "strip", zod.ZodTypeAny, {
|
|
@@ -280,7 +280,7 @@ export declare const userPreferences: zod.ZodObject<{
|
|
|
280
280
|
cameraId: string;
|
|
281
281
|
index: number;
|
|
282
282
|
}[];
|
|
283
|
-
viewSize:
|
|
283
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
284
284
|
}[];
|
|
285
285
|
}, {
|
|
286
286
|
views: {
|
|
@@ -290,7 +290,7 @@ export declare const userPreferences: zod.ZodObject<{
|
|
|
290
290
|
cameraId: string;
|
|
291
291
|
index: number;
|
|
292
292
|
}[];
|
|
293
|
-
viewSize:
|
|
293
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
294
294
|
_id?: string | undefined;
|
|
295
295
|
}[];
|
|
296
296
|
}>;
|
|
@@ -362,7 +362,7 @@ export declare const userPreferences: zod.ZodObject<{
|
|
|
362
362
|
cameraId: string;
|
|
363
363
|
index: number;
|
|
364
364
|
}[];
|
|
365
|
-
viewSize:
|
|
365
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
366
366
|
}[];
|
|
367
367
|
};
|
|
368
368
|
}, {
|
|
@@ -384,7 +384,7 @@ export declare const userPreferences: zod.ZodObject<{
|
|
|
384
384
|
cameraId: string;
|
|
385
385
|
index: number;
|
|
386
386
|
}[];
|
|
387
|
-
viewSize:
|
|
387
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
388
388
|
_id?: string | undefined;
|
|
389
389
|
}[];
|
|
390
390
|
};
|
|
@@ -424,7 +424,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
424
424
|
cameraId: string;
|
|
425
425
|
index: number;
|
|
426
426
|
}[];
|
|
427
|
-
viewSize:
|
|
427
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
428
428
|
}, {
|
|
429
429
|
name: string;
|
|
430
430
|
type: "dnd" | "view";
|
|
@@ -432,7 +432,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
432
432
|
cameraId: string;
|
|
433
433
|
index: number;
|
|
434
434
|
}[];
|
|
435
|
-
viewSize:
|
|
435
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
436
436
|
_id?: string | undefined;
|
|
437
437
|
}>, "many">;
|
|
438
438
|
}, "strip", zod.ZodTypeAny, {
|
|
@@ -444,7 +444,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
444
444
|
cameraId: string;
|
|
445
445
|
index: number;
|
|
446
446
|
}[];
|
|
447
|
-
viewSize:
|
|
447
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
448
448
|
}[];
|
|
449
449
|
}, {
|
|
450
450
|
views: {
|
|
@@ -454,7 +454,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
454
454
|
cameraId: string;
|
|
455
455
|
index: number;
|
|
456
456
|
}[];
|
|
457
|
-
viewSize:
|
|
457
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
458
458
|
_id?: string | undefined;
|
|
459
459
|
}[];
|
|
460
460
|
}>;
|
|
@@ -526,7 +526,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
526
526
|
cameraId: string;
|
|
527
527
|
index: number;
|
|
528
528
|
}[];
|
|
529
|
-
viewSize:
|
|
529
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
530
530
|
}[];
|
|
531
531
|
};
|
|
532
532
|
}, {
|
|
@@ -548,7 +548,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
548
548
|
cameraId: string;
|
|
549
549
|
index: number;
|
|
550
550
|
}[];
|
|
551
|
-
viewSize:
|
|
551
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
552
552
|
_id?: string | undefined;
|
|
553
553
|
}[];
|
|
554
554
|
};
|
|
@@ -583,7 +583,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
583
583
|
cameraId: string;
|
|
584
584
|
index: number;
|
|
585
585
|
}[];
|
|
586
|
-
viewSize:
|
|
586
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
587
587
|
}[];
|
|
588
588
|
};
|
|
589
589
|
};
|
|
@@ -616,7 +616,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
616
616
|
cameraId: string;
|
|
617
617
|
index: number;
|
|
618
618
|
}[];
|
|
619
|
-
viewSize:
|
|
619
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
620
620
|
_id?: string | undefined;
|
|
621
621
|
}[];
|
|
622
622
|
};
|
|
@@ -651,7 +651,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
651
651
|
cameraId: string;
|
|
652
652
|
index: number;
|
|
653
653
|
}[];
|
|
654
|
-
viewSize:
|
|
654
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
655
655
|
}[];
|
|
656
656
|
};
|
|
657
657
|
};
|
|
@@ -684,7 +684,7 @@ export declare const createUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
684
684
|
cameraId: string;
|
|
685
685
|
index: number;
|
|
686
686
|
}[];
|
|
687
|
-
viewSize:
|
|
687
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
688
688
|
_id?: string | undefined;
|
|
689
689
|
}[];
|
|
690
690
|
};
|
|
@@ -738,7 +738,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
738
738
|
cameraId: string;
|
|
739
739
|
index: number;
|
|
740
740
|
}[];
|
|
741
|
-
viewSize:
|
|
741
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
742
742
|
}, {
|
|
743
743
|
name: string;
|
|
744
744
|
type: "dnd" | "view";
|
|
@@ -746,7 +746,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
746
746
|
cameraId: string;
|
|
747
747
|
index: number;
|
|
748
748
|
}[];
|
|
749
|
-
viewSize:
|
|
749
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
750
750
|
_id?: string | undefined;
|
|
751
751
|
}>, "many">;
|
|
752
752
|
}, "strip", zod.ZodTypeAny, {
|
|
@@ -758,7 +758,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
758
758
|
cameraId: string;
|
|
759
759
|
index: number;
|
|
760
760
|
}[];
|
|
761
|
-
viewSize:
|
|
761
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
762
762
|
}[];
|
|
763
763
|
}, {
|
|
764
764
|
views: {
|
|
@@ -768,7 +768,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
768
768
|
cameraId: string;
|
|
769
769
|
index: number;
|
|
770
770
|
}[];
|
|
771
|
-
viewSize:
|
|
771
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
772
772
|
_id?: string | undefined;
|
|
773
773
|
}[];
|
|
774
774
|
}>>;
|
|
@@ -840,7 +840,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
840
840
|
cameraId: string;
|
|
841
841
|
index: number;
|
|
842
842
|
}[];
|
|
843
|
-
viewSize:
|
|
843
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
844
844
|
}[];
|
|
845
845
|
} | undefined;
|
|
846
846
|
}, {
|
|
@@ -862,7 +862,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
862
862
|
cameraId: string;
|
|
863
863
|
index: number;
|
|
864
864
|
}[];
|
|
865
|
-
viewSize:
|
|
865
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
866
866
|
_id?: string | undefined;
|
|
867
867
|
}[];
|
|
868
868
|
} | undefined;
|
|
@@ -897,7 +897,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
897
897
|
cameraId: string;
|
|
898
898
|
index: number;
|
|
899
899
|
}[];
|
|
900
|
-
viewSize:
|
|
900
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
901
901
|
}[];
|
|
902
902
|
} | undefined;
|
|
903
903
|
} | undefined;
|
|
@@ -930,7 +930,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
930
930
|
cameraId: string;
|
|
931
931
|
index: number;
|
|
932
932
|
}[];
|
|
933
|
-
viewSize:
|
|
933
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
934
934
|
_id?: string | undefined;
|
|
935
935
|
}[];
|
|
936
936
|
} | undefined;
|
|
@@ -965,7 +965,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
965
965
|
cameraId: string;
|
|
966
966
|
index: number;
|
|
967
967
|
}[];
|
|
968
|
-
viewSize:
|
|
968
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
969
969
|
}[];
|
|
970
970
|
} | undefined;
|
|
971
971
|
} | undefined;
|
|
@@ -998,7 +998,7 @@ export declare const patchUserSchema: zod.ZodEffects<zod.ZodObject<{
|
|
|
998
998
|
cameraId: string;
|
|
999
999
|
index: number;
|
|
1000
1000
|
}[];
|
|
1001
|
-
viewSize:
|
|
1001
|
+
viewSize: 4 | 6 | 1 | 9 | 10 | 16 | 20 | 12 | 7 | 13 | 15 | 26;
|
|
1002
1002
|
_id?: string | undefined;
|
|
1003
1003
|
}[];
|
|
1004
1004
|
} | undefined;
|
|
@@ -10,8 +10,8 @@ export declare class CameraController extends CameraDevice {
|
|
|
10
10
|
private motionTimeout?;
|
|
11
11
|
private objectTimeout?;
|
|
12
12
|
private objectTimeoutDuration;
|
|
13
|
-
private
|
|
14
|
-
private
|
|
13
|
+
private audioTimeout?;
|
|
14
|
+
private audioTimeoutDuration;
|
|
15
15
|
private proxyServer;
|
|
16
16
|
private go2rtcApi;
|
|
17
17
|
private configService;
|
|
@@ -43,9 +43,10 @@ export declare class CameraController extends CameraDevice {
|
|
|
43
43
|
private subscribeToCameraState;
|
|
44
44
|
private subscribeToCameraChanges;
|
|
45
45
|
private subscribeToStateChanges;
|
|
46
|
-
private
|
|
47
|
-
private
|
|
48
|
-
private
|
|
46
|
+
private motionStateChange;
|
|
47
|
+
private objectStateChange;
|
|
48
|
+
private audioStateChange;
|
|
49
|
+
private doorbellStateChange;
|
|
49
50
|
private triggerProxyEvent;
|
|
50
51
|
private proxyRequest;
|
|
51
52
|
private isCameraEvent;
|