📄 firebase-firestore-compat.js
/home/palash/git/site/node_modules/firebase/firebase-firestore-compat.js
Language: js • Lines: 9
((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(require("@firebase/app-compat"),require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app-compat","@firebase/app"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).firebase,e.firebase.INTERNAL.modularAPIs)})(this,function(r7,n7){try{!(function(){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}let a=n(r7),o=()=>{},u=function(t){var r=[];let n=0;for(let i=0;i<t.length;i++){let e=t.charCodeAt(i);e<128?r[n++]=e:(e<2048?r[n++]=e>>6|192:(55296==(64512&e)&&i+1<t.length&&56320==(64512&t.charCodeAt(i+1))?(e=65536+((1023&e)<<10)+(1023&t.charCodeAt(++i)),r[n++]=e>>18|240,r[n++]=e>>12&63|128):r[n++]=e>>12|224,r[n++]=e>>6&63|128),r[n++]=63&e|128)}return r},B={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray(r,e){if(!Array.isArray(r))throw Error("encodeByteArray takes an array as a parameter");this.init_();var n=e?this.byteToCharMapWebSafe_:this.byteToCharMap_,i=[];for(let h=0;h<r.length;h+=3){var s=r[h],a=h+1<r.length,o=a?r[h+1]:0,u=h+2<r.length,l=u?r[h+2]:0;let e=(15&o)<<2|l>>6,t=63&l;u||(t=64,a)||(e=64),i.push(n[s>>2],n[(3&s)<<4|o>>4],n[e],n[t])}return i.join("")},encodeString(e,t){return this.HAS_NATIVE_SUPPORT&&!t?btoa(e):this.encodeByteArray(u(e),t)},decodeString(r,n){if(this.HAS_NATIVE_SUPPORT&&!n)return atob(r);{var i=this.decodeStringToByteArray(r,n);var s=[];let e=0,t=0;for(;e<i.length;){var a,o,u,l=i[e++];l<128?s[t++]=String.fromCharCode(l):191<l&&l<224?(a=i[e++],s[t++]=String.fromCharCode((31&l)<<6|63&a)):239<l&&l<365?(a=((7&l)<<18|(63&i[e++])<<12|(63&i[e++])<<6|63&i[e++])-65536,s[t++]=String.fromCharCode(55296+(a>>10)),s[t++]=String.fromCharCode(56320+(1023&a))):(o=i[e++],u=i[e++],s[t++]=String.fromCharCode((15&l)<<12|(63&o)<<6|63&u))}return s.join("");return}},decodeStringToByteArray(e,t){this.init_();var r=t?this.charToByteMapWebSafe_:this.charToByteMap_,n=[];for(let u=0;u<e.length;){var i=r[e.charAt(u++)],s=u<e.length?r[e.charAt(u)]:0,a=++u<e.length?r[e.charAt(u)]:64,o=++u<e.length?r[e.charAt(u)]:64;if(++u,null==i||null==s||null==a||null==o)throw new q;n.push(i<<2|s>>4),64!==a&&(n.push(s<<4&240|a>>2),64!==o)&&n.push(a<<6&192|o)}return n},init_(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(let e=0;e<this.ENCODED_VALS.length;e++)this.byteToCharMap_[e]=this.ENCODED_VALS.charAt(e),this.charToByteMap_[this.byteToCharMap_[e]]=e,this.byteToCharMapWebSafe_[e]=this.ENCODED_VALS_WEBSAFE.charAt(e),(this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[e]]=e)>=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(e)]=e,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(e)]=e)}}};class q extends Error{constructor(){super(...arguments),this.name="DecodeBase64StringError"}}let G=function(e){var t=u(e);return B.encodeByteArray(t,!0)},j=function(e){return G(e).replace(/\./g,"")},z=function(e){try{return B.decodeString(e,!0)}catch(e){console.error("base64Decode failed: ",e)}return null};function H(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("Unable to locate global object.")}let K=()=>H().__FIREBASE_DEFAULTS__,$=()=>{var e;return"undefined"!=typeof process&&void 0!==process.env&&(e=process.env.__FIREBASE_DEFAULTS__)?JSON.parse(e):void 0},Q=()=>{if("undefined"!=typeof document){let e;try{e=document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/)}catch(e){return}var t=e&&z(e[1]);return t&&JSON.parse(t)}},Y=()=>{try{return o()||K()||$()||Q()}catch(e){console.info("Unable to get __FIREBASE_DEFAULTS__ due to: "+e)}};function W(){return"undefined"!=typeof navigator&&"string"==typeof navigator.userAgent?navigator.userAgent:""}function X(){var e=Y()?.forceEnvironment;if("node"===e)return 1;if("browser"!==e)try{return"[object process]"===Object.prototype.toString.call(global.process)}catch(e){}}function J(){return!X()&&navigator.userAgent&&navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")}function Z(){return!X()&&navigator.userAgent&&(navigator.userAgent.includes("Safari")||navigator.userAgent.includes("WebKit"))&&!navigator.userAgent.includes("Chrome")}class ee extends Error{constructor(e,t,r){super(t),this.code=e,this.customData=r,this.name="FirebaseError",Object.setPrototypeOf(this,ee.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,te.prototype.create)}}class te{constructor(e,t,r){this.service=e,this.serviceName=t,this.errors=r}create(e,...t){var n,r=t[0]||{},i=this.service+"/"+e,s=this.errors[e],s=s?(n=r,s.replace(re,(e,t)=>{var r=n[t];return null!=r?String(r):`<${t}?>`})):"Error",s=this.serviceName+`: ${s} (${i}).`;return new ee(i,s,r)}}let re=/\{\$([^}]+)}/g;function ne(e,t){if(e!==t){var r,n,i=Object.keys(e),s=Object.keys(t);for(r of i){if(!s.includes(r))return!1;var a=e[r],o=t[r];if(ie(a)&&ie(o)){if(!ne(a,o))return!1}else if(a!==o)return!1}for(n of s)if(!i.includes(n))return!1}return!0}function ie(e){return null!==e&&"object"==typeof e}function se(e){return e&&e._delegate?e._delegate:e}function ae(e){try{return(e.startsWith("http://")||e.startsWith("https://")?new URL(e).hostname:e).endsWith(".cloudworkstations.dev")}catch{return!1}}class oe{constructor(e,t,r){this.name=e,this.instanceFactory=t,this.type=r,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}setInstantiationMode(e){return this.instantiationMode=e,this}setMultipleInstances(e){return this.multipleInstances=e,this}setServiceProps(e){return this.serviceProps=e,this}setInstanceCreatedCallback(e){return this.onInstanceCreated=e,this}}var ue,le,c,e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!(function(){var e,t,s;function r(){this.blockSize=-1,this.blockSize=64,this.g=Array(4),this.C=Array(this.blockSize),this.o=this.h=0,this.u()}function n(){}function a(e,t,r){r=r||0;var n=Array(16);if("string"==typeof t)for(var i=0;i<16;++i)n[i]=t.charCodeAt(r++)|t.charCodeAt(r++)<<8|t.charCodeAt(r++)<<16|t.charCodeAt(r++)<<24;else for(i=0;i<16;++i)n[i]=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;t=e.g[0],r=e.g[1];var i=e.g[2],s=e.g[3],a=t+(s^r&(i^s))+n[0]+3614090360&4294967295;a=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=(r=(i=(s=(t=r+(a<<7&4294967295|a>>>25))+((a=s+(i^t&(r^i))+n[1]+3905402710&4294967295)<<12&4294967295|a>>>20))+((a=i+(r^s&(t^r))+n[2]+606105819&4294967295)<<17&4294967295|a>>>15))+((a=r+(t^i&(s^t))+n[3]+3250441966&4294967295)<<22&4294967295|a>>>10))+((a=t+(s^r&(i^s))+n[4]+4118548399&4294967295)<<7&4294967295|a>>>25))+((a=s+(i^t&(r^i))+n[5]+1200080426&4294967295)<<12&4294967295|a>>>20))+((a=i+(r^s&(t^r))+n[6]+2821735955&4294967295)<<17&4294967295|a>>>15))+((a=r+(t^i&(s^t))+n[7]+4249261313&4294967295)<<22&4294967295|a>>>10))+((a=t+(s^r&(i^s))+n[8]+1770035416&4294967295)<<7&4294967295|a>>>25))+((a=s+(i^t&(r^i))+n[9]+2336552879&4294967295)<<12&4294967295|a>>>20))+((a=i+(r^s&(t^r))+n[10]+4294925233&4294967295)<<17&4294967295|a>>>15))+((a=r+(t^i&(s^t))+n[11]+2304563134&4294967295)<<22&4294967295|a>>>10))+((a=t+(s^r&(i^s))+n[12]+1804603682&4294967295)<<7&4294967295|a>>>25))+((a=s+(i^t&(r^i))+n[13]+4254626195&4294967295)<<12&4294967295|a>>>20))+((a=i+(r^s&(t^r))+n[14]+2792965006&4294967295)<<17&4294967295|a>>>15))+((a=r+(t^i&(s^t))+n[15]+1236535329&4294967295)<<22&4294967295|a>>>10))+((a=t+(i^s&(r^i))+n[1]+4129170786&4294967295)<<5&4294967295|a>>>27))+((a=s+(r^i&(t^r))+n[6]+3225465664&4294967295)<<9&4294967295|a>>>23))+((a=i+(t^r&(s^t))+n[11]+643717713&4294967295)<<14&4294967295|a>>>18))+((a=r+(s^t&(i^s))+n[0]+3921069994&4294967295)<<20&4294967295|a>>>12))+((a=t+(i^s&(r^i))+n[5]+3593408605&4294967295)<<5&4294967295|a>>>27))+((a=s+(r^i&(t^r))+n[10]+38016083&4294967295)<<9&4294967295|a>>>23))+((a=i+(t^r&(s^t))+n[15]+3634488961&4294967295)<<14&4294967295|a>>>18))+((a=r+(s^t&(i^s))+n[4]+3889429448&4294967295)<<20&4294967295|a>>>12))+((a=t+(i^s&(r^i))+n[9]+568446438&4294967295)<<5&4294967295|a>>>27))+((a=s+(r^i&(t^r))+n[14]+3275163606&4294967295)<<9&4294967295|a>>>23))+((a=i+(t^r&(s^t))+n[3]+4107603335&4294967295)<<14&4294967295|a>>>18))+((a=r+(s^t&(i^s))+n[8]+1163531501&4294967295)<<20&4294967295|a>>>12))+((a=t+(i^s&(r^i))+n[13]+2850285829&4294967295)<<5&4294967295|a>>>27))+((a=s+(r^i&(t^r))+n[2]+4243563512&4294967295)<<9&4294967295|a>>>23))+((a=i+(t^r&(s^t))+n[7]+1735328473&4294967295)<<14&4294967295|a>>>18))+((a=r+(s^t&(i^s))+n[12]+2368359562&4294967295)<<20&4294967295|a>>>12))+((a=t+(r^i^s)+n[5]+4294588738&4294967295)<<4&4294967295|a>>>28))+((a=s+(t^r^i)+n[8]+2272392833&4294967295)<<11&4294967295|a>>>21))+((a=i+(s^t^r)+n[11]+1839030562&4294967295)<<16&4294967295|a>>>16))+((a=r+(i^s^t)+n[14]+4259657740&4294967295)<<23&4294967295|a>>>9))+((a=t+(r^i^s)+n[1]+2763975236&4294967295)<<4&4294967295|a>>>28))+((a=s+(t^r^i)+n[4]+1272893353&4294967295)<<11&4294967295|a>>>21))+((a=i+(s^t^r)+n[7]+4139469664&4294967295)<<16&4294967295|a>>>16))+((a=r+(i^s^t)+n[10]+3200236656&4294967295)<<23&4294967295|a>>>9))+((a=t+(r^i^s)+n[13]+681279174&4294967295)<<4&4294967295|a>>>28))+((a=s+(t^r^i)+n[0]+3936430074&4294967295)<<11&4294967295|a>>>21))+((a=i+(s^t^r)+n[3]+3572445317&4294967295)<<16&4294967295|a>>>16))+((a=r+(i^s^t)+n[6]+76029189&4294967295)<<23&4294967295|a>>>9))+((a=t+(r^i^s)+n[9]+3654602809&4294967295)<<4&4294967295|a>>>28))+((a=s+(t^r^i)+n[12]+3873151461&4294967295)<<11&4294967295|a>>>21))+((a=i+(s^t^r)+n[15]+530742520&4294967295)<<16&4294967295|a>>>16))+((a=r+(i^s^t)+n[2]+3299628645&4294967295)<<23&4294967295|a>>>9))+((a=t+(i^(r|~s))+n[0]+4096336452&4294967295)<<6&4294967295|a>>>26))+((a=s+(r^(t|~i))+n[7]+1126891415&4294967295)<<10&4294967295|a>>>22))+((a=i+(t^(s|~r))+n[14]+2878612391&4294967295)<<15&4294967295|a>>>17))+((a=r+(s^(i|~t))+n[5]+4237533241&4294967295)<<21&4294967295|a>>>11))+((a=t+(i^(r|~s))+n[12]+1700485571&4294967295)<<6&4294967295|a>>>26))+((a=s+(r^(t|~i))+n[3]+2399980690&4294967295)<<10&4294967295|a>>>22))+((a=i+(t^(s|~r))+n[10]+4293915773&4294967295)<<15&4294967295|a>>>17))+((a=r+(s^(i|~t))+n[1]+2240044497&4294967295)<<21&4294967295|a>>>11))+((a=t+(i^(r|~s))+n[8]+1873313359&4294967295)<<6&4294967295|a>>>26))+((a=s+(r^(t|~i))+n[15]+4264355552&4294967295)<<10&4294967295|a>>>22))+((a=i+(t^(s|~r))+n[6]+2734768916&4294967295)<<15&4294967295|a>>>17))+((a=r+(s^(i|~t))+n[13]+1309151649&4294967295)<<21&4294967295|a>>>11))+((s=(t=r+((a=t+(i^(r|~s))+n[4]+4149444226&4294967295)<<6&4294967295|a>>>26))+((a=s+(r^(t|~i))+n[11]+3174756917&4294967295)<<10&4294967295|a>>>22))^((i=s+((a=i+(t^(s|~r))+n[2]+718787259&4294967295)<<15&4294967295|a>>>17))|~t))+n[9]+3951481745&4294967295,e.g[0]=e.g[0]+t&4294967295,e.g[1]=e.g[1]+(i+(a<<21&4294967295|a>>>11))&4294967295,e.g[2]=e.g[2]+i&4294967295,e.g[3]=e.g[3]+s&4294967295}function u(e,t){this.h=t;var r=[];let n=!0;for(let s=e.length-1;0<=s;s--){var i=0|e[s];n&&i==t||(r[s]=i,n=!1)}this.g=r}t=r,s=function(){this.blockSize=-1},n.prototype=s.prototype,t.F=s.prototype,t.prototype=new n,(t.prototype.constructor=t).D=function(e,t,r){for(var n=Array(arguments.length-2),i=2;i<arguments.length;i++)n[i-2]=arguments[i];return s.prototype[t].apply(e,n)},r.prototype.u=function(){this.g[0]=1732584193,this.g[1]=4023233417,this.g[2]=2562383102,this.g[3]=271733878,this.o=this.h=0},r.prototype.v=function(e,t){var r=(t=void 0===t?e.length:t)-this.blockSize,n=this.C;let i=this.h,s=0;for(;s<t;){if(0==i)for(;s<=r;)a(this,e,s),s+=this.blockSize;if("string"==typeof e){for(;s<t;)if(n[i++]=e.charCodeAt(s++),i==this.blockSize){a(this,n),i=0;break}}else for(;s<t;)if(n[i++]=e[s++],i==this.blockSize){a(this,n),i=0;break}}this.h=i,this.o+=t},r.prototype.A=function(){var t=Array((this.h<56?this.blockSize:2*this.blockSize)-this.h);t[0]=128;for(var r=1;r<t.length-8;++r)t[r]=0;for(var r=8*this.o,n=t.length-8;n<t.length;++n)t[n]=255&r,r/=256;for(this.v(t),t=Array(16),n=r=0;n<4;++n)for(let e=0;e<32;e+=8)t[r++]=this.g[n]>>>e&255;return t};var i={};function o(e){return-128<=e&&e<128?(t=e,r=function(e){return new u([0|e],e<0?-1:0)},n=i,Object.prototype.hasOwnProperty.call(n,t)?n[t]:n[t]=r(t)):new u([0|e],e<0?-1:0);var t,r,n}function l(e){if(isNaN(e)||!isFinite(e))return h;if(e<0)return g(l(-e));var t=[];let r=1;for(let n=0;e>=r;n++)t[n]=e/r|0,r*=4294967296;return new u(t,0)}var h=o(0),c=o(1),d=o(16777216);function p(t){if(0==t.h){for(let e=0;e<t.g.length;e++)if(0!=t.g[e])return;return 1}}function f(e){return-1==e.h}function g(e){var t=e.g.length,r=[];for(let n=0;n<t;n++)r[n]=~e.g[n];return new u(r,~e.h).add(c)}function m(e,t){return e.add(g(t))}function v(e,t){for(;(65535&e[t])!=e[t];)e[t+1]+=e[t]>>>16,e[t]&=65535,t++}function y(e,t){this.g=e,this.h=t}function w(e,t){if(p(t))throw Error("division by zero");if(p(e))return new y(h,h);if(f(e))return t=w(g(e),t),new y(g(t.g),g(t.h));if(f(t))return t=w(e,g(t)),new y(g(t.g),t.h);if(30<e.g.length){if(f(e)||f(t))throw Error("slowDivide_ only works with positive integers.");for(var r=c,n=t;n.l(e)<=0;)r=_(r),n=_(n);for(var i=E(r,1),s=E(n,1),n=E(n,2),r=E(r,2);!p(n);){var a=s.add(n);a.l(e)<=0&&(i=i.add(r),s=a),n=E(n,1),r=E(r,1)}return t=m(e,i.j(t)),new y(i,t)}for(i=h;0<=e.l(t);){for(r=Math.max(1,Math.floor(e.m()/t.m())),n=(n=Math.ceil(Math.log(r)/Math.LN2))<=48?1:Math.pow(2,n-48),a=(s=l(r)).j(t);f(a)||0<a.l(e);)a=(s=l(r-=n)).j(t);p(s)&&(s=c),i=i.add(s),e=m(e,a)}return new y(i,e)}function _(e){var t=e.g.length+1,r=[];for(let n=0;n<t;n++)r[n]=e.i(n)<<1|e.i(n-1)>>>31;return new u(r,e.h)}function E(e,t){var r=t>>5,n=(t%=32,e.g.length-r),i=[];for(let s=0;s<n;s++)i[s]=0<t?e.i(s+r)>>>t|e.i(s+r+1)<<32-t:e.i(s+r);return new u(i,e.h)}(e=u.prototype).m=function(){if(f(this))return-g(this).m();let e=0,t=1;for(let n=0;n<this.g.length;n++){var r=this.i(n);e+=(0<=r?r:4294967296+r)*t,t*=4294967296}return e},e.toString=function(t){if((t=t||10)<2||36<t)throw Error("radix out of range: "+t);if(p(this))return"0";if(f(this))return"-"+g(this).toString(t);var r=l(Math.pow(t,6)),n=this;let i="";for(;;){var s=w(n,r).g;let e=((0<(n=m(n,s.j(r))).g.length?n.g[0]:n.h)>>>0).toString(t);if(p(n=s))return e+i;for(;e.length<6;)e="0"+e;i=e+i}},e.i=function(e){return e<0?0:e<this.g.length?this.g[e]:this.h},e.l=function(e){return f(e=m(this,e))?-1:p(e)?0:1},e.abs=function(){return f(this)?g(this):this},e.add=function(e){var t=Math.max(this.g.length,e.g.length),r=[];let n=0;for(let a=0;a<=t;a++){var i=n+(65535&this.i(a))+(65535&e.i(a)),s=(i>>>16)+(this.i(a)>>>16)+(e.i(a)>>>16);n=s>>>16,i&=65535,s&=65535,r[a]=s<<16|i}return new u(r,-2147483648&r[r.length-1]?-1:0)},e.j=function(t){if(p(this)||p(t))return h;if(f(this))return f(t)?g(this).j(g(t)):g(g(this).j(t));if(f(t))return g(this.j(g(t)));if(this.l(d)<0&&t.l(d)<0)return l(this.m()*t.m());for(var e=this.g.length+t.g.length,r=[],n=0;n<2*e;n++)r[n]=0;for(n=0;n<this.g.length;n++)for(let e=0;e<t.g.length;e++){var i=this.i(n)>>>16,s=65535&this.i(n),a=t.i(e)>>>16,o=65535&t.i(e);r[2*n+2*e]+=s*o,v(r,2*n+2*e),r[2*n+2*e+1]+=i*o,v(r,2*n+2*e+1),r[2*n+2*e+1]+=s*a,v(r,2*n+2*e+1),r[2*n+2*e+2]+=i*a,v(r,2*n+2*e+2)}for(t=0;t<e;t++)r[t]=r[2*t+1]<<16|r[2*t];for(t=e;t<2*e;t++)r[t]=0;return new u(r,0)},e.B=function(e){return w(this,e).h},e.and=function(e){var t=Math.max(this.g.length,e.g.length),r=[];for(let n=0;n<t;n++)r[n]=this.i(n)&e.i(n);return new u(r,this.h&e.h)},e.or=function(e){var t=Math.max(this.g.length,e.g.length),r=[];for(let n=0;n<t;n++)r[n]=this.i(n)|e.i(n);return new u(r,this.h|e.h)},e.xor=function(e){var t=Math.max(this.g.length,e.g.length),r=[];for(let n=0;n<t;n++)r[n]=this.i(n)^e.i(n);return new u(r,this.h^e.h)},r.prototype.digest=r.prototype.A,r.prototype.reset=r.prototype.u,r.prototype.update=r.prototype.v,le=r,u.prototype.multiply=u.prototype.j,u.prototype.modulo=u.prototype.B,u.prototype.compare=u.prototype.l,u.prototype.toNumber=u.prototype.m,u.prototype.getBits=u.prototype.i,u.fromNumber=l,u.fromString=function e(t,r){if(0==t.length)throw Error("number format error: empty string");if((r=r||10)<2||36<r)throw Error("radix out of range: "+r);if("-"==t.charAt(0))return g(e(t.substring(1),r));if(0<=t.indexOf("-"))throw Error('number format error: interior "-" character');var n=l(Math.pow(r,8));let i=h;for(let o=0;o<t.length;o+=8){var s=Math.min(8,t.length-o),a=parseInt(t.substring(o,o+s),r);i=(s<8?(s=l(Math.pow(r,s)),i.j(s)):i=i.j(n)).add(l(a))}return i},ue=u}).apply(void 0!==e?e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),(B0=c=c||{})[B0.DEBUG=0]="DEBUG",B0[B0.VERBOSE=1]="VERBOSE",B0[B0.INFO=2]="INFO",B0[B0.WARN=3]="WARN",B0[B0.ERROR=4]="ERROR",B0[B0.SILENT=5]="SILENT";let he={debug:c.DEBUG,verbose:c.VERBOSE,info:c.INFO,warn:c.WARN,error:c.ERROR,silent:c.SILENT},ce=c.INFO,de={[c.DEBUG]:"log",[c.VERBOSE]:"log",[c.INFO]:"info",[c.WARN]:"warn",[c.ERROR]:"error"},pe=(e,t,...r)=>{if(!(t<e.logLevel)){var n=(new Date).toISOString(),i=de[t];if(!i)throw new Error(`Attempted to log a message with an invalid logType (value: ${t})`);console[i](`[${n}]  ${e.name}:`,...r)}};var ar,or,ur,lr,hr,cr,dr,pr,fr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!(function(){var e,M=Object.defineProperty;var V=(e=>{e=["object"==typeof globalThis&&globalThis,e,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof fr&&fr];for(var t=0;t<e.length;++t){var r=e[t];if(r&&r.Math==Math)return r}throw Error("Cannot find global object")})(this);function F(e,t){if(t)e:{var r=V;e=e.split(".");for(var n=0;n<e.length-1;n++){var i=e[n];if(!(i in r))break e;r=r[i]}(t=t(n=r[e=e[e.length-1]]))!=n&&null!=t&&M(r,e,{configurable:!0,writable:!0,value:t})}}F("Symbol.dispose",function(e){return e||Symbol("Symbol.dispose")}),F("Array.prototype.values",function(e){return e||function(){return this[Symbol.iterator]()}}),F("Object.entries",function(e){return e||function(e){var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.push([t,e[t]]);return r}});var U=U||{},N=this||self;function d(e){var t=typeof e;return"object"==t&&null!=e||"function"==t}function B(e,t,r){return e.call.apply(e.bind,arguments)}function v(e,t,r){return(v=B).apply(null,arguments)}function q(t){var r=Array.prototype.slice.call(arguments,1);return function(){var e=r.slice();return e.push.apply(e,arguments),t.apply(this,e)}}function t(e,s){function t(){}t.prototype=s.prototype,e.Z=s.prototype,e.prototype=new t,(e.prototype.constructor=e).Ob=function(e,t,r){for(var n=Array(arguments.length-2),i=2;i<arguments.length;i++)n[i-2]=arguments[i];return s.prototype[t].apply(e,n)}}var G="undefined"!=typeof AsyncContext&&"function"==typeof AsyncContext.Snapshot?e=>e&&AsyncContext.Snapshot.wrap(e):e=>e;function j(t){var r=t.length;if(0<r){var n=Array(r);for(let e=0;e<r;e++)n[e]=t[e];return n}return[]}function z(t){for(let e=1;e<arguments.length;e++){var r=arguments[e];if("array"==(n="object"!=(n=typeof r)?n:r?Array.isArray(r)?"array":n:"null")||"object"==n&&"number"==typeof r.length){var n=t.length||0,i=r.length||0;t.length=n+i;for(let e=0;e<i;e++)t[n+e]=r[e]}else t.push(r)}}var H=new class{constructor(e,t){this.i=e,this.j=t,this.h=0,this.g=null}get(){let e;return 0<this.h?(this.h--,e=this.g,this.g=e.next,e.next=null):e=this.i(),e}}(()=>new K,e=>e.reset());class K{constructor(){this.next=this.g=this.h=null}set(e,t){this.h=e,this.g=t,this.next=null}reset(){this.next=this.g=this.h=null}}let r,n=!1,$=new class{constructor(){this.h=this.g=null}add(e,t){var r=H.get();r.set(e,t),this.h?this.h.next=r:this.g=r,this.h=r}},Q=()=>{let e=Promise.resolve(void 0);r=()=>{e.then(Y)}};function Y(){for(var e;e=(()=>{let e=$,t=null;return e.g&&(t=e.g,e.g=e.g.next,e.g||(e.h=null),t.next=null),t})();){try{e.h.call(e.g)}catch(e){(e=>{N.setTimeout(()=>{throw e},0)})(e)}var t=H;t.j(e),t.h<100&&(t.h++,e.next=t.g,t.g=e)}n=!1}function i(){this.u=this.u,this.C=this.C}function o(e,t){this.type=e,this.g=this.target=t,this.defaultPrevented=!1}i.prototype.u=!1,i.prototype.dispose=function(){this.u||(this.u=!0,this.N())},i.prototype[Symbol.dispose]=function(){this.dispose()},i.prototype.N=function(){if(this.C)for(;this.C.length;)this.C.shift()()},o.prototype.h=function(){this.defaultPrevented=!0};var W=(()=>{if(!N.addEventListener||!Object.defineProperty)return!1;var e=!1,t=Object.defineProperty({},"passive",{get:function(){e=!0}});try{var r=()=>{};N.addEventListener("test",r,t),N.removeEventListener("test",r,t)}catch(e){}return e})();function D(e){return/^[\s\xa0]*$/.test(e)}function s(e,t){o.call(this,e?e.type:""),this.relatedTarget=this.g=this.target=null,this.button=this.screenY=this.screenX=this.clientY=this.clientX=0,this.key="",this.metaKey=this.shiftKey=this.altKey=this.ctrlKey=!1,this.state=null,this.pointerId=0,this.pointerType="",this.i=null,e&&this.init(e,t)}t(s,o),s.prototype.init=function(e,t){var r=this.type=e.type,n=e.changedTouches&&e.changedTouches.length?e.changedTouches[0]:null;this.target=e.target||e.srcElement,this.g=t,(t=e.relatedTarget)||("mouseover"==r?t=e.fromElement:"mouseout"==r&&(t=e.toElement)),this.relatedTarget=t,n?(this.clientX=void 0!==n.clientX?n.clientX:n.pageX,this.clientY=void 0!==n.clientY?n.clientY:n.pageY,this.screenX=n.screenX||0,this.screenY=n.screenY||0):(this.clientX=void 0!==e.clientX?e.clientX:e.pageX,this.clientY=void 0!==e.clientY?e.clientY:e.pageY,this.screenX=e.screenX||0,this.screenY=e.screenY||0),this.button=e.button,this.key=e.key||"",this.ctrlKey=e.ctrlKey,this.altKey=e.altKey,this.shiftKey=e.shiftKey,this.metaKey=e.metaKey,this.pointerId=e.pointerId||0,this.pointerType=e.pointerType,this.state=e.state,(this.i=e).defaultPrevented&&s.Z.h.call(this)},s.prototype.h=function(){s.Z.h.call(this);var e=this.i;e.preventDefault?e.preventDefault():e.returnValue=!1};var u="closure_listenable_"+(1e6*Math.random()|0),X=0;function J(e,t,r,n,i){this.listener=e,this.proxy=null,this.src=t,this.type=r,this.capture=!!n,this.ha=i,this.key=++X,this.da=this.fa=!1}function Z(e){e.da=!0,e.listener=null,e.proxy=null,e.src=null,e.ha=null}function ee(e,t,r){for(var n in e)t.call(r,e[n],n,e)}function te(e){var t,r={};for(t in e)r[t]=e[t];return r}let re="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function ne(t){let r,n;for(let i=1;i<arguments.length;i++){for(r in n=arguments[i])t[r]=n[r];for(let e=0;e<re.length;e++)r=re[e],Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}}function ie(e){this.src=e,this.g={},this.h=0}function se(e,t){var r,n,i,s=t.type;s in e.g&&(r=e.g[s],(i=0<=(n=Array.prototype.indexOf.call(r,t,void 0)))&&Array.prototype.splice.call(r,n,1),i)&&(Z(t),0==e.g[s].length)&&(delete e.g[s],e.h--)}function ae(e,t,r,n){for(let s=0;s<e.length;++s){var i=e[s];if(!i.da&&i.listener==t&&i.capture==!!r&&i.ha==n)return s}return-1}ie.prototype.add=function(e,t,r,n,i){var s=e.toString(),a=((e=this.g[s])||(e=this.g[s]=[],this.h++),ae(e,t,n,i));return-1<a?(t=e[a],r||(t.fa=!1)):((t=new J(t,this.src,s,!!n,i)).fa=r,e.push(t)),t};var oe="closure_lm_"+(1e6*Math.random()|0),ue={};function le(t,r,n,i,s){if(i&&i.once)return function t(r,n,i,s,a){if(Array.isArray(n)){for(let e=0;e<n.length;e++)t(r,n[e],i,s,a);return null}i=me(i);return r&&r[u]?r.K(n,i,d(s)?!!s.capture:!!s,a):he(r,n,i,!0,s,a)}(t,r,n,i,s);if(Array.isArray(r)){for(let e=0;e<r.length;e++)le(t,r[e],n,i,s);return null}return n=me(n),t&&t[u]?t.J(r,n,d(i)?!!i.capture:!!i,s):he(t,r,n,!1,i,s)}function he(e,t,r,n,i,s){if(!t)throw Error("Invalid event type");var a=d(i)?!!i.capture:!!i;let o=fe(e);if(o||(e[oe]=o=new ie(e)),!(r=o.add(t,r,n,a,s)).proxy)if(n=(()=>{let r=pe;return function e(t){return r.call(e.src,e.listener,t)}})(),(r.proxy=n).src=e,n.listener=r,e.addEventListener)void 0===(i=W?i:a)&&(i=!1),e.addEventListener(t.toString(),n,i);else if(e.attachEvent)e.attachEvent(de(t.toString()),n);else{if(!e.addListener||!e.removeListener)throw Error("addEventListener and attachEvent are unavailable.");e.addListener(n)}return r}function ce(e){var t,r,n;"number"!=typeof e&&e&&!e.da&&((t=e.src)&&t[u]?se(t.i,e):(r=e.type,n=e.proxy,t.removeEventListener?t.removeEventListener(r,n,e.capture):t.detachEvent?t.detachEvent(de(r),n):t.addListener&&t.removeListener&&t.removeListener(n),(r=fe(t))?(se(r,e),0==r.h&&(r.src=null,t[oe]=null)):Z(e)))}function de(e){return e in ue?ue[e]:ue[e]="on"+e}function pe(e,t){var r,n;return e=!!e.da||(t=new s(t,this),r=e.listener,n=e.ha||e.src,e.fa&&ce(e),r.call(n,t))}function fe(e){return(e=e[oe])instanceof ie?e:null}var ge="__closure_events_fn_"+(1e9*Math.random()>>>0);function me(t){return"function"==typeof t?t:(t[ge]||(t[ge]=function(e){return t.handleEvent(e)}),t[ge])}function a(){i.call(this),this.i=new ie(this),(this.M=this).G=null}function l(e,t){var r,n,i=e.G;if(i)for(r=[];i;i=i.G)r.push(i);e=e.M,i=t.type||t,"string"==typeof t?t=new o(t,e):t instanceof o?t.target=t.target||e:(n=t,ne(t=new o(i,e),n)),n=!0;let s,a;if(r)for(a=r.length-1;0<=a;a--)n=ve(s=t.g=r[a],i,!0,t)&&n;if(n=ve(s=t.g=e,i,!0,t)&&n,n=ve(s,i,!1,t)&&n,r)for(a=0;a<r.length;a++)n=ve(s=t.g=r[a],i,!1,t)&&n}function ve(e,t,r,n){if(!(t=e.i.g[String(t)]))return!0;t=t.concat();let i=!0;for(let u=0;u<t.length;++u){var s,a,o=t[u];o&&!o.da&&o.capture==r&&(s=o.listener,a=o.ha||o.src,o.fa&&se(e.i,o),i=!1!==s.call(a,n)&&i)}return i&&!n.defaultPrevented}function ye(e){e.g=((e,t)=>{if("function"!=typeof e){if(!e||"function"!=typeof e.handleEvent)throw Error("Invalid listener argument");e=v(e.handleEvent,e)}return 2147483647<Number(t)?-1:N.setTimeout(e,t||0)})(()=>{e.g=null,e.i&&(e.i=!1,ye(e))},e.l);var t=e.h;e.h=null,e.m.apply(null,t)}t(a,i),a.prototype[u]=!0,a.prototype.removeEventListener=function(e,t,r,n){!function e(t,r,n,i,s){if(Array.isArray(r))for(var a=0;a<r.length;a++)e(t,r[a],n,i,s);else i=d(i)?!!i.capture:!!i,n=me(n),t&&t[u]?(t=t.i,(a=String(r).toString())in t.g&&-1<(n=ae(r=t.g[a],n,i,s))&&(Z(r[n]),Array.prototype.splice.call(r,n,1),0==r.length)&&(delete t.g[a],t.h--)):(t=t&&fe(t))&&(r=t.g[r.toString()],n=(t=-1)<(t=r?ae(r,n,i,s):t)?r[t]:null)&&ce(n)}(this,e,t,r,n)},a.prototype.N=function(){if(a.Z.N.call(this),this.i){var t,r=this.i;for(t in r.g){var n=r.g[t];for(let e=0;e<n.length;e++)Z(n[e]);delete r.g[t],r.h--}}this.G=null},a.prototype.J=function(e,t,r,n){return this.i.add(String(e),t,!1,r,n)},a.prototype.K=function(e,t,r,n){return this.i.add(String(e),t,!0,r,n)};class we extends i{constructor(e,t){super(),this.m=e,this.l=t,this.h=null,this.i=!1,this.g=null}j(e){this.h=arguments,this.g?this.i=!0:ye(this)}N(){super.N(),this.g&&(N.clearTimeout(this.g),this.g=null,this.i=!1,this.h=null)}}function h(e){i.call(this),this.h=e,this.g={}}t(h,i);var _e=[];function Ee(e){ee(e.g,function(e,t){this.g.hasOwnProperty(t)&&ce(e)},e),e.g={}}h.prototype.N=function(){h.Z.N.call(this),Ee(this)},h.prototype.handleEvent=function(){throw Error("EventHandler.handleEvent not implemented")};var Te=N.JSON.stringify,be=N.JSON.parse,Se=class{stringify(e){return N.JSON.stringify(e,void 0)}parse(e){return N.JSON.parse(e,void 0)}};function Ie(){}function Ae(){}var Ce={OPEN:"a",hb:"b",ERROR:"c",tb:"d"};function xe(){o.call(this,"d")}function Ne(){o.call(this,"c")}t(xe,o),t(Ne,o);var c={},De=null;function Oe(){return De=De||new a}function Re(e){o.call(this,c.Ia,e)}function ke(){var e=Oe();l(e,new Re(e))}function Le(e,t){o.call(this,c.STAT_EVENT,e),this.stat=t}function O(e){var t=Oe();l(t,new Le(t,e))}function Pe(e,t){o.call(this,c.Ja,e),this.size=t}function y(e,t){if("function"!=typeof e)throw Error("Fn must not be null and must be a function");return N.setTimeout(function(){e()},t)}function p(){this.g=!0}function R(e,t,r,n){e.info(function(){return"XMLHTTP TEXT ("+t+"): "+((e,t)=>{if(!e.g)return t;if(!t)return null;try{var r=JSON.parse(t);if(r)for(e=0;e<r.length;e++)if(Array.isArray(r[e])){var n=r[e];if(!(n.length<2)){var i=n[1];if(Array.isArray(i)&&!(i.length<1)){var s=i[0];if("noop"!=s&&"stop"!=s&&"close"!=s)for(let e=1;e<i.length;e++)i[e]=""}}}return Te(r)}catch(e){return t}})(e,r)+(n?" "+n:"")})}c.Ia="serverreachability",t(Re,o),c.STAT_EVENT="statevent",t(Le,o),c.Ja="timingevent",t(Pe,o),p.prototype.ua=function(){this.g=!1},p.prototype.info=function(){};var Me={NO_ERROR:0,cb:1,qb:2,pb:3,kb:4,ob:5,rb:6,Ga:7,TIMEOUT:8,ub:9},Ve={ib:"complete",Fb:"success",ERROR:"error",Ga:"abort",xb:"ready",yb:"readystatechange",TIMEOUT:"timeout",sb:"incrementaldata",wb:"progress",lb:"downloadprogress",Nb:"uploadprogress"};function Fe(){}function f(e){return encodeURIComponent(String(e))}function g(e,t,r,n){this.j=e,this.i=t,this.l=r,this.S=n||1,this.V=new h(this),this.H=45e3,this.J=null,this.o=!1,this.u=this.B=this.A=this.M=this.F=this.T=this.D=null,this.G=[],this.g=null,this.C=0,this.m=this.v=null,this.X=-1,this.K=!1,this.P=0,this.O=null,this.W=this.L=this.U=this.R=!1,this.h=new Ue}function Ue(){this.i=null,this.g="",this.h=!1}t(Fe,Ie),Fe.prototype.g=function(){return new XMLHttpRequest};var Be=new Fe,qe={},Ge={};function je(e,t,r){e.M=1,e.A=ot(w(t)),e.u=r,e.R=!0,ze(e,null)}function ze(e,t){e.F=Date.now(),Ke(e),e.B=w(e.A);var a,o,u,l,h,c,r=e.B,n=e.S,i=(Array.isArray(n)||(n=[String(n)]),_t(r.i,"t",n),e.C=0,r=e.j.L,e.h=new Ue,e.g=tr(e.j,r?t:null,!e.u),0<e.P&&(e.O=new we(v(e.Y,e,e.g),e.P)),t=e.V,r=e.g,n=e.ba,"readystatechange");Array.isArray(i)||(i&&(_e[0]=i.toString()),i=_e);for(let d=0;d<i.length;d++){var s=le(r,i[d],n||t.handleEvent,!1,t.h||t);if(!s)break;t.g[s.key]=s}t=e.J?te(e.J):{},e.u?(e.v||(e.v="POST"),t["Content-Type"]="application/x-www-form-urlencoded",e.g.ea(e.B,e.v,e.u,t)):(e.v="GET",e.g.ea(e.B,e.v,null,t)),ke(),a=e.i,o=e.v,u=e.B,l=e.l,h=e.S,c=e.u,a.info(function(){if(a.g)if(c){var t="",r=c.split("&");for(let e=0;e<r.length;e++){var n,i,s=r[e].split("=");1<s.length&&(n=s[0],s=s[1],t=2<=(i=n.split("_")).length&&"type"==i[1]?t+(n+"=")+s+"&":t+(n+"=redacted&"))}}else t=null;else t=c;return"XMLHTTP REQ ("+l+") [attempt "+h+"]: "+o+"\n"+u+"\n"+t})}function He(e){return e.g&&"GET"==e.v&&2!=e.M&&e.j.Aa}function Ke(e){e.T=Date.now()+e.H,$e(e,e.H)}function $e(e,t){if(null!=e.D)throw Error("WatchDog timer not null");e.D=y(v(e.aa,e),t)}function Qe(e){e.D&&(N.clearTimeout(e.D),e.D=null)}function k(e){0==e.j.I||e.K||Xt(e.j,e)}function L(e){Qe(e);var t=e.O;t&&"function"==typeof t.dispose&&t.dispose(),e.O=null,Ee(e.V),e.g&&(t=e.g,e.g=null,t.abort(),t.dispose())}function Ye(e,t){try{var r=e.j;if(0!=r.I&&(r.g==e||et(r.h,e)))if(!e.L&&et(r.h,e)&&3==r.I){try{var n=r.Ba.g.parse(t)}catch(e){n=null}if(Array.isArray(n)&&3==n.length){var i=n;if(0==i[0]){e:if(!r.v){if(r.g){if(!(r.g.F+3e3<e.F))break e;Wt(r),Bt(r)}$t(r),O(18)}}else r.xa=i[1],0<r.xa-r.K&&i[2]<37500&&r.F&&0==r.A&&!r.C&&(r.C=y(v(r.Va,r),6e3));Ze(r.h)<=1&&r.ta&&(r.ta=void 0)}else A(r,11)}else if(!e.L&&r.g!=e||Wt(r),!D(t))for(i=r.Ba.g.parse(t),t=0;t<i.length;t++){var s,a,o,u,l,h,c,d,p,f,g=i[t],m=g[0];m<=r.K||(r.K=m,g=g[1],2==r.I?"c"==g[0]?(r.M=g[1],r.ba=g[2],null!=(s=g[3])&&(r.ka=s,r.j.info("VER="+r.ka)),null!=(a=g[4])&&(r.za=a,r.j.info("SVER="+r.za)),null!=(o=g[5])&&"number"==typeof o&&0<o&&(n=1.5*o,r.O=n,r.j.info("backChannelRequestTimeoutMs_="+n)),n=r,(u=e.g)&&(!(l=u.g?u.g.getResponseHeader("X-Client-Wire-Protocol"):null)||(h=n.h).g||-1==l.indexOf("spdy")&&-1==l.indexOf("quic")&&-1==l.indexOf("h2")||(h.j=h.l,h.g=new Set,h.h&&(tt(h,h.h),h.h=null)),n.G)&&(c=u.g?u.g.getResponseHeader("X-HTTP-Session-Id"):null)&&(n.wa=c,E(n.J,n.G,c)),r.I=3,r.l&&r.l.ra(),r.aa&&(r.T=Date.now()-e.F,r.j.info("Handshake RTT: "+r.T+"ms")),d=e,(n=r).na=er(n,n.L?n.ba:null,n.W),d.L?(rt(n.h,d),p=d,(f=n.O)&&(p.H=f),p.D&&(Qe(p),Ke(p)),n.g=d):Kt(n),0<r.i.length&&Gt(r)):"stop"!=g[0]&&"close"!=g[0]||A(r,7):3==r.I&&("stop"==g[0]||"close"==g[0]?"stop"==g[0]?A(r,7):Ut(r):"noop"!=g[0]&&r.l&&r.l.qa(g),r.A=0))}ke()}catch(e){}}g.prototype.ba=function(e){e=e.target;var t=this.O;t&&3==P(e)?t.j():this.Y(e)},g.prototype.Y=function(e){try{if(e==this.g)e:{var t=P(this.g),r=this.g.ya();this.g.ca();if(!(t<3)&&(3!=t||this.g&&(this.h.h||this.g.la()||Mt(this.g)))){this.K||4!=t||7==r||ke(),Qe(this);var n,i,s=this.g.ca(),a=(this.X=s,(e=>{if(!He(e))return e.g.la();var t=Mt(e.g);if(""===t)return"";let r="",n=t.length,i=4==P(e.g);if(!e.h.i){if("undefined"==typeof TextDecoder)return L(e),k(e),"";e.h.i=new N.TextDecoder}for(let s=0;s<n;s++)e.h.h=!0,r+=e.h.i.decode(t[s],{stream:!(i&&s==n-1)});return t.length=0,e.h.g+=r,e.C=0,e.h.g})(this));if(this.o=200==s,T=this.i,b=this.v,S=this.B,I=this.l,A=this.S,C=t,x=s,T.info(function(){return"XMLHTTP RESP ("+I+") [ attempt "+A+"]: "+b+"\n"+S+"\n"+C+" "+x}),this.o){if(this.U&&!this.L){t:{if(this.g){var o,u=this.g;if((o=u.g?u.g.getResponseHeader("X-HTTP-Initial-Response"):null)&&!D(o)){var l=o;break t}}l=null}if(!(e=l)){this.o=!1,this.m=3,O(12),L(this),k(this);break e}R(this.i,this.l,e,"Initial handshake response via X-HTTP-Initial-Response"),this.L=!0,Ye(this,e)}if(this.R){for(e=!0;!this.K&&this.C<a.length;){if(w=a,E=_=void 0,_=(y=this).C,(n=-1==(E=w.indexOf("\n",_))?Ge:(_=Number(w.substring(_,E)),isNaN(_)?qe:(E+=1)+_>w.length?Ge:(w=w.slice(E,E+_),y.C=E+_,w)))==Ge){4==t&&(this.m=4,O(14),e=!1),R(this.i,this.l,null,"[Incomplete Response]");break}if(n==qe){this.m=4,O(15),R(this.i,this.l,a,"[Invalid Chunk]"),e=!1;break}R(this.i,this.l,n,null),Ye(this,n)}He(this)&&0!=this.C&&(this.h.g=this.h.g.slice(this.C),this.C=0),4!=t||0!=a.length||this.h.h||(this.m=1,O(16),e=!1),this.o=this.o&&e,e?0<a.length&&!this.W&&(this.W=!0,(i=this.j).g==this)&&i.aa&&!i.P&&(i.j.info("Great, no buffering proxy detected. Bytes received: "+a.length),Qt(i),i.P=!0,O(11)):(R(this.i,this.l,a,"[Invalid Chunked Response]"),L(this),k(this))}else R(this.i,this.l,a,null),Ye(this,a);4==t&&L(this),this.o&&!this.K&&(4==t?Xt(this.j,this):(this.o=!1,Ke(this)))}else{{var h=this.g;var c,d,p,f={};h=(h.g&&2<=P(h)&&h.g.getAllResponseHeaders()||"").split("\r\n");for(let e=0;e<h.length;e++)D(h[e])||(c=(e=>{for(var t=1,r=(e=e.split(":"),[]);0<t&&e.length;)r.push(e.shift()),t--;return e.length&&r.push(e.join(":")),r})(h[e]),d=c[0],"string"==typeof(c=c[1])&&(c=c.trim(),p=f[d]||[],(f[d]=p).push(c)));var g,m=f,v=function(e){return e.join(", ")};for(g in m)v.call(void 0,m[g],g,m)}400==s&&0<a.indexOf("Unknown SID")?(this.m=3,O(12)):(this.m=0,O(13)),L(this),k(this)}}}}catch(e){}var y,w,_,E,T,b,S,I,A,C,x},g.prototype.cancel=function(){this.K=!0,L(this)},g.prototype.aa=function(){this.D=null;var e,t,r=Date.now();0<=r-this.T?(e=this.i,t=this.B,e.info(function(){return"TIMEOUT: "+t}),2!=this.M&&(ke(),O(17)),L(this),this.m=2,k(this)):$e(this,this.T-r)};var We=class{constructor(e,t){this.g=e,this.map=t}};function Xe(e){this.l=e||10,e=N.PerformanceNavigationTiming?0<(e=N.performance.getEntriesByType("navigation")).length&&("hq"==e[0].nextHopProtocol||"h2"==e[0].nextHopProtocol):!!(N.chrome&&N.chrome.loadTimes&&N.chrome.loadTimes()&&N.chrome.loadTimes().wasFetchedViaSpdy),this.j=e?this.l:1,this.g=null,1<this.j&&(this.g=new Set),this.h=null,this.i=[]}function Je(e){return e.h||e.g&&e.g.size>=e.j}function Ze(e){return e.h?1:e.g?e.g.size:0}function et(e,t){return e.h?e.h==t:e.g&&e.g.has(t)}function tt(e,t){e.g?e.g.add(t):e.h=t}function rt(e,t){e.h&&e.h==t?e.h=null:e.g&&e.g.has(t)&&e.g.delete(t)}function nt(t){if(null!=t.h)return t.i.concat(t.h.G);if(null==t.g||0===t.g.size)return j(t.i);{let e=t.i;for(var r of t.g.values())e=e.concat(r.G);return e}}Xe.prototype.cancel=function(){if(this.i=nt(this),this.h)this.h.cancel(),this.h=null;else if(this.g&&0!==this.g.size){for(var e of this.g.values())e.cancel();this.g.clear()}};var it=RegExp("^(?:([^:/?#.]+):)?(?://(?:([^\\\\/?#]*)@)?([^\\\\/?#]*?)(?::([0-9]+))?(?=[\\\\/?#]|$))?([^?#]+)?(?:\\?([^#]*))?(?:#([\\s\\S]*))?$");function m(e){this.g=this.o=this.j="",this.u=null,this.m=this.h="",this.l=!1;let t;e instanceof m?(this.l=e.l,_(this,e.j),this.o=e.o,this.g=e.g,st(this,e.u),this.h=e.h,at(this,Et(e.i)),this.m=e.m):e&&(t=String(e).match(it))?(this.l=!1,_(this,t[1]||"",!0),this.o=ut(t[2]||""),this.g=ut(t[3]||"",!0),st(this,t[4]),this.h=ut(t[5]||"",!0),at(this,t[6]||"",!0),this.m=ut(t[7]||"")):(this.l=!1,this.i=new mt(null,this.l))}function w(e){return new m(e)}function _(e,t,r){e.j=r?ut(t,!0):t,e.j&&(e.j=e.j.replace(/:$/,""))}function st(e,t){if(t){if(t=Number(t),isNaN(t)||t<0)throw Error("Bad port number "+t);e.u=t}else e.u=null}function at(e,t,r){var n,i;t instanceof mt?(e.i=t,n=e.i,(i=e.l)&&!n.j&&(T(n),n.i=null,n.g.forEach(function(e,t){var r=t.toLowerCase();t!=r&&(vt(this,t),_t(this,r,e))},n)),n.j=i):(r||(t=lt(t,ft)),e.i=new mt(t,e.l))}function E(e,t,r){e.i.set(t,r)}function ot(e){return E(e,"zx",Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^Date.now()).toString(36)),e}function ut(e,t){return e?t?decodeURI(e.replace(/%25/g,"%2525")):decodeURIComponent(e):""}function lt(e,t,r){return"string"==typeof e?(e=encodeURI(e).replace(t,ht),e=r?e.replace(/%25([0-9a-fA-F]{2})/g,"%$1"):e):null}function ht(e){return"%"+((e=e.charCodeAt(0))>>4&15).toString(16)+(15&e).toString(16)}m.prototype.toString=function(){var e=[],t=this.j,r=(t&&e.push(lt(t,ct,!0),":"),this.g);return!r&&"file"!=t||(e.push("//"),(t=this.o)&&e.push(lt(t,ct,!0),"@"),e.push(f(r).replace(/%25([0-9a-fA-F]{2})/g,"%$1")),null==(r=this.u))||e.push(":",String(r)),(r=this.h)&&(this.g&&"/"!=r.charAt(0)&&e.push("/"),e.push(lt(r,"/"==r.charAt(0)?pt:dt,!0))),(r=this.i.toString())&&e.push("?",r),(r=this.m)&&e.push("#",lt(r,gt)),e.join("")},m.prototype.resolve=function(e){var t=w(this);let r=!!e.j;r?_(t,e.j):r=!!e.o,r?t.o=e.o:r=!!e.g,r?t.g=e.g:r=null!=e.u;var n=e.h;if(r)st(t,e.u);else if(r=!!e.h)if("/"!=n.charAt(0)&&(this.g&&!this.h?n="/"+n:-1!=(i=t.h.lastIndexOf("/"))&&(n=t.h.slice(0,i+1)+n)),".."==(i=n)||"."==i)n="";else if(-1!=i.indexOf("./")||-1!=i.indexOf("/.")){var n=0==i.lastIndexOf("/",0),i=i.split("/"),s=[];for(let e=0;e<i.length;){var a=i[e++];"."==a?n&&e==i.length&&s.push(""):".."==a?((1<s.length||1==s.length&&""!=s[0])&&s.pop(),n&&e==i.length&&s.push("")):(s.push(a),n=!0)}n=s.join("/")}else n=i;return r?t.h=n:r=""!==e.i.toString(),r?at(t,Et(e.i)):r=!!e.m,r&&(t.m=e.m),t};var ct=/[#\/\?@]/g,dt=/[#\?:]/g,pt=/[#\?]/g,ft=/[#\?@]/g,gt=/#/g;function mt(e,t){this.h=this.g=null,this.i=e||null,this.j=!!t}function T(r){if(!r.g&&(r.g=new Map,r.h=0,r.i)){var n=r.i,i=function(e,t){r.add(decodeURIComponent(e.replace(/\+/g," ")),t)};if(n){n=n.split("&");for(let r=0;r<n.length;r++){var s=n[r].indexOf("=");let e,t=null;0<=s?(e=n[r].substring(0,s),t=n[r].substring(s+1)):e=n[r],i(e,t?decodeURIComponent(t.replace(/\+/g," ")):"")}}}}function vt(e,t){T(e),t=b(e,t),e.g.has(t)&&(e.i=null,e.h-=e.g.get(t).length,e.g.delete(t))}function yt(e,t){return T(e),t=b(e,t),e.g.has(t)}function wt(e,t){T(e);let r=[];if("string"==typeof t)yt(e,t)&&(r=r.concat(e.g.get(b(e,t))));else for(e=Array.from(e.g.values()),t=0;t<e.length;t++)r=r.concat(e[t]);return r}function _t(e,t,r){vt(e,t),0<r.length&&(e.i=null,e.g.set(b(e,t),j(r)),e.h+=r.length)}function Et(e){var t=new mt;return t.i=e.i,e.g&&(t.g=new Map(e.g),t.h=e.h),t}function b(e,t){return t=String(t),t=e.j?t.toLowerCase():t}function S(e,t,r,n,i){try{i&&(i.onload=null,i.onerror=null,i.onabort=null,i.ontimeout=null),n(r)}catch(e){}}function Tt(){this.g=new Se}function bt(e){this.i=e.Sb||null,this.h=e.ab||!1}function St(e,t){a.call(this),this.H=e,this.o=t,this.m=void 0,this.status=this.readyState=0,this.responseType=this.responseText=this.response=this.statusText="",this.onreadystatechange=null,this.A=new Headers,this.h=null,this.F="GET",this.D="",this.g=!1,this.B=this.j=this.l=null,this.v=new AbortController}function It(e){e.j.read().then(e.Ma.bind(e)).catch(e.ga.bind(e))}function At(e){e.readyState=4,e.l=null,e.j=null,e.B=null,Ct(e)}function Ct(e){e.onreadystatechange&&e.onreadystatechange.call(e)}function xt(e){let r="";return ee(e,function(e,t){r=(r=r+t+":")+e+"\r\n"}),r}function Nt(e,t,r){e:{for(n in r){var n=!1;break e}n=!0}n||(r=xt(r),"string"==typeof e?null!=r&&f(r):E(e,t,r))}function I(e){a.call(this),this.headers=new Map,this.L=e||null,this.h=!1,this.g=null,this.D="",this.o=0,this.l="",this.j=this.B=this.v=this.A=!1,this.m=null,this.F="",this.H=!1}(e=mt.prototype).add=function(e,t){T(this),this.i=null,e=b(this,e);let r=this.g.get(e);return r||this.g.set(e,r=[]),r.push(t),this.h+=1,this},e.forEach=function(r,n){T(this),this.g.forEach(function(e,t){e.forEach(function(e){r.call(n,e,t,this)},this)},this)},e.set=function(e,t){return T(this),this.i=null,yt(this,e=b(this,e))&&(this.h-=this.g.get(e).length),this.g.set(e,[t]),this.h+=1,this},e.get=function(e,t){return e&&0<(e=wt(this,e)).length?String(e[0]):t},e.toString=function(){if(this.i)return this.i;if(!this.g)return"";var r=[],e=Array.from(this.g.keys());for(let s=0;s<e.length;s++){var n=f(i=e[s]),i=wt(this,i);for(let t=0;t<i.length;t++){let e=n;""!==i[t]&&(e+="="+f(i[t])),r.push(e)}}return this.i=r.join("&")},t(bt,Ie),bt.prototype.g=function(){return new St(this.i,this.h)},t(St,a),(e=St.prototype).open=function(e,t){if(0!=this.readyState)throw this.abort(),Error("Error reopening a connection");this.F=e,this.D=t,this.readyState=1,Ct(this)},e.send=function(e){if(1!=this.readyState)throw this.abort(),Error("need to call open() first. ");if(this.v.signal.aborted)throw this.abort(),Error("Request was aborted.");this.g=!0;var t={headers:this.A,method:this.F,credentials:this.m,cache:void 0,signal:this.v.signal};e&&(t.body=e),(this.H||N).fetch(new Request(this.D,t)).then(this.Pa.bind(this),this.ga.bind(this))},e.abort=function(){this.response=this.responseText="",this.A=new Headers,this.status=0,this.v.abort(),this.j&&this.j.cancel("Request was aborted.").catch(()=>{}),1<=this.readyState&&this.g&&4!=this.readyState&&(this.g=!1,At(this)),this.readyState=0},e.Pa=function(e){if(this.g&&(this.l=e,this.h||(this.status=this.l.status,this.statusText=this.l.statusText,this.h=e.headers,this.readyState=2,Ct(this)),this.g)&&(this.readyState=3,Ct(this),this.g))if("arraybuffer"===this.responseType)e.arrayBuffer().then(this.Na.bind(this),this.ga.bind(this));else if(void 0!==N.ReadableStream&&"body"in e){if(this.j=e.body.getReader(),this.o){if(this.responseType)throw Error('responseType must be empty for "streamBinaryChunks" mode responses.');this.response=[]}else this.response=this.responseText="",this.B=new TextDecoder;It(this)}else e.text().then(this.Oa.bind(this),this.ga.bind(this))},e.Ma=function(e){var t;this.g&&(this.o&&e.value?this.response.push(e.value):!this.o&&(t=e.value||new Uint8Array(0),t=this.B.decode(t,{stream:!e.done}))&&(this.response=this.responseText+=t),(e.done?At:Ct)(this),3==this.readyState)&&It(this)},e.Oa=function(e){this.g&&(this.response=this.responseText=e,At(this))},e.Na=function(e){this.g&&(this.response=e,At(this))},e.ga=function(){this.g&&At(this)},e.setRequestHeader=function(e,t){this.A.append(e,t)},e.getResponseHeader=function(e){return this.h&&this.h.get(e.toLowerCase())||""},e.getAllResponseHeaders=function(){if(!this.h)return"";for(var e=[],t=this.h.entries(),r=t.next();!r.done;)r=r.value,e.push(r[0]+": "+r[1]),r=t.next();return e.join("\r\n")},Object.defineProperty(St.prototype,"withCredentials",{get:function(){return"include"===this.m},set:function(e){this.m=e?"include":"same-origin"}}),t(I,a);var Dt=/^https?$/i,Ot=["POST","PUT"];function Rt(e,t){e.h=!1,e.g&&(e.j=!0,e.g.abort(),e.j=!1),e.l=t,e.o=5,kt(e),Pt(e)}function kt(e){e.A||(e.A=!0,l(e,"complete"),l(e,"error"))}function Lt(t){if(t.h&&void 0!==U)if(t.v&&4==P(t))setTimeout(t.Ca.bind(t),0);else if(l(t,"readystatechange"),4==P(t)){t.h=!1;try{var e,r,n=t.ca();switch(n){case 200:case 201:case 202:case 204:case 206:case 304:case 1223:var i=!0;break;default:i=!1}if(!(e=i)){if(r=0===n){let e=String(t.D).match(it)[1]||null;!e&&N.self&&N.self.location&&(e=N.self.location.protocol.slice(0,-1)),r=!Dt.test(e?e.toLowerCase():"")}e=r}if(e)l(t,"complete"),l(t,"success");else{t.o=6;try{var s=2<P(t)?t.g.statusText:""}catch(e){s=""}t.l=s+" ["+t.ca()+"]",kt(t)}}finally{Pt(t)}}}function Pt(e,t){if(e.g){e.m&&(clearTimeout(e.m),e.m=null);var r=e.g;e.g=null,t||l(e,"ready");try{r.onreadystatechange=null}catch(e){}}}function P(e){return e.g?e.g.readyState:0}function Mt(e){try{if(e.g){if("response"in e.g)return e.g.response;switch(e.F){case"":case"text":return e.g.responseText;case"arraybuffer":if("mozResponseArrayBuffer"in e.g)return e.g.mozResponseArrayBuffer}}return null}catch(e){return null}}function Vt(e,t,r){return r&&r.internalChannelParams&&r.internalChannelParams[e]||t}function Ft(e){this.za=0,this.i=[],this.j=new p,this.ba=this.na=this.J=this.W=this.g=this.wa=this.G=this.H=this.u=this.U=this.o=null,this.Ya=this.V=0,this.Sa=Vt("failFast",!1,e),this.F=this.C=this.v=this.m=this.l=null,this.X=!0,this.xa=this.K=-1,this.Y=this.A=this.D=0,this.Qa=Vt("baseRetryDelayMs",5e3,e),this.Za=Vt("retryDelaySeedMs",1e4,e),this.Ta=Vt("forwardChannelMaxRetries",2,e),this.va=Vt("forwardChannelRequestTimeoutMs",2e4,e),this.ma=e&&e.xmlHttpFactory||void 0,this.Ua=e&&e.Rb||void 0,this.Aa=e&&e.useFetchStreams||!1,this.O=void 0,this.L=e&&e.supportsCrossDomainXhr||!1,this.M="",this.h=new Xe(e&&e.concurrentRequestLimit),this.Ba=new Tt,this.S=e&&e.fastHandshake||!1,this.R=e&&e.encodeInitMessageHeaders||!1,this.S&&this.R&&(this.R=!1),this.Ra=e&&e.Pb||!1,e&&e.ua&&this.j.ua(),e&&e.forceLongPolling&&(this.X=!1),this.aa=!this.S&&this.X&&e&&e.detectBufferingProxy||!1,this.ia=void 0,e&&e.longPollingTimeout&&0<e.longPollingTimeout&&(this.ia=e.longPollingTimeout),this.ta=void 0,this.T=0,this.P=!1,this.ja=this.B=null}function Ut(e){if(qt(e),3==e.I){var t=e.V++,r=w(e.J);if(E(r,"SID",e.M),E(r,"RID",t),E(r,"TYPE","terminate"),zt(e,r),(t=new g(e,e.j,t)).M=2,t.A=ot(w(r)),r=!1,N.navigator&&N.navigator.sendBeacon)try{r=N.navigator.sendBeacon(t.A.toString(),"")}catch(e){}!r&&N.Image&&((new Image).src=t.A,r=!0),r||(t.g=tr(t.j,null),t.g.ea(t.A)),t.F=Date.now(),Ke(t)}Zt(e)}function Bt(e){e.g&&(Qt(e),e.g.cancel(),e.g=null)}function qt(e){Bt(e),e.v&&(N.clearTimeout(e.v),e.v=null),Wt(e),e.h.cancel(),e.m&&("number"==typeof e.m&&N.clearTimeout(e.m),e.m=null)}function Gt(e){var t;Je(e.h)||e.m||(e.m=!0,t=e.Ea,r||Q(),n||(r(),n=!0),$.add(t,e),e.D=0)}function jt(e,t){var r=t?t.l:e.V++,n=w(e.J);E(n,"SID",e.M),E(n,"RID",r),E(n,"AID",e.K),zt(e,n),e.u&&e.o&&Nt(n,e.u,e.o),r=new g(e,e.j,r,e.D+1),null===e.u&&(r.J=e.o),t&&(e.i=t.G.concat(e.i)),t=Ht(e,r,1e3),r.H=Math.round(.5*e.va)+Math.round(.5*e.va*Math.random()),tt(e.h,r),je(r,n,t)}function zt(e,r){e.H&&ee(e.H,function(e,t){E(r,t,e)}),e.l&&ee({},function(e,t){E(r,t,e)})}function Ht(e,t,i){i=Math.min(e.i.length,i);var s=e.l?v(e.l.Ka,e.l,e):null;e:{let r=e.i,n=-1;for(;;){var a=["count="+i];-1==n?0<i?(n=r[0].g,a.push("ofs="+n)):n=0:a.push("ofs="+n);let e=!0;for(let t=0;t<i;t++){var o=r[t].g,u=r[t].map;if((o-=n)<0)n=Math.max(0,r[t].g-100),e=!1;else try{o="req"+o+"_"||"";try{var l,h,c=u instanceof Map?u:Object.entries(u);for([l,h]of c){let e=h;d(h)&&(e=Te(h)),a.push(o+l+"="+encodeURIComponent(e))}}catch(e){throw a.push(o+"type="+encodeURIComponent("_badmap")),e}}catch(e){s&&s(u)}}if(e){c=a.join("&");break e}}c=void 0}return e=e.i.splice(0,i),t.G=e,c}function Kt(e){var t;e.g||e.v||(e.Y=1,t=e.Da,r||Q(),n||(r(),n=!0),$.add(t,e),e.A=0)}function $t(e){return!(e.g||e.v||3<=e.A)&&(e.Y++,e.v=y(v(e.Da,e),Jt(e,e.A)),e.A++,1)}function Qt(e){null!=e.B&&(N.clearTimeout(e.B),e.B=null)}function Yt(e){e.g=new g(e,e.j,"rpc",e.Y),null===e.u&&(e.g.J=e.o),e.g.P=0;var t=w(e.na),r=(E(t,"RID","rpc"),E(t,"SID",e.M),E(t,"AID",e.K),E(t,"CI",e.F?"0":"1"),!e.F&&e.ia&&E(t,"TO",e.ia),E(t,"TYPE","xmlhttp"),zt(e,t),e.u&&e.o&&Nt(t,e.u,e.o),e.O&&(e.g.H=e.O),e.g);e=e.ba,r.M=1,r.A=ot(w(t)),r.u=null,r.R=!0,ze(r,e)}function Wt(e){null!=e.C&&(N.clearTimeout(e.C),e.C=null)}function Xt(e,t){var r,n,i,s=null;if(e.g==t){Wt(e),Qt(e),e.g=null;var a=2}else{if(!et(e.h,t))return;s=t.G,rt(e.h,t),a=1}if(0!=e.I)if(t.o)(1==a?(s=t.u?t.u.length:0,t=Date.now()-t.F,r=e.D,l(a=Oe(),new Pe(a,s)),Gt):Kt)(e);else if(3==(r=t.m)||0==r&&0<t.X||(1!=a||(i=t,Ze((n=e).h)>=n.h.j-(n.m?1:0))||(n.m?(n.i=i.G.concat(n.i),0):1==n.I||2==n.I||n.D>=(n.Sa?0:n.Ta)||(n.m=y(v(n.Ea,n,i),Jt(n,n.D)),n.D++,0)))&&(2!=a||!$t(e)))switch(s&&0<s.length&&(t=e.h,t.i=t.i.concat(s)),r){case 1:A(e,5);break;case 4:A(e,10);break;case 3:A(e,6);break;default:A(e,2)}}function Jt(e,t){let r=e.Qa+Math.floor(Math.random()*e.Za);return e.isActive()||(r*=2),r*t}function A(e,t){var r,n,i;e.j.info("Error code "+t),2==t?(r=v(e.bb,e),n=!(i=e.Ua),i=new m(i||"//www.google.com/images/cleardot.gif"),N.location&&"http"==N.location.protocol||_(i,"https"),ot(i),(n?(t,r)=>{var n=new p;if(N.Image){let e=new Image;e.onload=q(S,n,"TestLoadImage: loaded",!0,r,e),e.onerror=q(S,n,"TestLoadImage: error",!1,r,e),e.onabort=q(S,n,"TestLoadImage: abort",!1,r,e),e.ontimeout=q(S,n,"TestLoadImage: timeout",!1,r,e),N.setTimeout(function(){e.ontimeout&&e.ontimeout()},1e4),e.src=t}else r(!1)}:(e,t)=>{let r=new p,n=new AbortController,i=setTimeout(()=>{n.abort(),S(r,0,!1,t)},1e4);fetch(e,{signal:n.signal}).then(e=>{clearTimeout(i),e.ok?S(r,0,!0,t):S(r,0,!1,t)}).catch(()=>{clearTimeout(i),S(r,0,!1,t)})})(i.toString(),r)):O(2),e.I=0,e.l&&e.l.pa(t),Zt(e),qt(e)}function Zt(e){var t;e.I=0,e.ja=[],e.l&&(0==(t=nt(e.h)).length&&0==e.i.length||(z(e.ja,t),z(e.ja,e.i),e.h.i.length=0,j(e.i),e.i.length=0),e.l.oa())}function er(e,t,r){var n,i,s=r instanceof m?w(r):new m(r);return""!=s.g?(t&&(s.g=t+"."+s.g),st(s,s.u)):(s=(n=N.location).protocol,t=t?t+"."+n.hostname:n.hostname,n=+n.port,i=new m(null),s&&_(i,s),t&&(i.g=t),n&&st(i,n),r&&(i.h=r),s=i),r=e.G,t=e.wa,r&&t&&E(s,r,t),E(s,"VER",e.ka),zt(e,s),s}function tr(e,t,r){if(t&&!e.L)throw Error("Can't create secondary domain capable XhrIo object.");return(t=e.Aa&&!e.ma?new I(new bt({ab:r})):new I(e.ma)).Fa(e.L),t}function rr(){}function nr(){}function C(e,t){a.call(this),this.g=new Ft(t),this.l=e,this.h=t&&t.messageUrlParams||null,e=t&&t.messageHeaders||null,t&&t.clientProtocolHeaderRequired&&(e?e["X-Client-Protocol"]="webchannel":e={"X-Client-Protocol":"webchannel"}),this.g.o=e,e=t&&t.initMessageHeaders||null,t&&t.messageContentType&&(e?e["X-WebChannel-Content-Type"]=t.messageContentType:e={"X-WebChannel-Content-Type":t.messageContentType}),t&&t.sa&&(e?e["X-WebChannel-Client-Profile"]=t.sa:e={"X-WebChannel-Client-Profile":t.sa}),this.g.U=e,(e=t&&t.Qb)&&!D(e)&&(this.g.u=e),this.A=t&&t.supportsCrossDomainXhr||!1,this.v=t&&t.sendRawJson||!1,(t=t&&t.httpSessionIdParam)&&!D(t)&&(this.g.G=t,null!==(e=this.h))&&t in e&&t in(e=this.h)&&delete e[t],this.j=new x(this)}function ir(e){xe.call(this),e.__headers__&&(this.headers=e.__headers__,this.statusCode=e.__status__,delete e.__headers__,delete e.__status__);var t=e.__sm__;if(t){e:{for(var r in t){e=r;break e}e=void 0}(this.i=e)&&(e=this.i,t=null!==t&&e in t?t[e]:void 0),this.data=t}else this.data=e}function sr(){Ne.call(this),this.status=1}function x(e){this.g=e}(e=I.prototype).Fa=function(e){this.H=e},e.ea=function(e,t,r,n){if(this.g)throw Error("[goog.net.XhrIo] Object is active with another request="+this.D+"; newUri="+e);t=t?t.toUpperCase():"GET",this.D=e,this.l="",this.o=0,this.A=!1,this.h=!0,this.g=(this.L||Be).g(),this.g.onreadystatechange=G(v(this.Ca,this));try{this.B=!0,this.g.open(t,String(e),!0),this.B=!1}catch(e){return void Rt(this,e)}if(e=r||"",r=new Map(this.headers),n)if(Object.getPrototypeOf(n)===Object.prototype)for(var i in n)r.set(i,n[i]);else{if("function"!=typeof n.keys||"function"!=typeof n.get)throw Error("Unknown input type for opt_headers: "+String(n));for(var s of n.keys())r.set(s,n.get(s))}n=Array.from(r.keys()).find(e=>"content-type"==e.toLowerCase()),i=N.FormData&&e instanceof N.FormData,0<=Array.prototype.indexOf.call(Ot,t,void 0)&&!n&&!i&&r.set("Content-Type","application/x-www-form-urlencoded;charset=utf-8");for(var[a,o]of r)this.g.setRequestHeader(a,o);this.F&&(this.g.responseType=this.F),"withCredentials"in this.g&&this.g.withCredentials!==this.H&&(this.g.withCredentials=this.H);try{this.m&&(clearTimeout(this.m),this.m=null),this.v=!0,this.g.send(e),this.v=!1}catch(e){Rt(this,e)}},e.abort=function(e){this.g&&this.h&&(this.h=!1,this.j=!0,this.g.abort(),this.j=!1,this.o=e||7,l(this,"complete"),l(this,"abort"),Pt(this))},e.N=function(){this.g&&(this.h&&(this.h=!1,this.j=!0,this.g.abort(),this.j=!1),Pt(this,!0)),I.Z.N.call(this)},e.Ca=function(){this.u||(this.B||this.v||this.j?Lt(this):this.Xa())},e.Xa=function(){Lt(this)},e.isActive=function(){return!!this.g},e.ca=function(){try{return 2<P(this)?this.g.status:-1}catch(e){return-1}},e.la=function(){try{return this.g?this.g.responseText:""}catch(e){return""}},e.La=function(e){var t;if(this.g)return t=this.g.responseText,e&&0==t.indexOf(e)&&(t=t.substring(e.length)),be(t)},e.ya=function(){return this.o},e.Ha=function(){return"string"==typeof this.l?this.l:String(this.l)},(e=Ft.prototype).ka=8,e.I=1,e.connect=function(e,t,r,n){O(0),this.W=e,this.H=t||{},r&&void 0!==n&&(this.H.OSID=r,this.H.OAID=n),this.F=this.X,this.J=er(this,null,this.W),Gt(this)},e.Ea=function(t){if(this.m)if(this.m=null,1==this.I){if(!t){this.V=Math.floor(1e5*Math.random()),t=this.V++;var r=new g(this,this.j,t);let e=this.o;if(this.U&&(e?ne(e=te(e),this.U):e=this.U),null!==this.u||this.R||(r.J=e,e=null),this.S)e:{for(var n=0,i=0;i<this.i.length;i++){var s=this.i[i];if("__data__"in s.map&&"string"==typeof(s=s.map.__data__)?s=s.length:s=void 0,void 0===s)break;if(4096<(n+=s)){n=i;break e}if(4096===n||i===this.i.length-1){n=i+1;break e}}n=1e3}else n=1e3;n=Ht(this,r,n),E(i=w(this.J),"RID",t),E(i,"CVER",22),this.G&&E(i,"X-HTTP-Session-Id",this.G),zt(this,i),e&&(this.R?n="headers="+f(xt(e))+"&"+n:this.u&&Nt(i,this.u,e)),tt(this.h,r),this.Ra&&E(i,"TYPE","init"),this.S?(E(i,"$req",n),E(i,"SID","null"),r.U=!0,je(r,i,null)):je(r,i,n),this.I=2}}else 3==this.I&&(t?jt(this,t):0==this.i.length||Je(this.h)||jt(this))},e.Da=function(){var e;this.v=null,Yt(this),this.aa&&!(this.P||null==this.g||this.T<=0)&&(e=4*this.T,this.j.info("BP detection timer enabled: "+e),this.B=y(v(this.Wa,this),e))},e.Wa=function(){this.B&&(this.B=null,this.j.info("BP detection timeout reached."),this.j.info("Buffering proxy detected and switch to long-polling!"),this.F=!1,this.P=!0,O(10),Bt(this),Yt(this))},e.Va=function(){null!=this.C&&(this.C=null,Bt(this),$t(this),O(19))},e.bb=function(e){e?(this.j.info("Successfully pinged google.com"),O(2)):(this.j.info("Failed to ping google.com"),O(1))},e.isActive=function(){return!!this.l&&this.l.isActive(this)},(e=rr.prototype).ra=function(){},e.qa=function(){},e.pa=function(){},e.oa=function(){},e.isActive=function(){return!0},e.Ka=function(){},nr.prototype.g=function(e,t){return new C(e,t)},t(C,a),C.prototype.m=function(){this.g.l=this.j,this.A&&(this.g.L=!0),this.g.connect(this.l,this.h||void 0)},C.prototype.close=function(){Ut(this.g)},C.prototype.o=function(e){var t,r=this.g;"string"==typeof e?((t={}).__data__=e,e=t):this.v&&((t={}).__data__=Te(e),e=t),r.i.push(new We(r.Ya++,e)),3==r.I&&Gt(r)},C.prototype.N=function(){this.g.l=null,delete this.j,Ut(this.g),delete this.g,C.Z.N.call(this)},t(ir,xe),t(sr,Ne),t(x,rr),x.prototype.ra=function(){l(this.g,"a")},x.prototype.qa=function(e){l(this.g,new ir(e))},x.prototype.pa=function(e){l(this.g,new sr)},x.prototype.oa=function(){l(this.g,"b")},nr.prototype.createWebChannel=nr.prototype.g,C.prototype.send=C.prototype.o,C.prototype.open=C.prototype.m,pr=function(){return new nr},dr=Oe,cr=c,hr={jb:0,mb:1,nb:2,Hb:3,Mb:4,Jb:5,Kb:6,Ib:7,Gb:8,Lb:9,PROXY:10,NOPROXY:11,Eb:12,Ab:13,Bb:14,zb:15,Cb:16,Db:17,fb:18,eb:19,gb:20},Me.NO_ERROR=0,Me.TIMEOUT=8,Me.HTTP_ERROR=6,lr=Me,Ve.COMPLETE="complete",ur=Ve,(Ae.EventType=Ce).OPEN="a",Ce.CLOSE="b",Ce.ERROR="c",Ce.MESSAGE="d",a.prototype.listen=a.prototype.J,or=Ae,I.prototype.listenOnce=I.prototype.K,I.prototype.getLastError=I.prototype.Ha,I.prototype.getLastErrorCode=I.prototype.ya,I.prototype.getStatus=I.prototype.ca,I.prototype.getResponseJson=I.prototype.La,I.prototype.getResponseText=I.prototype.la,I.prototype.send=I.prototype.ea,I.prototype.setWithCredentials=I.prototype.Fa,ar=I}).apply(void 0!==fr?fr:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});class b{static FOLD_CASE=1;static LITERAL=2;static CLASS_NL=4;static DOT_NL=8;static ONE_LINE=16;static NON_GREEDY=32;static PERL_X=64;static UNICODE_GROUPS=128;static WAS_DOLLAR=256;static MATCH_NL=b.CLASS_NL|b.DOT_NL;static PERL=b.CLASS_NL|b.ONE_LINE|b.PERL_X|b.UNICODE_GROUPS;static POSIX=0;static UNANCHORED=0;static ANCHOR_START=1;static ANCHOR_BOTH=2}class p{static CODES=new Map([["",7],["\b",8],["\t",9],["\n",10],["\v",11],["\f",12],["\r",13],[" ",32],['"',34],["$",36],["&",38],["(",40],[")",41],["*",42],["+",43],["-",45],[".",46],["0",48],["1",49],["2",50],["3",51],["4",52],["5",53],["6",54],["7",55],["8",56],["9",57],[":",58],["<",60],[">",62],["?",63],["A",65],["B",66],["C",67],["F",70],["P",80],["Q",81],["U",85],["Z",90],["[",91],["\\",92],["]",93],["^",94],["_",95],["a",97],["b",98],["f",102],["i",105],["m",109],["n",110],["r",114],["s",115],["t",116],["v",118],["x",120],["z",122],["{",123],["|",124],["}",125]]);static toUpperCase(e){var t,r=String.fromCodePoint(e).toUpperCase();return 1<r.length||1<(t=String.fromCodePoint(r.codePointAt(0)).toLowerCase()).length||t.codePointAt(0)!==e?e:r.codePointAt(0)}static toLowerCase(e){var t,r=String.fromCodePoint(e).toLowerCase();return 1<r.length||1<(t=String.fromCodePoint(r.codePointAt(0)).toUpperCase()).length||t.codePointAt(0)!==e?e:r.codePointAt(0)}}class r{static CASE_ORBIT=new Map([[75,107],[107,8490],[8490,75],[83,115],[115,383],[383,83],[181,924],[924,956],[956,181],[197,229],[229,8491],[8491,197],[452,453],[453,454],[454,452],[455,456],[456,457],[457,455],[458,459],[459,460],[460,458],[497,498],[498,499],[499,497],[837,921],[921,953],[953,8126],[8126,837],[914,946],[946,976],[976,914],[917,949],[949,1013],[1013,917],[920,952],[952,977],[977,1012],[1012,920],[922,954],[954,1008],[1008,922],[928,960],[960,982],[982,928],[929,961],[961,1009],[1009,929],[931,962],[962,963],[963,931],[934,966],[966,981],[981,934],[937,969],[969,8486],[8486,937],[1042,1074],[1074,7296],[7296,1042],[1044,1076],[1076,7297],[7297,1044],[1054,1086],[1086,7298],[7298,1054],[1057,1089],[1089,7299],[7299,1057],[1058,1090],[1090,7300],[7300,7301],[7301,1058],[1066,1098],[1098,7302],[7302,1066],[1122,1123],[1123,7303],[7303,1122],[7304,42570],[42570,42571],[42571,7304],[7776,7777],[7777,7835],[7835,7776],[223,7838],[7838,223],[8064,8072],[8072,8064],[8065,8073],[8073,8065],[8066,8074],[8074,8066],[8067,8075],[8075,8067],[8068,8076],[8076,8068],[8069,8077],[8077,8069],[8070,8078],[8078,8070],[8071,8079],[8079,8071],[8080,8088],[8088,8080],[8081,8089],[8089,8081],[8082,8090],[8090,8082],[8083,8091],[8091,8083],[8084,8092],[8092,8084],[8085,8093],[8093,8085],[8086,8094],[8094,8086],[8087,8095],[8095,8087],[8096,8104],[8104,8096],[8097,8105],[8105,8097],[8098,8106],[8106,8098],[8099,8107],[8107,8099],[8100,8108],[8108,8100],[8101,8109],[8109,8101],[8102,8110],[8110,8102],[8103,8111],[8111,8103],[8115,8124],[8124,8115],[8131,8140],[8140,8131],[912,8147],[8147,912],[944,8163],[8163,944],[8179,8188],[8188,8179],[64261,64262],[64262,64261],[66560,66600],[66600,66560],[66561,66601],[66601,66561],[66562,66602],[66602,66562],[66563,66603],[66603,66563],[66564,66604],[66604,66564],[66565,66605],[66605,66565],[66566,66606],[66606,66566],[66567,66607],[66607,66567],[66568,66608],[66608,66568],[66569,66609],[66609,66569],[66570,66610],[66610,66570],[66571,66611],[66611,66571],[66572,66612],[66612,66572],[66573,66613],[66613,66573],[66574,66614],[66614,66574],[66575,66615],[66615,66575],[66576,66616],[66616,66576],[66577,66617],[66617,66577],[66578,66618],[66618,66578],[66579,66619],[66619,66579],[66580,66620],[66620,66580],[66581,66621],[66621,66581],[66582,66622],[66622,66582],[66583,66623],[66623,66583],[66584,66624],[66624,66584],[66585,66625],[66625,66585],[66586,66626],[66626,66586],[66587,66627],[66627,66587],[66588,66628],[66628,66588],[66589,66629],[66629,66589],[66590,66630],[66630,66590],[66591,66631],[66631,66591],[66592,66632],[66632,66592],[66593,66633],[66633,66593],[66594,66634],[66634,66594],[66595,66635],[66635,66595],[66596,66636],[66636,66596],[66597,66637],[66637,66597],[66598,66638],[66638,66598],[66599,66639],[66639,66599],[66736,66776],[66776,66736],[66737,66777],[66777,66737],[66738,66778],[66778,66738],[66739,66779],[66779,66739],[66740,66780],[66780,66740],[66741,66781],[66781,66741],[66742,66782],[66782,66742],[66743,66783],[66783,66743],[66744,66784],[66784,66744],[66745,66785],[66785,66745],[66746,66786],[66786,66746],[66747,66787],[66787,66747],[66748,66788],[66788,66748],[66749,66789],[66789,66749],[66750,66790],[66790,66750],[66751,66791],[66791,66751],[66752,66792],[66792,66752],[66753,66793],[66793,66753],[66754,66794],[66794,66754],[66755,66795],[66795,66755],[66756,66796],[66796,66756],[66757,66797],[66797,66757],[66758,66798],[66798,66758],[66759,66799],[66799,66759],[66760,66800],[66800,66760],[66761,66801],[66801,66761],[66762,66802],[66802,66762],[66763,66803],[66803,66763],[66764,66804],[66804,66764],[66765,66805],[66805,66765],[66766,66806],[66806,66766],[66767,66807],[66807,66767],[66768,66808],[66808,66768],[66769,66809],[66809,66769],[66770,66810],[66810,66770],[66771,66811],[66811,66771],[66928,66967],[66967,66928],[66929,66968],[66968,66929],[66930,66969],[66969,66930],[66931,66970],[66970,66931],[66932,66971],[66971,66932],[66933,66972],[66972,66933],[66934,66973],[66973,66934],[66935,66974],[66974,66935],[66936,66975],[66975,66936],[66937,66976],[66976,66937],[66938,66977],[66977,66938],[66940,66979],[66979,66940],[66941,66980],[66980,66941],[66942,66981],[66981,66942],[66943,66982],[66982,66943],[66944,66983],[66983,66944],[66945,66984],[66984,66945],[66946,66985],[66985,66946],[66947,66986],[66986,66947],[66948,66987],[66987,66948],[66949,66988],[66988,66949],[66950,66989],[66989,66950],[66951,66990],[66990,66951],[66952,66991],[66991,66952],[66953,66992],[66992,66953],[66954,66993],[66993,66954],[66956,66995],[66995,66956],[66957,66996],[66996,66957],[66958,66997],[66997,66958],[66959,66998],[66998,66959],[66960,66999],[66999,66960],[66961,67e3],[67e3,66961],[66962,67001],[67001,66962],[66964,67003],[67003,66964],[66965,67004],[67004,66965],[68736,68800],[68800,68736],[68737,68801],[68801,68737],[68738,68802],[68802,68738],[68739,68803],[68803,68739],[68740,68804],[68804,68740],[68741,68805],[68805,68741],[68742,68806],[68806,68742],[68743,68807],[68807,68743],[68744,68808],[68808,68744],[68745,68809],[68809,68745],[68746,68810],[68810,68746],[68747,68811],[68811,68747],[68748,68812],[68812,68748],[68749,68813],[68813,68749],[68750,68814],[68814,68750],[68751,68815],[68815,68751],[68752,68816],[68816,68752],[68753,68817],[68817,68753],[68754,68818],[68818,68754],[68755,68819],[68819,68755],[68756,68820],[68820,68756],[68757,68821],[68821,68757],[68758,68822],[68822,68758],[68759,68823],[68823,68759],[68760,68824],[68824,68760],[68761,68825],[68825,68761],[68762,68826],[68826,68762],[68763,68827],[68827,68763],[68764,68828],[68828,68764],[68765,68829],[68829,68765],[68766,68830],[68830,68766],[68767,68831],[68831,68767],[68768,68832],[68832,68768],[68769,68833],[68833,68769],[68770,68834],[68834,68770],[68771,68835],[68835,68771],[68772,68836],[68836,68772],[68773,68837],[68837,68773],[68774,68838],[68838,68774],[68775,68839],[68839,68775],[68776,68840],[68840,68776],[68777,68841],[68841,68777],[68778,68842],[68842,68778],[68779,68843],[68843,68779],[68780,68844],[68844,68780],[68781,68845],[68845,68781],[68782,68846],[68846,68782],[68783,68847],[68847,68783],[68784,68848],[68848,68784],[68785,68849],[68849,68785],[68786,68850],[68850,68786],[71840,71872],[71872,71840],[71841,71873],[71873,71841],[71842,71874],[71874,71842],[71843,71875],[71875,71843],[71844,71876],[71876,71844],[71845,71877],[71877,71845],[71846,71878],[71878,71846],[71847,71879],[71879,71847],[71848,71880],[71880,71848],[71849,71881],[71881,71849],[71850,71882],[71882,71850],[71851,71883],[71883,71851],[71852,71884],[71884,71852],[71853,71885],[71885,71853],[71854,71886],[71886,71854],[71855,71887],[71887,71855],[71856,71888],[71888,71856],[71857,71889],[71889,71857],[71858,71890],[71890,71858],[71859,71891],[71891,71859],[71860,71892],[71892,71860],[71861,71893],[71893,71861],[71862,71894],[71894,71862],[71863,71895],[71895,71863],[71864,71896],[71896,71864],[71865,71897],[71897,71865],[71866,71898],[71898,71866],[71867,71899],[71899,71867],[71868,71900],[71900,71868],[71869,71901],[71901,71869],[71870,71902],[71902,71870],[71871,71903],[71903,71871],[93760,93792],[93792,93760],[93761,93793],[93793,93761],[93762,93794],[93794,93762],[93763,93795],[93795,93763],[93764,93796],[93796,93764],[93765,93797],[93797,93765],[93766,93798],[93798,93766],[93767,93799],[93799,93767],[93768,93800],[93800,93768],[93769,93801],[93801,93769],[93770,93802],[93802,93770],[93771,93803],[93803,93771],[93772,93804],[93804,93772],[93773,93805],[93805,93773],[93774,93806],[93806,93774],[93775,93807],[93807,93775],[93776,93808],[93808,93776],[93777,93809],[93809,93777],[93778,93810],[93810,93778],[93779,93811],[93811,93779],[93780,93812],[93812,93780],[93781,93813],[93813,93781],[93782,93814],[93814,93782],[93783,93815],[93815,93783],[93784,93816],[93816,93784],[93785,93817],[93817,93785],[93786,93818],[93818,93786],[93787,93819],[93819,93787],[93788,93820],[93820,93788],[93789,93821],[93821,93789],[93790,93822],[93822,93790],[93791,93823],[93823,93791],[125184,125218],[125218,125184],[125185,125219],[125219,125185],[125186,125220],[125220,125186],[125187,125221],[125221,125187],[125188,125222],[125222,125188],[125189,125223],[125223,125189],[125190,125224],[125224,125190],[125191,125225],[125225,125191],[125192,125226],[125226,125192],[125193,125227],[125227,125193],[125194,125228],[125228,125194],[125195,125229],[125229,125195],[125196,125230],[125230,125196],[125197,125231],[125231,125197],[125198,125232],[125232,125198],[125199,125233],[125233,125199],[125200,125234],[125234,125200],[125201,125235],[125235,125201],[125202,125236],[125236,125202],[125203,125237],[125237,125203],[125204,125238],[125238,125204],[125205,125239],[125239,125205],[125206,125240],[125240,125206],[125207,125241],[125241,125207],[125208,125242],[125242,125208],[125209,125243],[125243,125209],[125210,125244],[125244,125210],[125211,125245],[125245,125211],[125212,125246],[125246,125212],[125213,125247],[125247,125213],[125214,125248],[125248,125214],[125215,125249],[125249,125215],[125216,125250],[125250,125216],[125217,125251],[125251,125217]]);static C=[[0,31,1],[127,159,1],[173,888,715],[889,896,7],[897,899,1],[907,909,2],[930,1328,398],[1367,1368,1],[1419,1420,1],[1424,1480,56],[1481,1487,1],[1515,1518,1],[1525,1541,1],[1564,1757,193],[1806,1807,1],[1867,1868,1],[1970,1983,1],[2043,2044,1],[2094,2095,1],[2111,2140,29],[2141,2143,2],[2155,2159,1],[2191,2199,1],[2274,2436,162],[2445,2446,1],[2449,2450,1],[2473,2481,8],[2483,2485,1],[2490,2491,1],[2501,2502,1],[2505,2506,1],[2511,2518,1],[2520,2523,1],[2526,2532,6],[2533,2559,26],[2560,2564,4],[2571,2574,1],[2577,2578,1],[2601,2609,8],[2612,2618,3],[2619,2621,2],[2627,2630,1],[2633,2634,1],[2638,2640,1],[2642,2648,1],[2653,2655,2],[2656,2661,1],[2679,2688,1],[2692,2702,10],[2706,2729,23],[2737,2740,3],[2746,2747,1],[2758,2766,4],[2767,2769,2],[2770,2783,1],[2788,2789,1],[2802,2808,1],[2816,2820,4],[2829,2830,1],[2833,2834,1],[2857,2865,8],[2868,2874,6],[2875,2885,10],[2886,2889,3],[2890,2894,4],[2895,2900,1],[2904,2907,1],[2910,2916,6],[2917,2936,19],[2937,2945,1],[2948,2955,7],[2956,2957,1],[2961,2966,5],[2967,2968,1],[2971,2973,2],[2976,2978,1],[2981,2983,1],[2987,2989,1],[3002,3005,1],[3011,3013,1],[3017,3022,5],[3023,3025,2],[3026,3030,1],[3032,3045,1],[3067,3071,1],[3085,3089,4],[3113,3130,17],[3131,3141,10],[3145,3150,5],[3151,3156,1],[3159,3163,4],[3164,3166,2],[3167,3172,5],[3173,3184,11],[3185,3190,1],[3213,3217,4],[3241,3252,11],[3258,3259,1],[3269,3273,4],[3278,3284,1],[3287,3292,1],[3295,3300,5],[3301,3312,11],[3316,3327,1],[3341,3345,4],[3397,3401,4],[3408,3411,1],[3428,3429,1],[3456,3460,4],[3479,3481,1],[3506,3516,10],[3518,3519,1],[3527,3529,1],[3531,3534,1],[3541,3543,2],[3552,3557,1],[3568,3569,1],[3573,3584,1],[3643,3646,1],[3676,3712,1],[3715,3717,2],[3723,3748,25],[3750,3774,24],[3775,3781,6],[3783,3791,8],[3802,3803,1],[3808,3839,1],[3912,3949,37],[3950,3952,1],[3992,4029,37],[4045,4059,14],[4060,4095,1],[4294,4296,2],[4297,4300,1],[4302,4303,1],[4681,4686,5],[4687,4695,8],[4697,4702,5],[4703,4745,42],[4750,4751,1],[4785,4790,5],[4791,4799,8],[4801,4806,5],[4807,4823,16],[4881,4886,5],[4887,4955,68],[4956,4989,33],[4990,4991,1],[5018,5023,1],[5110,5111,1],[5118,5119,1],[5789,5791,1],[5881,5887,1],[5910,5918,1],[5943,5951,1],[5972,5983,1],[5997,6001,4],[6004,6015,1],[6110,6111,1],[6122,6127,1],[6138,6143,1],[6158,6170,12],[6171,6175,1],[6265,6271,1],[6315,6319,1],[6390,6399,1],[6431,6444,13],[6445,6447,1],[6460,6463,1],[6465,6467,1],[6510,6511,1],[6517,6527,1],[6572,6575,1],[6602,6607,1],[6619,6621,1],[6684,6685,1],[6751,6781,30],[6782,6794,12],[6795,6799,1],[6810,6815,1],[6830,6831,1],[6863,6911,1],[6989,6991,1],[7039,7156,117],[7157,7163,1],[7224,7226,1],[7242,7244,1],[7305,7311,1],[7355,7356,1],[7368,7375,1],[7419,7423,1],[7958,7959,1],[7966,7967,1],[8006,8007,1],[8014,8015,1],[8024,8030,2],[8062,8063,1],[8117,8133,16],[8148,8149,1],[8156,8176,20],[8177,8181,4],[8191,8203,12],[8204,8207,1],[8234,8238,1],[8288,8303,1],[8306,8307,1],[8335,8349,14],[8350,8351,1],[8385,8399,1],[8433,8447,1],[8588,8591,1],[9255,9279,1],[9291,9311,1],[11124,11125,1],[11158,11508,350],[11509,11512,1],[11558,11560,2],[11561,11564,1],[11566,11567,1],[11624,11630,1],[11633,11646,1],[11671,11679,1],[11687,11743,8],[11870,11903,1],[11930,12020,90],[12021,12031,1],[12246,12271,1],[12352,12439,87],[12440,12544,104],[12545,12548,1],[12592,12687,95],[12772,12782,1],[12831,42125,29294],[42126,42127,1],[42183,42191,1],[42540,42559,1],[42744,42751,1],[42955,42959,1],[42962,42964,2],[42970,42993,1],[43053,43055,1],[43066,43071,1],[43128,43135,1],[43206,43213,1],[43226,43231,1],[43348,43358,1],[43389,43391,1],[43470,43482,12],[43483,43485,1],[43519,43575,56],[43576,43583,1],[43598,43599,1],[43610,43611,1],[43715,43738,1],[43767,43776,1],[43783,43784,1],[43791,43792,1],[43799,43807,1],[43815,43823,8],[43884,43887,1],[44014,44015,1],[44026,44031,1],[55204,55215,1],[55239,55242,1],[55292,63743,1],[64110,64111,1],[64218,64255,1],[64263,64274,1],[64280,64284,1],[64311,64317,6],[64319,64325,3],[64451,64466,1],[64912,64913,1],[64968,64974,1],[64976,65007,1],[65050,65055,1],[65107,65127,20],[65132,65135,1],[65141,65277,136],[65278,65280,1],[65471,65473,1],[65480,65481,1],[65488,65489,1],[65496,65497,1],[65501,65503,1],[65511,65519,8],[65520,65531,1],[65534,65535,1],[65548,65575,27],[65595,65598,3],[65614,65615,1],[65630,65663,1],[65787,65791,1],[65795,65798,1],[65844,65846,1],[65935,65949,14],[65950,65951,1],[65953,65999,1],[66046,66175,1],[66205,66207,1],[66257,66271,1],[66300,66303,1],[66340,66348,1],[66379,66383,1],[66427,66431,1],[66462,66500,38],[66501,66503,1],[66518,66559,1],[66718,66719,1],[66730,66735,1],[66772,66775,1],[66812,66815,1],[66856,66863,1],[66916,66926,1],[66939,66955,16],[66963,66966,3],[66978,66994,16],[67002,67005,3],[67006,67071,1],[67383,67391,1],[67414,67423,1],[67432,67455,1],[67462,67505,43],[67515,67583,1],[67590,67591,1],[67593,67638,45],[67641,67643,1],[67645,67646,1],[67670,67743,73],[67744,67750,1],[67760,67807,1],[67827,67830,3],[67831,67834,1],[67868,67870,1],[67898,67902,1],[67904,67967,1],[68024,68027,1],[68048,68049,1],[68100,68103,3],[68104,68107,1],[68116,68120,4],[68150,68151,1],[68155,68158,1],[68169,68175,1],[68185,68191,1],[68256,68287,1],[68327,68330,1],[68343,68351,1],[68406,68408,1],[68438,68439,1],[68467,68471,1],[68498,68504,1],[68509,68520,1],[68528,68607,1],[68681,68735,1],[68787,68799,1],[68851,68857,1],[68904,68911,1],[68922,69215,1],[69247,69290,43],[69294,69295,1],[69298,69372,1],[69416,69423,1],[69466,69487,1],[69514,69551,1],[69580,69599,1],[69623,69631,1],[69710,69713,1],[69750,69758,1],[69821,69827,6],[69828,69839,1],[69865,69871,1],[69882,69887,1],[69941,69960,19],[69961,69967,1],[70007,70015,1],[70112,70133,21],[70134,70143,1],[70162,70210,48],[70211,70271,1],[70279,70281,2],[70286,70302,16],[70314,70319,1],[70379,70383,1],[70394,70399,1],[70404,70413,9],[70414,70417,3],[70418,70441,23],[70449,70452,3],[70458,70469,11],[70470,70473,3],[70474,70478,4],[70479,70481,2],[70482,70486,1],[70488,70492,1],[70500,70501,1],[70509,70511,1],[70517,70655,1],[70748,70754,6],[70755,70783,1],[70856,70863,1],[70874,71039,1],[71094,71095,1],[71134,71167,1],[71237,71247,1],[71258,71263,1],[71277,71295,1],[71354,71359,1],[71370,71423,1],[71451,71452,1],[71468,71471,1],[71495,71679,1],[71740,71839,1],[71923,71934,1],[71943,71944,1],[71946,71947,1],[71956,71959,3],[71990,71993,3],[71994,72007,13],[72008,72015,1],[72026,72095,1],[72104,72105,1],[72152,72153,1],[72165,72191,1],[72264,72271,1],[72355,72367,1],[72441,72447,1],[72458,72703,1],[72713,72759,46],[72774,72783,1],[72813,72815,1],[72848,72849,1],[72872,72887,15],[72888,72959,1],[72967,72970,3],[73015,73017,1],[73019,73022,3],[73032,73039,1],[73050,73055,1],[73062,73065,3],[73103,73106,3],[73113,73119,1],[73130,73439,1],[73465,73471,1],[73489,73531,42],[73532,73533,1],[73562,73647,1],[73649,73663,1],[73714,73726,1],[74650,74751,1],[74863,74869,6],[74870,74879,1],[75076,77711,1],[77811,77823,1],[78896,78911,1],[78934,82943,1],[83527,92159,1],[92729,92735,1],[92767,92778,11],[92779,92781,1],[92863,92874,11],[92875,92879,1],[92910,92911,1],[92918,92927,1],[92998,93007,1],[93018,93026,8],[93048,93052,1],[93072,93759,1],[93851,93951,1],[94027,94030,1],[94088,94094,1],[94112,94175,1],[94181,94191,1],[94194,94207,1],[100344,100351,1],[101590,101631,1],[101641,110575,1],[110580,110588,8],[110591,110883,292],[110884,110897,1],[110899,110927,1],[110931,110932,1],[110934,110947,1],[110952,110959,1],[111356,113663,1],[113771,113775,1],[113789,113791,1],[113801,113807,1],[113818,113819,1],[113824,118527,1],[118574,118575,1],[118599,118607,1],[118724,118783,1],[119030,119039,1],[119079,119080,1],[119155,119162,1],[119275,119295,1],[119366,119487,1],[119508,119519,1],[119540,119551,1],[119639,119647,1],[119673,119807,1],[119893,119965,72],[119968,119969,1],[119971,119972,1],[119975,119976,1],[119981,119994,13],[119996,120004,8],[120070,120075,5],[120076,120085,9],[120093,120122,29],[120127,120133,6],[120135,120137,1],[120145,120486,341],[120487,120780,293],[120781,121484,703],[121485,121498,1],[121504,121520,16],[121521,122623,1],[122655,122660,1],[122667,122879,1],[122887,122905,18],[122906,122914,8],[122917,122923,6],[122924,122927,1],[122990,123022,1],[123024,123135,1],[123181,123183,1],[123198,123199,1],[123210,123213,1],[123216,123535,1],[123567,123583,1],[123642,123646,1],[123648,124111,1],[124154,124895,1],[124903,124908,5],[124911,124927,16],[125125,125126,1],[125143,125183,1],[125260,125263,1],[125274,125277,1],[125280,126064,1],[126133,126208,1],[126270,126463,1],[126468,126496,28],[126499,126501,2],[126502,126504,2],[126515,126520,5],[126522,126524,2],[126525,126529,1],[126531,126534,1],[126536,126540,2],[126544,126547,3],[126549,126550,1],[126552,126560,2],[126563,126565,2],[126566,126571,5],[126579,126589,5],[126591,126602,11],[126620,126624,1],[126628,126634,6],[126652,126703,1],[126706,126975,1],[127020,127023,1],[127124,127135,1],[127151,127152,1],[127168,127184,16],[127222,127231,1],[127406,127461,1],[127491,127503,1],[127548,127551,1],[127561,127567,1],[127570,127583,1],[127590,127743,1],[128728,128731,1],[128749,128751,1],[128765,128767,1],[128887,128890,1],[128986,128991,1],[129004,129007,1],[129009,129023,1],[129036,129039,1],[129096,129103,1],[129114,129119,1],[129160,129167,1],[129198,129199,1],[129202,129279,1],[129620,129631,1],[129646,129647,1],[129661,129663,1],[129673,129679,1],[129726,129734,8],[129735,129741,1],[129756,129759,1],[129769,129775,1],[129785,129791,1],[129939,129995,56],[129996,130031,1],[130042,131071,1],[173792,173823,1],[177978,177983,1],[178206,178207,1],[183970,183983,1],[191457,191471,1],[192094,194559,1],[195102,196607,1],[201547,201551,1],[205744,917759,1],[918e3,1114111,1]];static Cc=[[0,31,1],[127,159,1]];static Cf=[[173,1536,1363],[1537,1541,1],[1564,1757,193],[1807,2192,385],[2193,2274,81],[6158,8203,2045],[8204,8207,1],[8234,8238,1],[8288,8292,1],[8294,8303,1],[65279,65529,250],[65530,65531,1],[69821,69837,16],[78896,78911,1],[113824,113827,1],[119155,119162,1],[917505,917536,31],[917537,917631,1]];static Co=[[57344,63743,1],[983040,1048573,1],[1048576,1114109,1]];static Cs=[[55296,57343,1]];static L=[[65,90,1],[97,122,1],[170,181,11],[186,192,6],[193,214,1],[216,246,1],[248,705,1],[710,721,1],[736,740,1],[748,750,2],[880,884,1],[886,887,1],[890,893,1],[895,902,7],[904,906,1],[908,910,2],[911,929,1],[931,1013,1],[1015,1153,1],[1162,1327,1],[1329,1366,1],[1369,1376,7],[1377,1416,1],[1488,1514,1],[1519,1522,1],[1568,1610,1],[1646,1647,1],[1649,1747,1],[1749,1765,16],[1766,1774,8],[1775,1786,11],[1787,1788,1],[1791,1808,17],[1810,1839,1],[1869,1957,1],[1969,1994,25],[1995,2026,1],[2036,2037,1],[2042,2048,6],[2049,2069,1],[2074,2084,10],[2088,2112,24],[2113,2136,1],[2144,2154,1],[2160,2183,1],[2185,2190,1],[2208,2249,1],[2308,2361,1],[2365,2384,19],[2392,2401,1],[2417,2432,1],[2437,2444,1],[2447,2448,1],[2451,2472,1],[2474,2480,1],[2482,2486,4],[2487,2489,1],[2493,2510,17],[2524,2525,1],[2527,2529,1],[2544,2545,1],[2556,2565,9],[2566,2570,1],[2575,2576,1],[2579,2600,1],[2602,2608,1],[2610,2611,1],[2613,2614,1],[2616,2617,1],[2649,2652,1],[2654,2674,20],[2675,2676,1],[2693,2701,1],[2703,2705,1],[2707,2728,1],[2730,2736,1],[2738,2739,1],[2741,2745,1],[2749,2768,19],[2784,2785,1],[2809,2821,12],[2822,2828,1],[2831,2832,1],[2835,2856,1],[2858,2864,1],[2866,2867,1],[2869,2873,1],[2877,2908,31],[2909,2911,2],[2912,2913,1],[2929,2947,18],[2949,2954,1],[2958,2960,1],[2962,2965,1],[2969,2970,1],[2972,2974,2],[2975,2979,4],[2980,2984,4],[2985,2986,1],[2990,3001,1],[3024,3077,53],[3078,3084,1],[3086,3088,1],[3090,3112,1],[3114,3129,1],[3133,3160,27],[3161,3162,1],[3165,3168,3],[3169,3200,31],[3205,3212,1],[3214,3216,1],[3218,3240,1],[3242,3251,1],[3253,3257,1],[3261,3293,32],[3294,3296,2],[3297,3313,16],[3314,3332,18],[3333,3340,1],[3342,3344,1],[3346,3386,1],[3389,3406,17],[3412,3414,1],[3423,3425,1],[3450,3455,1],[3461,3478,1],[3482,3505,1],[3507,3515,1],[3517,3520,3],[3521,3526,1],[3585,3632,1],[3634,3635,1],[3648,3654,1],[3713,3714,1],[3716,3718,2],[3719,3722,1],[3724,3747,1],[3749,3751,2],[3752,3760,1],[3762,3763,1],[3773,3776,3],[3777,3780,1],[3782,3804,22],[3805,3807,1],[3840,3904,64],[3905,3911,1],[3913,3948,1],[3976,3980,1],[4096,4138,1],[4159,4176,17],[4177,4181,1],[4186,4189,1],[4193,4197,4],[4198,4206,8],[4207,4208,1],[4213,4225,1],[4238,4256,18],[4257,4293,1],[4295,4301,6],[4304,4346,1],[4348,4680,1],[4682,4685,1],[4688,4694,1],[4696,4698,2],[4699,4701,1],[4704,4744,1],[4746,4749,1],[4752,4784,1],[4786,4789,1],[4792,4798,1],[4800,4802,2],[4803,4805,1],[4808,4822,1],[4824,4880,1],[4882,4885,1],[4888,4954,1],[4992,5007,1],[5024,5109,1],[5112,5117,1],[5121,5740,1],[5743,5759,1],[5761,5786,1],[5792,5866,1],[5873,5880,1],[5888,5905,1],[5919,5937,1],[5952,5969,1],[5984,5996,1],[5998,6e3,1],[6016,6067,1],[6103,6108,5],[6176,6264,1],[6272,6276,1],[6279,6312,1],[6314,6320,6],[6321,6389,1],[6400,6430,1],[6480,6509,1],[6512,6516,1],[6528,6571,1],[6576,6601,1],[6656,6678,1],[6688,6740,1],[6823,6917,94],[6918,6963,1],[6981,6988,1],[7043,7072,1],[7086,7087,1],[7098,7141,1],[7168,7203,1],[7245,7247,1],[7258,7293,1],[7296,7304,1],[7312,7354,1],[7357,7359,1],[7401,7404,1],[7406,7411,1],[7413,7414,1],[7418,7424,6],[7425,7615,1],[7680,7957,1],[7960,7965,1],[7968,8005,1],[8008,8013,1],[8016,8023,1],[8025,8031,2],[8032,8061,1],[8064,8116,1],[8118,8124,1],[8126,8130,4],[8131,8132,1],[8134,8140,1],[8144,8147,1],[8150,8155,1],[8160,8172,1],[8178,8180,1],[8182,8188,1],[8305,8319,14],[8336,8348,1],[8450,8455,5],[8458,8467,1],[8469,8473,4],[8474,8477,1],[8484,8490,2],[8491,8493,1],[8495,8505,1],[8508,8511,1],[8517,8521,1],[8526,8579,53],[8580,11264,2684],[11265,11492,1],[11499,11502,1],[11506,11507,1],[11520,11557,1],[11559,11565,6],[11568,11623,1],[11631,11648,17],[11649,11670,1],[11680,11686,1],[11688,11694,1],[11696,11702,1],[11704,11710,1],[11712,11718,1],[11720,11726,1],[11728,11734,1],[11736,11742,1],[11823,12293,470],[12294,12337,43],[12338,12341,1],[12347,12348,1],[12353,12438,1],[12445,12447,1],[12449,12538,1],[12540,12543,1],[12549,12591,1],[12593,12686,1],[12704,12735,1],[12784,12799,1],[13312,19903,1],[19968,42124,1],[42192,42237,1],[42240,42508,1],[42512,42527,1],[42538,42539,1],[42560,42606,1],[42623,42653,1],[42656,42725,1],[42775,42783,1],[42786,42888,1],[42891,42954,1],[42960,42961,1],[42963,42965,2],[42966,42969,1],[42994,43009,1],[43011,43013,1],[43015,43018,1],[43020,43042,1],[43072,43123,1],[43138,43187,1],[43250,43255,1],[43259,43261,2],[43262,43274,12],[43275,43301,1],[43312,43334,1],[43360,43388,1],[43396,43442,1],[43471,43488,17],[43489,43492,1],[43494,43503,1],[43514,43518,1],[43520,43560,1],[43584,43586,1],[43588,43595,1],[43616,43638,1],[43642,43646,4],[43647,43695,1],[43697,43701,4],[43702,43705,3],[43706,43709,1],[43712,43714,2],[43739,43741,1],[43744,43754,1],[43762,43764,1],[43777,43782,1],[43785,43790,1],[43793,43798,1],[43808,43814,1],[43816,43822,1],[43824,43866,1],[43868,43881,1],[43888,44002,1],[44032,55203,1],[55216,55238,1],[55243,55291,1],[63744,64109,1],[64112,64217,1],[64256,64262,1],[64275,64279,1],[64285,64287,2],[64288,64296,1],[64298,64310,1],[64312,64316,1],[64318,64320,2],[64321,64323,2],[64324,64326,2],[64327,64433,1],[64467,64829,1],[64848,64911,1],[64914,64967,1],[65008,65019,1],[65136,65140,1],[65142,65276,1],[65313,65338,1],[65345,65370,1],[65382,65470,1],[65474,65479,1],[65482,65487,1],[65490,65495,1],[65498,65500,1],[65536,65547,1],[65549,65574,1],[65576,65594,1],[65596,65597,1],[65599,65613,1],[65616,65629,1],[65664,65786,1],[66176,66204,1],[66208,66256,1],[66304,66335,1],[66349,66368,1],[66370,66377,1],[66384,66421,1],[66432,66461,1],[66464,66499,1],[66504,66511,1],[66560,66717,1],[66736,66771,1],[66776,66811,1],[66816,66855,1],[66864,66915,1],[66928,66938,1],[66940,66954,1],[66956,66962,1],[66964,66965,1],[66967,66977,1],[66979,66993,1],[66995,67001,1],[67003,67004,1],[67072,67382,1],[67392,67413,1],[67424,67431,1],[67456,67461,1],[67463,67504,1],[67506,67514,1],[67584,67589,1],[67592,67594,2],[67595,67637,1],[67639,67640,1],[67644,67647,3],[67648,67669,1],[67680,67702,1],[67712,67742,1],[67808,67826,1],[67828,67829,1],[67840,67861,1],[67872,67897,1],[67968,68023,1],[68030,68031,1],[68096,68112,16],[68113,68115,1],[68117,68119,1],[68121,68149,1],[68192,68220,1],[68224,68252,1],[68288,68295,1],[68297,68324,1],[68352,68405,1],[68416,68437,1],[68448,68466,1],[68480,68497,1],[68608,68680,1],[68736,68786,1],[68800,68850,1],[68864,68899,1],[69248,69289,1],[69296,69297,1],[69376,69404,1],[69415,69424,9],[69425,69445,1],[69488,69505,1],[69552,69572,1],[69600,69622,1],[69635,69687,1],[69745,69746,1],[69749,69763,14],[69764,69807,1],[69840,69864,1],[69891,69926,1],[69956,69959,3],[69968,70002,1],[70006,70019,13],[70020,70066,1],[70081,70084,1],[70106,70108,2],[70144,70161,1],[70163,70187,1],[70207,70208,1],[70272,70278,1],[70280,70282,2],[70283,70285,1],[70287,70301,1],[70303,70312,1],[70320,70366,1],[70405,70412,1],[70415,70416,1],[70419,70440,1],[70442,70448,1],[70450,70451,1],[70453,70457,1],[70461,70480,19],[70493,70497,1],[70656,70708,1],[70727,70730,1],[70751,70753,1],[70784,70831,1],[70852,70853,1],[70855,71040,185],[71041,71086,1],[71128,71131,1],[71168,71215,1],[71236,71296,60],[71297,71338,1],[71352,71424,72],[71425,71450,1],[71488,71494,1],[71680,71723,1],[71840,71903,1],[71935,71942,1],[71945,71948,3],[71949,71955,1],[71957,71958,1],[71960,71983,1],[71999,72001,2],[72096,72103,1],[72106,72144,1],[72161,72163,2],[72192,72203,11],[72204,72242,1],[72250,72272,22],[72284,72329,1],[72349,72368,19],[72369,72440,1],[72704,72712,1],[72714,72750,1],[72768,72818,50],[72819,72847,1],[72960,72966,1],[72968,72969,1],[72971,73008,1],[73030,73056,26],[73057,73061,1],[73063,73064,1],[73066,73097,1],[73112,73440,328],[73441,73458,1],[73474,73476,2],[73477,73488,1],[73490,73523,1],[73648,73728,80],[73729,74649,1],[74880,75075,1],[77712,77808,1],[77824,78895,1],[78913,78918,1],[82944,83526,1],[92160,92728,1],[92736,92766,1],[92784,92862,1],[92880,92909,1],[92928,92975,1],[92992,92995,1],[93027,93047,1],[93053,93071,1],[93760,93823,1],[93952,94026,1],[94032,94099,67],[94100,94111,1],[94176,94177,1],[94179,94208,29],[94209,100343,1],[100352,101589,1],[101632,101640,1],[110576,110579,1],[110581,110587,1],[110589,110590,1],[110592,110882,1],[110898,110928,30],[110929,110930,1],[110933,110948,15],[110949,110951,1],[110960,111355,1],[113664,113770,1],[113776,113788,1],[113792,113800,1],[113808,113817,1],[119808,119892,1],[119894,119964,1],[119966,119967,1],[119970,119973,3],[119974,119977,3],[119978,119980,1],[119982,119993,1],[119995,119997,2],[119998,120003,1],[120005,120069,1],[120071,120074,1],[120077,120084,1],[120086,120092,1],[120094,120121,1],[120123,120126,1],[120128,120132,1],[120134,120138,4],[120139,120144,1],[120146,120485,1],[120488,120512,1],[120514,120538,1],[120540,120570,1],[120572,120596,1],[120598,120628,1],[120630,120654,1],[120656,120686,1],[120688,120712,1],[120714,120744,1],[120746,120770,1],[120772,120779,1],[122624,122654,1],[122661,122666,1],[122928,122989,1],[123136,123180,1],[123191,123197,1],[123214,123536,322],[123537,123565,1],[123584,123627,1],[124112,124139,1],[124896,124902,1],[124904,124907,1],[124909,124910,1],[124912,124926,1],[124928,125124,1],[125184,125251,1],[125259,126464,1205],[126465,126467,1],[126469,126495,1],[126497,126498,1],[126500,126503,3],[126505,126514,1],[126516,126519,1],[126521,126523,2],[126530,126535,5],[126537,126541,2],[126542,126543,1],[126545,126546,1],[126548,126551,3],[126553,126561,2],[126562,126564,2],[126567,126570,1],[126572,126578,1],[126580,126583,1],[126585,126588,1],[126590,126592,2],[126593,126601,1],[126603,126619,1],[126625,126627,1],[126629,126633,1],[126635,126651,1],[131072,173791,1],[173824,177977,1],[177984,178205,1],[178208,183969,1],[183984,191456,1],[191472,192093,1],[194560,195101,1],[196608,201546,1],[201552,205743,1]];static foldL=[[837,837,1]];static Ll=[[97,122,1],[181,223,42],[224,246,1],[248,255,1],[257,311,2],[312,328,2],[329,375,2],[378,382,2],[383,384,1],[387,389,2],[392,396,4],[397,402,5],[405,409,4],[410,411,1],[414,417,3],[419,421,2],[424,426,2],[427,429,2],[432,436,4],[438,441,3],[442,445,3],[446,447,1],[454,460,3],[462,476,2],[477,495,2],[496,499,3],[501,505,4],[507,563,2],[564,569,1],[572,575,3],[576,578,2],[583,591,2],[592,659,1],[661,687,1],[881,883,2],[887,891,4],[892,893,1],[912,940,28],[941,974,1],[976,977,1],[981,983,1],[985,1007,2],[1008,1011,1],[1013,1019,3],[1020,1072,52],[1073,1119,1],[1121,1153,2],[1163,1215,2],[1218,1230,2],[1231,1327,2],[1376,1416,1],[4304,4346,1],[4349,4351,1],[5112,5117,1],[7296,7304,1],[7424,7467,1],[7531,7543,1],[7545,7578,1],[7681,7829,2],[7830,7837,1],[7839,7935,2],[7936,7943,1],[7952,7957,1],[7968,7975,1],[7984,7991,1],[8e3,8005,1],[8016,8023,1],[8032,8039,1],[8048,8061,1],[8064,8071,1],[8080,8087,1],[8096,8103,1],[8112,8116,1],[8118,8119,1],[8126,8130,4],[8131,8132,1],[8134,8135,1],[8144,8147,1],[8150,8151,1],[8160,8167,1],[8178,8180,1],[8182,8183,1],[8458,8462,4],[8463,8467,4],[8495,8505,5],[8508,8509,1],[8518,8521,1],[8526,8580,54],[11312,11359,1],[11361,11365,4],[11366,11372,2],[11377,11379,2],[11380,11382,2],[11383,11387,1],[11393,11491,2],[11492,11500,8],[11502,11507,5],[11520,11557,1],[11559,11565,6],[42561,42605,2],[42625,42651,2],[42787,42799,2],[42800,42801,1],[42803,42865,2],[42866,42872,1],[42874,42876,2],[42879,42887,2],[42892,42894,2],[42897,42899,2],[42900,42901,1],[42903,42921,2],[42927,42933,6],[42935,42947,2],[42952,42954,2],[42961,42969,2],[42998,43002,4],[43824,43866,1],[43872,43880,1],[43888,43967,1],[64256,64262,1],[64275,64279,1],[65345,65370,1],[66600,66639,1],[66776,66811,1],[66967,66977,1],[66979,66993,1],[66995,67001,1],[67003,67004,1],[68800,68850,1],[71872,71903,1],[93792,93823,1],[119834,119859,1],[119886,119892,1],[119894,119911,1],[119938,119963,1],[119990,119993,1],[119995,119997,2],[119998,120003,1],[120005,120015,1],[120042,120067,1],[120094,120119,1],[120146,120171,1],[120198,120223,1],[120250,120275,1],[120302,120327,1],[120354,120379,1],[120406,120431,1],[120458,120485,1],[120514,120538,1],[120540,120545,1],[120572,120596,1],[120598,120603,1],[120630,120654,1],[120656,120661,1],[120688,120712,1],[120714,120719,1],[120746,120770,1],[120772,120777,1],[120779,122624,1845],[122625,122633,1],[122635,122654,1],[122661,122666,1],[125218,125251,1]];static foldLl=[[65,90,1],[192,214,1],[216,222,1],[256,302,2],[306,310,2],[313,327,2],[330,376,2],[377,381,2],[385,386,1],[388,390,2],[391,393,2],[394,395,1],[398,401,1],[403,404,1],[406,408,1],[412,413,1],[415,416,1],[418,422,2],[423,425,2],[428,430,2],[431,433,2],[434,435,1],[437,439,2],[440,444,4],[452,453,1],[455,456,1],[458,459,1],[461,475,2],[478,494,2],[497,498,1],[500,502,2],[503,504,1],[506,562,2],[570,571,1],[573,574,1],[577,579,2],[580,582,1],[584,590,2],[837,880,43],[882,886,4],[895,902,7],[904,906,1],[908,910,2],[911,913,2],[914,929,1],[931,939,1],[975,984,9],[986,1006,2],[1012,1015,3],[1017,1018,1],[1021,1071,1],[1120,1152,2],[1162,1216,2],[1217,1229,2],[1232,1326,2],[1329,1366,1],[4256,4293,1],[4295,4301,6],[5024,5109,1],[7312,7354,1],[7357,7359,1],[7680,7828,2],[7838,7934,2],[7944,7951,1],[7960,7965,1],[7976,7983,1],[7992,7999,1],[8008,8013,1],[8025,8031,2],[8040,8047,1],[8072,8079,1],[8088,8095,1],[8104,8111,1],[8120,8124,1],[8136,8140,1],[8152,8155,1],[8168,8172,1],[8184,8188,1],[8486,8490,4],[8491,8498,7],[8579,11264,2685],[11265,11311,1],[11360,11362,2],[11363,11364,1],[11367,11373,2],[11374,11376,1],[11378,11381,3],[11390,11392,1],[11394,11490,2],[11499,11501,2],[11506,42560,31054],[42562,42604,2],[42624,42650,2],[42786,42798,2],[42802,42862,2],[42873,42877,2],[42878,42886,2],[42891,42893,2],[42896,42898,2],[42902,42922,2],[42923,42926,1],[42928,42932,1],[42934,42948,2],[42949,42951,1],[42953,42960,7],[42966,42968,2],[42997,65313,22316],[65314,65338,1],[66560,66599,1],[66736,66771,1],[66928,66938,1],[66940,66954,1],[66956,66962,1],[66964,66965,1],[68736,68786,1],[71840,71871,1],[93760,93791,1],[125184,125217,1]];static Lm=[[688,705,1],[710,721,1],[736,740,1],[748,750,2],[884,890,6],[1369,1600,231],[1765,1766,1],[2036,2037,1],[2042,2074,32],[2084,2088,4],[2249,2417,168],[3654,3782,128],[4348,6103,1755],[6211,6823,612],[7288,7293,1],[7468,7530,1],[7544,7579,35],[7580,7615,1],[8305,8319,14],[8336,8348,1],[11388,11389,1],[11631,11823,192],[12293,12337,44],[12338,12341,1],[12347,12445,98],[12446,12540,94],[12541,12542,1],[40981,42232,1251],[42233,42237,1],[42508,42623,115],[42652,42653,1],[42775,42783,1],[42864,42888,24],[42994,42996,1],[43e3,43001,1],[43471,43494,23],[43632,43741,109],[43763,43764,1],[43868,43871,1],[43881,65392,21511],[65438,65439,1],[67456,67461,1],[67463,67504,1],[67506,67514,1],[92992,92995,1],[94099,94111,1],[94176,94177,1],[94179,110576,16397],[110577,110579,1],[110581,110587,1],[110589,110590,1],[122928,122989,1],[123191,123197,1],[124139,125259,1120]];static Lo=[[170,186,16],[443,448,5],[449,451,1],[660,1488,828],[1489,1514,1],[1519,1522,1],[1568,1599,1],[1601,1610,1],[1646,1647,1],[1649,1747,1],[1749,1774,25],[1775,1786,11],[1787,1788,1],[1791,1808,17],[1810,1839,1],[1869,1957,1],[1969,1994,25],[1995,2026,1],[2048,2069,1],[2112,2136,1],[2144,2154,1],[2160,2183,1],[2185,2190,1],[2208,2248,1],[2308,2361,1],[2365,2384,19],[2392,2401,1],[2418,2432,1],[2437,2444,1],[2447,2448,1],[2451,2472,1],[2474,2480,1],[2482,2486,4],[2487,2489,1],[2493,2510,17],[2524,2525,1],[2527,2529,1],[2544,2545,1],[2556,2565,9],[2566,2570,1],[2575,2576,1],[2579,2600,1],[2602,2608,1],[2610,2611,1],[2613,2614,1],[2616,2617,1],[2649,2652,1],[2654,2674,20],[2675,2676,1],[2693,2701,1],[2703,2705,1],[2707,2728,1],[2730,2736,1],[2738,2739,1],[2741,2745,1],[2749,2768,19],[2784,2785,1],[2809,2821,12],[2822,2828,1],[2831,2832,1],[2835,2856,1],[2858,2864,1],[2866,2867,1],[2869,2873,1],[2877,2908,31],[2909,2911,2],[2912,2913,1],[2929,2947,18],[2949,2954,1],[2958,2960,1],[2962,2965,1],[2969,2970,1],[2972,2974,2],[2975,2979,4],[2980,2984,4],[2985,2986,1],[2990,3001,1],[3024,3077,53],[3078,3084,1],[3086,3088,1],[3090,3112,1],[3114,3129,1],[3133,3160,27],[3161,3162,1],[3165,3168,3],[3169,3200,31],[3205,3212,1],[3214,3216,1],[3218,3240,1],[3242,3251,1],[3253,3257,1],[3261,3293,32],[3294,3296,2],[3297,3313,16],[3314,3332,18],[3333,3340,1],[3342,3344,1],[3346,3386,1],[3389,3406,17],[3412,3414,1],[3423,3425,1],[3450,3455,1],[3461,3478,1],[3482,3505,1],[3507,3515,1],[3517,3520,3],[3521,3526,1],[3585,3632,1],[3634,3635,1],[3648,3653,1],[3713,3714,1],[3716,3718,2],[3719,3722,1],[3724,3747,1],[3749,3751,2],[3752,3760,1],[3762,3763,1],[3773,3776,3],[3777,3780,1],[3804,3807,1],[3840,3904,64],[3905,3911,1],[3913,3948,1],[3976,3980,1],[4096,4138,1],[4159,4176,17],[4177,4181,1],[4186,4189,1],[4193,4197,4],[4198,4206,8],[4207,4208,1],[4213,4225,1],[4238,4352,114],[4353,4680,1],[4682,4685,1],[4688,4694,1],[4696,4698,2],[4699,4701,1],[4704,4744,1],[4746,4749,1],[4752,4784,1],[4786,4789,1],[4792,4798,1],[4800,4802,2],[4803,4805,1],[4808,4822,1],[4824,4880,1],[4882,4885,1],[4888,4954,1],[4992,5007,1],[5121,5740,1],[5743,5759,1],[5761,5786,1],[5792,5866,1],[5873,5880,1],[5888,5905,1],[5919,5937,1],[5952,5969,1],[5984,5996,1],[5998,6e3,1],[6016,6067,1],[6108,6176,68],[6177,6210,1],[6212,6264,1],[6272,6276,1],[6279,6312,1],[6314,6320,6],[6321,6389,1],[6400,6430,1],[6480,6509,1],[6512,6516,1],[6528,6571,1],[6576,6601,1],[6656,6678,1],[6688,6740,1],[6917,6963,1],[6981,6988,1],[7043,7072,1],[7086,7087,1],[7098,7141,1],[7168,7203,1],[7245,7247,1],[7258,7287,1],[7401,7404,1],[7406,7411,1],[7413,7414,1],[7418,8501,1083],[8502,8504,1],[11568,11623,1],[11648,11670,1],[11680,11686,1],[11688,11694,1],[11696,11702,1],[11704,11710,1],[11712,11718,1],[11720,11726,1],[11728,11734,1],[11736,11742,1],[12294,12348,54],[12353,12438,1],[12447,12449,2],[12450,12538,1],[12543,12549,6],[12550,12591,1],[12593,12686,1],[12704,12735,1],[12784,12799,1],[13312,19903,1],[19968,40980,1],[40982,42124,1],[42192,42231,1],[42240,42507,1],[42512,42527,1],[42538,42539,1],[42606,42656,50],[42657,42725,1],[42895,42999,104],[43003,43009,1],[43011,43013,1],[43015,43018,1],[43020,43042,1],[43072,43123,1],[43138,43187,1],[43250,43255,1],[43259,43261,2],[43262,43274,12],[43275,43301,1],[43312,43334,1],[43360,43388,1],[43396,43442,1],[43488,43492,1],[43495,43503,1],[43514,43518,1],[43520,43560,1],[43584,43586,1],[43588,43595,1],[43616,43631,1],[43633,43638,1],[43642,43646,4],[43647,43695,1],[43697,43701,4],[43702,43705,3],[43706,43709,1],[43712,43714,2],[43739,43740,1],[43744,43754,1],[43762,43777,15],[43778,43782,1],[43785,43790,1],[43793,43798,1],[43808,43814,1],[43816,43822,1],[43968,44002,1],[44032,55203,1],[55216,55238,1],[55243,55291,1],[63744,64109,1],[64112,64217,1],[64285,64287,2],[64288,64296,1],[64298,64310,1],[64312,64316,1],[64318,64320,2],[64321,64323,2],[64324,64326,2],[64327,64433,1],[64467,64829,1],[64848,64911,1],[64914,64967,1],[65008,65019,1],[65136,65140,1],[65142,65276,1],[65382,65391,1],[65393,65437,1],[65440,65470,1],[65474,65479,1],[65482,65487,1],[65490,65495,1],[65498,65500,1],[65536,65547,1],[65549,65574,1],[65576,65594,1],[65596,65597,1],[65599,65613,1],[65616,65629,1],[65664,65786,1],[66176,66204,1],[66208,66256,1],[66304,66335,1],[66349,66368,1],[66370,66377,1],[66384,66421,1],[66432,66461,1],[66464,66499,1],[66504,66511,1],[66640,66717,1],[66816,66855,1],[66864,66915,1],[67072,67382,1],[67392,67413,1],[67424,67431,1],[67584,67589,1],[67592,67594,2],[67595,67637,1],[67639,67640,1],[67644,67647,3],[67648,67669,1],[67680,67702,1],[67712,67742,1],[67808,67826,1],[67828,67829,1],[67840,67861,1],[67872,67897,1],[67968,68023,1],[68030,68031,1],[68096,68112,16],[68113,68115,1],[68117,68119,1],[68121,68149,1],[68192,68220,1],[68224,68252,1],[68288,68295,1],[68297,68324,1],[68352,68405,1],[68416,68437,1],[68448,68466,1],[68480,68497,1],[68608,68680,1],[68864,68899,1],[69248,69289,1],[69296,69297,1],[69376,69404,1],[69415,69424,9],[69425,69445,1],[69488,69505,1],[69552,69572,1],[69600,69622,1],[69635,69687,1],[69745,69746,1],[69749,69763,14],[69764,69807,1],[69840,69864,1],[69891,69926,1],[69956,69959,3],[69968,70002,1],[70006,70019,13],[70020,70066,1],[70081,70084,1],[70106,70108,2],[70144,70161,1],[70163,70187,1],[70207,70208,1],[70272,70278,1],[70280,70282,2],[70283,70285,1],[70287,70301,1],[70303,70312,1],[70320,70366,1],[70405,70412,1],[70415,70416,1],[70419,70440,1],[70442,70448,1],[70450,70451,1],[70453,70457,1],[70461,70480,19],[70493,70497,1],[70656,70708,1],[70727,70730,1],[70751,70753,1],[70784,70831,1],[70852,70853,1],[70855,71040,185],[71041,71086,1],[71128,71131,1],[71168,71215,1],[71236,71296,60],[71297,71338,1],[71352,71424,72],[71425,71450,1],[71488,71494,1],[71680,71723,1],[71935,71942,1],[71945,71948,3],[71949,71955,1],[71957,71958,1],[71960,71983,1],[71999,72001,2],[72096,72103,1],[72106,72144,1],[72161,72163,2],[72192,72203,11],[72204,72242,1],[72250,72272,22],[72284,72329,1],[72349,72368,19],[72369,72440,1],[72704,72712,1],[72714,72750,1],[72768,72818,50],[72819,72847,1],[72960,72966,1],[72968,72969,1],[72971,73008,1],[73030,73056,26],[73057,73061,1],[73063,73064,1],[73066,73097,1],[73112,73440,328],[73441,73458,1],[73474,73476,2],[73477,73488,1],[73490,73523,1],[73648,73728,80],[73729,74649,1],[74880,75075,1],[77712,77808,1],[77824,78895,1],[78913,78918,1],[82944,83526,1],[92160,92728,1],[92736,92766,1],[92784,92862,1],[92880,92909,1],[92928,92975,1],[93027,93047,1],[93053,93071,1],[93952,94026,1],[94032,94208,176],[94209,100343,1],[100352,101589,1],[101632,101640,1],[110592,110882,1],[110898,110928,30],[110929,110930,1],[110933,110948,15],[110949,110951,1],[110960,111355,1],[113664,113770,1],[113776,113788,1],[113792,113800,1],[113808,113817,1],[122634,123136,502],[123137,123180,1],[123214,123536,322],[123537,123565,1],[123584,123627,1],[124112,124138,1],[124896,124902,1],[124904,124907,1],[124909,124910,1],[124912,124926,1],[124928,125124,1],[126464,126467,1],[126469,126495,1],[126497,126498,1],[126500,126503,3],[126505,126514,1],[126516,126519,1],[126521,126523,2],[126530,126535,5],[126537,126541,2],[126542,126543,1],[126545,126546,1],[126548,126551,3],[126553,126561,2],[126562,126564,2],[126567,126570,1],[126572,126578,1],[126580,126583,1],[126585,126588,1],[126590,126592,2],[126593,126601,1],[126603,126619,1],[126625,126627,1],[126629,126633,1],[126635,126651,1],[131072,173791,1],[173824,177977,1],[177984,178205,1],[178208,183969,1],[183984,191456,1],[191472,192093,1],[194560,195101,1],[196608,201546,1],[201552,205743,1]];static Lt=[[453,459,3],[498,8072,7574],[8073,8079,1],[8088,8095,1],[8104,8111,1],[8124,8140,16],[8188,8188,1]];static foldLt=[[452,454,2],[455,457,2],[458,460,2],[497,499,2],[8064,8071,1],[8080,8087,1],[8096,8103,1],[8115,8131,16],[8179,8179,1]];static Lu=[[65,90,1],[192,214,1],[216,222,1],[256,310,2],[313,327,2],[330,376,2],[377,381,2],[385,386,1],[388,390,2],[391,393,2],[394,395,1],[398,401,1],[403,404,1],[406,408,1],[412,413,1],[415,416,1],[418,422,2],[423,425,2],[428,430,2],[431,433,2],[434,435,1],[437,439,2],[440,444,4],[452,461,3],[463,475,2],[478,494,2],[497,500,3],[502,504,1],[506,562,2],[570,571,1],[573,574,1],[577,579,2],[580,582,1],[584,590,2],[880,882,2],[886,895,9],[902,904,2],[905,906,1],[908,910,2],[911,913,2],[914,929,1],[931,939,1],[975,978,3],[979,980,1],[984,1006,2],[1012,1015,3],[1017,1018,1],[1021,1071,1],[1120,1152,2],[1162,1216,2],[1217,1229,2],[1232,1326,2],[1329,1366,1],[4256,4293,1],[4295,4301,6],[5024,5109,1],[7312,7354,1],[7357,7359,1],[7680,7828,2],[7838,7934,2],[7944,7951,1],[7960,7965,1],[7976,7983,1],[7992,7999,1],[8008,8013,1],[8025,8031,2],[8040,8047,1],[8120,8123,1],[8136,8139,1],[8152,8155,1],[8168,8172,1],[8184,8187,1],[8450,8455,5],[8459,8461,1],[8464,8466,1],[8469,8473,4],[8474,8477,1],[8484,8490,2],[8491,8493,1],[8496,8499,1],[8510,8511,1],[8517,8579,62],[11264,11311,1],[11360,11362,2],[11363,11364,1],[11367,11373,2],[11374,11376,1],[11378,11381,3],[11390,11392,1],[11394,11490,2],[11499,11501,2],[11506,42560,31054],[42562,42604,2],[42624,42650,2],[42786,42798,2],[42802,42862,2],[42873,42877,2],[42878,42886,2],[42891,42893,2],[42896,42898,2],[42902,42922,2],[42923,42926,1],[42928,42932,1],[42934,42948,2],[42949,42951,1],[42953,42960,7],[42966,42968,2],[42997,65313,22316],[65314,65338,1],[66560,66599,1],[66736,66771,1],[66928,66938,1],[66940,66954,1],[66956,66962,1],[66964,66965,1],[68736,68786,1],[71840,71871,1],[93760,93791,1],[119808,119833,1],[119860,119885,1],[119912,119937,1],[119964,119966,2],[119967,119973,3],[119974,119977,3],[119978,119980,1],[119982,119989,1],[120016,120041,1],[120068,120069,1],[120071,120074,1],[120077,120084,1],[120086,120092,1],[120120,120121,1],[120123,120126,1],[120128,120132,1],[120134,120138,4],[120139,120144,1],[120172,120197,1],[120224,120249,1],[120276,120301,1],[120328,120353,1],[120380,120405,1],[120432,120457,1],[120488,120512,1],[120546,120570,1],[120604,120628,1],[120662,120686,1],[120720,120744,1],[120778,125184,4406],[125185,125217,1]];static Upper=this.Lu;static foldLu=[[97,122,1],[181,223,42],[224,246,1],[248,255,1],[257,303,2],[307,311,2],[314,328,2],[331,375,2],[378,382,2],[383,384,1],[387,389,2],[392,396,4],[402,405,3],[409,410,1],[414,417,3],[419,421,2],[424,429,5],[432,436,4],[438,441,3],[445,447,2],[453,454,1],[456,457,1],[459,460,1],[462,476,2],[477,495,2],[498,499,1],[501,505,4],[507,543,2],[547,563,2],[572,575,3],[576,578,2],[583,591,2],[592,596,1],[598,599,1],[601,603,2],[604,608,4],[609,613,2],[614,616,2],[617,620,1],[623,625,2],[626,629,3],[637,640,3],[642,643,1],[647,652,1],[658,669,11],[670,837,167],[881,883,2],[887,891,4],[892,893,1],[940,943,1],[945,974,1],[976,977,1],[981,983,1],[985,1007,2],[1008,1011,1],[1013,1019,3],[1072,1119,1],[1121,1153,2],[1163,1215,2],[1218,1230,2],[1231,1327,2],[1377,1414,1],[4304,4346,1],[4349,4351,1],[5112,5117,1],[7296,7304,1],[7545,7549,4],[7566,7681,115],[7683,7829,2],[7835,7841,6],[7843,7935,2],[7936,7943,1],[7952,7957,1],[7968,7975,1],[7984,7991,1],[8e3,8005,1],[8017,8023,2],[8032,8039,1],[8048,8061,1],[8112,8113,1],[8126,8144,18],[8145,8160,15],[8161,8165,4],[8526,8580,54],[11312,11359,1],[11361,11365,4],[11366,11372,2],[11379,11382,3],[11393,11491,2],[11500,11502,2],[11507,11520,13],[11521,11557,1],[11559,11565,6],[42561,42605,2],[42625,42651,2],[42787,42799,2],[42803,42863,2],[42874,42876,2],[42879,42887,2],[42892,42897,5],[42899,42900,1],[42903,42921,2],[42933,42947,2],[42952,42954,2],[42961,42967,6],[42969,42998,29],[43859,43888,29],[43889,43967,1],[65345,65370,1],[66600,66639,1],[66776,66811,1],[66967,66977,1],[66979,66993,1],[66995,67001,1],[67003,67004,1],[68800,68850,1],[71872,71903,1],[93792,93823,1],[125218,125251,1]];static M=[[768,879,1],[1155,1161,1],[1425,1469,1],[1471,1473,2],[1474,1476,2],[1477,1479,2],[1552,1562,1],[1611,1631,1],[1648,1750,102],[1751,1756,1],[1759,1764,1],[1767,1768,1],[1770,1773,1],[1809,1840,31],[1841,1866,1],[1958,1968,1],[2027,2035,1],[2045,2070,25],[2071,2073,1],[2075,2083,1],[2085,2087,1],[2089,2093,1],[2137,2139,1],[2200,2207,1],[2250,2273,1],[2275,2307,1],[2362,2364,1],[2366,2383,1],[2385,2391,1],[2402,2403,1],[2433,2435,1],[2492,2494,2],[2495,2500,1],[2503,2504,1],[2507,2509,1],[2519,2530,11],[2531,2558,27],[2561,2563,1],[2620,2622,2],[2623,2626,1],[2631,2632,1],[2635,2637,1],[2641,2672,31],[2673,2677,4],[2689,2691,1],[2748,2750,2],[2751,2757,1],[2759,2761,1],[2763,2765,1],[2786,2787,1],[2810,2815,1],[2817,2819,1],[2876,2878,2],[2879,2884,1],[2887,2888,1],[2891,2893,1],[2901,2903,1],[2914,2915,1],[2946,3006,60],[3007,3010,1],[3014,3016,1],[3018,3021,1],[3031,3072,41],[3073,3076,1],[3132,3134,2],[3135,3140,1],[3142,3144,1],[3146,3149,1],[3157,3158,1],[3170,3171,1],[3201,3203,1],[3260,3262,2],[3263,3268,1],[3270,3272,1],[3274,3277,1],[3285,3286,1],[3298,3299,1],[3315,3328,13],[3329,3331,1],[3387,3388,1],[3390,3396,1],[3398,3400,1],[3402,3405,1],[3415,3426,11],[3427,3457,30],[3458,3459,1],[3530,3535,5],[3536,3540,1],[3542,3544,2],[3545,3551,1],[3570,3571,1],[3633,3636,3],[3637,3642,1],[3655,3662,1],[3761,3764,3],[3765,3772,1],[3784,3790,1],[3864,3865,1],[3893,3897,2],[3902,3903,1],[3953,3972,1],[3974,3975,1],[3981,3991,1],[3993,4028,1],[4038,4139,101],[4140,4158,1],[4182,4185,1],[4190,4192,1],[4194,4196,1],[4199,4205,1],[4209,4212,1],[4226,4237,1],[4239,4250,11],[4251,4253,1],[4957,4959,1],[5906,5909,1],[5938,5940,1],[5970,5971,1],[6002,6003,1],[6068,6099,1],[6109,6155,46],[6156,6157,1],[6159,6277,118],[6278,6313,35],[6432,6443,1],[6448,6459,1],[6679,6683,1],[6741,6750,1],[6752,6780,1],[6783,6832,49],[6833,6862,1],[6912,6916,1],[6964,6980,1],[7019,7027,1],[7040,7042,1],[7073,7085,1],[7142,7155,1],[7204,7223,1],[7376,7378,1],[7380,7400,1],[7405,7412,7],[7415,7417,1],[7616,7679,1],[8400,8432,1],[11503,11505,1],[11647,11744,97],[11745,11775,1],[12330,12335,1],[12441,12442,1],[42607,42610,1],[42612,42621,1],[42654,42655,1],[42736,42737,1],[43010,43014,4],[43019,43043,24],[43044,43047,1],[43052,43136,84],[43137,43188,51],[43189,43205,1],[43232,43249,1],[43263,43302,39],[43303,43309,1],[43335,43347,1],[43392,43395,1],[43443,43456,1],[43493,43561,68],[43562,43574,1],[43587,43596,9],[43597,43643,46],[43644,43645,1],[43696,43698,2],[43699,43700,1],[43703,43704,1],[43710,43711,1],[43713,43755,42],[43756,43759,1],[43765,43766,1],[44003,44010,1],[44012,44013,1],[64286,65024,738],[65025,65039,1],[65056,65071,1],[66045,66272,227],[66422,66426,1],[68097,68099,1],[68101,68102,1],[68108,68111,1],[68152,68154,1],[68159,68325,166],[68326,68900,574],[68901,68903,1],[69291,69292,1],[69373,69375,1],[69446,69456,1],[69506,69509,1],[69632,69634,1],[69688,69702,1],[69744,69747,3],[69748,69759,11],[69760,69762,1],[69808,69818,1],[69826,69888,62],[69889,69890,1],[69927,69940,1],[69957,69958,1],[70003,70016,13],[70017,70018,1],[70067,70080,1],[70089,70092,1],[70094,70095,1],[70188,70199,1],[70206,70209,3],[70367,70378,1],[70400,70403,1],[70459,70460,1],[70462,70468,1],[70471,70472,1],[70475,70477,1],[70487,70498,11],[70499,70502,3],[70503,70508,1],[70512,70516,1],[70709,70726,1],[70750,70832,82],[70833,70851,1],[71087,71093,1],[71096,71104,1],[71132,71133,1],[71216,71232,1],[71339,71351,1],[71453,71467,1],[71724,71738,1],[71984,71989,1],[71991,71992,1],[71995,71998,1],[72e3,72002,2],[72003,72145,142],[72146,72151,1],[72154,72160,1],[72164,72193,29],[72194,72202,1],[72243,72249,1],[72251,72254,1],[72263,72273,10],[72274,72283,1],[72330,72345,1],[72751,72758,1],[72760,72767,1],[72850,72871,1],[72873,72886,1],[73009,73014,1],[73018,73020,2],[73021,73023,2],[73024,73029,1],[73031,73098,67],[73099,73102,1],[73104,73105,1],[73107,73111,1],[73459,73462,1],[73472,73473,1],[73475,73524,49],[73525,73530,1],[73534,73538,1],[78912,78919,7],[78920,78933,1],[92912,92916,1],[92976,92982,1],[94031,94033,2],[94034,94087,1],[94095,94098,1],[94180,94192,12],[94193,113821,19628],[113822,118528,4706],[118529,118573,1],[118576,118598,1],[119141,119145,1],[119149,119154,1],[119163,119170,1],[119173,119179,1],[119210,119213,1],[119362,119364,1],[121344,121398,1],[121403,121452,1],[121461,121476,15],[121499,121503,1],[121505,121519,1],[122880,122886,1],[122888,122904,1],[122907,122913,1],[122915,122916,1],[122918,122922,1],[123023,123184,161],[123185,123190,1],[123566,123628,62],[123629,123631,1],[124140,124143,1],[125136,125142,1],[125252,125258,1],[917760,917999,1]];static foldM=[[921,953,32],[8126,8126,1]];static Mc=[[2307,2363,56],[2366,2368,1],[2377,2380,1],[2382,2383,1],[2434,2435,1],[2494,2496,1],[2503,2504,1],[2507,2508,1],[2519,2563,44],[2622,2624,1],[2691,2750,59],[2751,2752,1],[2761,2763,2],[2764,2818,54],[2819,2878,59],[2880,2887,7],[2888,2891,3],[2892,2903,11],[3006,3007,1],[3009,3010,1],[3014,3016,1],[3018,3020,1],[3031,3073,42],[3074,3075,1],[3137,3140,1],[3202,3203,1],[3262,3264,2],[3265,3268,1],[3271,3272,1],[3274,3275,1],[3285,3286,1],[3315,3330,15],[3331,3390,59],[3391,3392,1],[3398,3400,1],[3402,3404,1],[3415,3458,43],[3459,3535,76],[3536,3537,1],[3544,3551,1],[3570,3571,1],[3902,3903,1],[3967,4139,172],[4140,4145,5],[4152,4155,3],[4156,4182,26],[4183,4194,11],[4195,4196,1],[4199,4205,1],[4227,4228,1],[4231,4236,1],[4239,4250,11],[4251,4252,1],[5909,5940,31],[6070,6078,8],[6079,6085,1],[6087,6088,1],[6435,6438,1],[6441,6443,1],[6448,6449,1],[6451,6456,1],[6681,6682,1],[6741,6743,2],[6753,6755,2],[6756,6765,9],[6766,6770,1],[6916,6965,49],[6971,6973,2],[6974,6977,1],[6979,6980,1],[7042,7073,31],[7078,7079,1],[7082,7143,61],[7146,7148,1],[7150,7154,4],[7155,7204,49],[7205,7211,1],[7220,7221,1],[7393,7415,22],[12334,12335,1],[43043,43044,1],[43047,43136,89],[43137,43188,51],[43189,43203,1],[43346,43347,1],[43395,43444,49],[43445,43450,5],[43451,43454,3],[43455,43456,1],[43567,43568,1],[43571,43572,1],[43597,43643,46],[43645,43755,110],[43758,43759,1],[43765,44003,238],[44004,44006,2],[44007,44009,2],[44010,44012,2],[69632,69634,2],[69762,69808,46],[69809,69810,1],[69815,69816,1],[69932,69957,25],[69958,70018,60],[70067,70069,1],[70079,70080,1],[70094,70188,94],[70189,70190,1],[70194,70195,1],[70197,70368,171],[70369,70370,1],[70402,70403,1],[70462,70463,1],[70465,70468,1],[70471,70472,1],[70475,70477,1],[70487,70498,11],[70499,70709,210],[70710,70711,1],[70720,70721,1],[70725,70832,107],[70833,70834,1],[70841,70843,2],[70844,70846,1],[70849,71087,238],[71088,71089,1],[71096,71099,1],[71102,71216,114],[71217,71218,1],[71227,71228,1],[71230,71340,110],[71342,71343,1],[71350,71456,106],[71457,71462,5],[71724,71726,1],[71736,71984,248],[71985,71989,1],[71991,71992,1],[71997,72e3,3],[72002,72145,143],[72146,72147,1],[72156,72159,1],[72164,72249,85],[72279,72280,1],[72343,72751,408],[72766,72873,107],[72881,72884,3],[73098,73102,1],[73107,73108,1],[73110,73461,351],[73462,73475,13],[73524,73525,1],[73534,73535,1],[73537,94033,20496],[94034,94087,1],[94192,94193,1],[119141,119142,1],[119149,119154,1]];static Me=[[1160,1161,1],[6846,8413,1567],[8414,8416,1],[8418,8420,1],[42608,42610,1]];static Mn=[[768,879,1],[1155,1159,1],[1425,1469,1],[1471,1473,2],[1474,1476,2],[1477,1479,2],[1552,1562,1],[1611,1631,1],[1648,1750,102],[1751,1756,1],[1759,1764,1],[1767,1768,1],[1770,1773,1],[1809,1840,31],[1841,1866,1],[1958,1968,1],[2027,2035,1],[2045,2070,25],[2071,2073,1],[2075,2083,1],[2085,2087,1],[2089,2093,1],[2137,2139,1],[2200,2207,1],[2250,2273,1],[2275,2306,1],[2362,2364,2],[2369,2376,1],[2381,2385,4],[2386,2391,1],[2402,2403,1],[2433,2492,59],[2497,2500,1],[2509,2530,21],[2531,2558,27],[2561,2562,1],[2620,2625,5],[2626,2631,5],[2632,2635,3],[2636,2637,1],[2641,2672,31],[2673,2677,4],[2689,2690,1],[2748,2753,5],[2754,2757,1],[2759,2760,1],[2765,2786,21],[2787,2810,23],[2811,2815,1],[2817,2876,59],[2879,2881,2],[2882,2884,1],[2893,2901,8],[2902,2914,12],[2915,2946,31],[3008,3021,13],[3072,3076,4],[3132,3134,2],[3135,3136,1],[3142,3144,1],[3146,3149,1],[3157,3158,1],[3170,3171,1],[3201,3260,59],[3263,3270,7],[3276,3277,1],[3298,3299,1],[3328,3329,1],[3387,3388,1],[3393,3396,1],[3405,3426,21],[3427,3457,30],[3530,3538,8],[3539,3540,1],[3542,3633,91],[3636,3642,1],[3655,3662,1],[3761,3764,3],[3765,3772,1],[3784,3790,1],[3864,3865,1],[3893,3897,2],[3953,3966,1],[3968,3972,1],[3974,3975,1],[3981,3991,1],[3993,4028,1],[4038,4141,103],[4142,4144,1],[4146,4151,1],[4153,4154,1],[4157,4158,1],[4184,4185,1],[4190,4192,1],[4209,4212,1],[4226,4229,3],[4230,4237,7],[4253,4957,704],[4958,4959,1],[5906,5908,1],[5938,5939,1],[5970,5971,1],[6002,6003,1],[6068,6069,1],[6071,6077,1],[6086,6089,3],[6090,6099,1],[6109,6155,46],[6156,6157,1],[6159,6277,118],[6278,6313,35],[6432,6434,1],[6439,6440,1],[6450,6457,7],[6458,6459,1],[6679,6680,1],[6683,6742,59],[6744,6750,1],[6752,6754,2],[6757,6764,1],[6771,6780,1],[6783,6832,49],[6833,6845,1],[6847,6862,1],[6912,6915,1],[6964,6966,2],[6967,6970,1],[6972,6978,6],[7019,7027,1],[7040,7041,1],[7074,7077,1],[7080,7081,1],[7083,7085,1],[7142,7144,2],[7145,7149,4],[7151,7153,1],[7212,7219,1],[7222,7223,1],[7376,7378,1],[7380,7392,1],[7394,7400,1],[7405,7412,7],[7416,7417,1],[7616,7679,1],[8400,8412,1],[8417,8421,4],[8422,8432,1],[11503,11505,1],[11647,11744,97],[11745,11775,1],[12330,12333,1],[12441,12442,1],[42607,42612,5],[42613,42621,1],[42654,42655,1],[42736,42737,1],[43010,43014,4],[43019,43045,26],[43046,43052,6],[43204,43205,1],[43232,43249,1],[43263,43302,39],[43303,43309,1],[43335,43345,1],[43392,43394,1],[43443,43446,3],[43447,43449,1],[43452,43453,1],[43493,43561,68],[43562,43566,1],[43569,43570,1],[43573,43574,1],[43587,43596,9],[43644,43696,52],[43698,43700,1],[43703,43704,1],[43710,43711,1],[43713,43756,43],[43757,43766,9],[44005,44008,3],[44013,64286,20273],[65024,65039,1],[65056,65071,1],[66045,66272,227],[66422,66426,1],[68097,68099,1],[68101,68102,1],[68108,68111,1],[68152,68154,1],[68159,68325,166],[68326,68900,574],[68901,68903,1],[69291,69292,1],[69373,69375,1],[69446,69456,1],[69506,69509,1],[69633,69688,55],[69689,69702,1],[69744,69747,3],[69748,69759,11],[69760,69761,1],[69811,69814,1],[69817,69818,1],[69826,69888,62],[69889,69890,1],[69927,69931,1],[69933,69940,1],[70003,70016,13],[70017,70070,53],[70071,70078,1],[70089,70092,1],[70095,70191,96],[70192,70193,1],[70196,70198,2],[70199,70206,7],[70209,70367,158],[70371,70378,1],[70400,70401,1],[70459,70460,1],[70464,70502,38],[70503,70508,1],[70512,70516,1],[70712,70719,1],[70722,70724,1],[70726,70750,24],[70835,70840,1],[70842,70847,5],[70848,70850,2],[70851,71090,239],[71091,71093,1],[71100,71101,1],[71103,71104,1],[71132,71133,1],[71219,71226,1],[71229,71231,2],[71232,71339,107],[71341,71344,3],[71345,71349,1],[71351,71453,102],[71454,71455,1],[71458,71461,1],[71463,71467,1],[71727,71735,1],[71737,71738,1],[71995,71996,1],[71998,72003,5],[72148,72151,1],[72154,72155,1],[72160,72193,33],[72194,72202,1],[72243,72248,1],[72251,72254,1],[72263,72273,10],[72274,72278,1],[72281,72283,1],[72330,72342,1],[72344,72345,1],[72752,72758,1],[72760,72765,1],[72767,72850,83],[72851,72871,1],[72874,72880,1],[72882,72883,1],[72885,72886,1],[73009,73014,1],[73018,73020,2],[73021,73023,2],[73024,73029,1],[73031,73104,73],[73105,73109,4],[73111,73459,348],[73460,73472,12],[73473,73526,53],[73527,73530,1],[73536,73538,2],[78912,78919,7],[78920,78933,1],[92912,92916,1],[92976,92982,1],[94031,94095,64],[94096,94098,1],[94180,113821,19641],[113822,118528,4706],[118529,118573,1],[118576,118598,1],[119143,119145,1],[119163,119170,1],[119173,119179,1],[119210,119213,1],[119362,119364,1],[121344,121398,1],[121403,121452,1],[121461,121476,15],[121499,121503,1],[121505,121519,1],[122880,122886,1],[122888,122904,1],[122907,122913,1],[122915,122916,1],[122918,122922,1],[123023,123184,161],[123185,123190,1],[123566,123628,62],[123629,123631,1],[124140,124143,1],[125136,125142,1],[125252,125258,1],[917760,917999,1]];static foldMn=[[921,953,32],[8126,8126,1]];static N=[[48,57,1],[178,179,1],[185,188,3],[189,190,1],[1632,1641,1],[1776,1785,1],[1984,1993,1],[2406,2415,1],[2534,2543,1],[2548,2553,1],[2662,2671,1],[2790,2799,1],[2918,2927,1],[2930,2935,1],[3046,3058,1],[3174,3183,1],[3192,3198,1],[3302,3311,1],[3416,3422,1],[3430,3448,1],[3558,3567,1],[3664,3673,1],[3792,3801,1],[3872,3891,1],[4160,4169,1],[4240,4249,1],[4969,4988,1],[5870,5872,1],[6112,6121,1],[6128,6137,1],[6160,6169,1],[6470,6479,1],[6608,6618,1],[6784,6793,1],[6800,6809,1],[6992,7001,1],[7088,7097,1],[7232,7241,1],[7248,7257,1],[8304,8308,4],[8309,8313,1],[8320,8329,1],[8528,8578,1],[8581,8585,1],[9312,9371,1],[9450,9471,1],[10102,10131,1],[11517,12295,778],[12321,12329,1],[12344,12346,1],[12690,12693,1],[12832,12841,1],[12872,12879,1],[12881,12895,1],[12928,12937,1],[12977,12991,1],[42528,42537,1],[42726,42735,1],[43056,43061,1],[43216,43225,1],[43264,43273,1],[43472,43481,1],[43504,43513,1],[43600,43609,1],[44016,44025,1],[65296,65305,1],[65799,65843,1],[65856,65912,1],[65930,65931,1],[66273,66299,1],[66336,66339,1],[66369,66378,9],[66513,66517,1],[66720,66729,1],[67672,67679,1],[67705,67711,1],[67751,67759,1],[67835,67839,1],[67862,67867,1],[68028,68029,1],[68032,68047,1],[68050,68095,1],[68160,68168,1],[68221,68222,1],[68253,68255,1],[68331,68335,1],[68440,68447,1],[68472,68479,1],[68521,68527,1],[68858,68863,1],[68912,68921,1],[69216,69246,1],[69405,69414,1],[69457,69460,1],[69573,69579,1],[69714,69743,1],[69872,69881,1],[69942,69951,1],[70096,70105,1],[70113,70132,1],[70384,70393,1],[70736,70745,1],[70864,70873,1],[71248,71257,1],[71360,71369,1],[71472,71483,1],[71904,71922,1],[72016,72025,1],[72784,72812,1],[73040,73049,1],[73120,73129,1],[73552,73561,1],[73664,73684,1],[74752,74862,1],[92768,92777,1],[92864,92873,1],[93008,93017,1],[93019,93025,1],[93824,93846,1],[119488,119507,1],[119520,119539,1],[119648,119672,1],[120782,120831,1],[123200,123209,1],[123632,123641,1],[124144,124153,1],[125127,125135,1],[125264,125273,1],[126065,126123,1],[126125,126127,1],[126129,126132,1],[126209,126253,1],[126255,126269,1],[127232,127244,1],[130032,130041,1]];static Nd=[[48,57,1],[1632,1641,1],[1776,1785,1],[1984,1993,1],[2406,2415,1],[2534,2543,1],[2662,2671,1],[2790,2799,1],[2918,2927,1],[3046,3055,1],[3174,3183,1],[3302,3311,1],[3430,3439,1],[3558,3567,1],[3664,3673,1],[3792,3801,1],[3872,3881,1],[4160,4169,1],[4240,4249,1],[6112,6121,1],[6160,6169,1],[6470,6479,1],[6608,6617,1],[6784,6793,1],[6800,6809,1],[6992,7001,1],[7088,7097,1],[7232,7241,1],[7248,7257,1],[42528,42537,1],[43216,43225,1],[43264,43273,1],[43472,43481,1],[43504,43513,1],[43600,43609,1],[44016,44025,1],[65296,65305,1],[66720,66729,1],[68912,68921,1],[69734,69743,1],[69872,69881,1],[69942,69951,1],[70096,70105,1],[70384,70393,1],[70736,70745,1],[70864,70873,1],[71248,71257,1],[71360,71369,1],[71472,71481,1],[71904,71913,1],[72016,72025,1],[72784,72793,1],[73040,73049,1],[73120,73129,1],[73552,73561,1],[92768,92777,1],[92864,92873,1],[93008,93017,1],[120782,120831,1],[123200,123209,1],[123632,123641,1],[124144,124153,1],[125264,125273,1],[130032,130041,1]];static Nl=[[5870,5872,1],[8544,8578,1],[8581,8584,1],[12295,12321,26],[12322,12329,1],[12344,12346,1],[42726,42735,1],[65856,65908,1],[66369,66378,9],[66513,66517,1],[74752,74862,1]];static No=[[178,179,1],[185,188,3],[189,190,1],[2548,2553,1],[2930,2935,1],[3056,3058,1],[3192,3198,1],[3416,3422,1],[3440,3448,1],[3882,3891,1],[4969,4988,1],[6128,6137,1],[6618,8304,1686],[8308,8313,1],[8320,8329,1],[8528,8543,1],[8585,9312,727],[9313,9371,1],[9450,9471,1],[10102,10131,1],[11517,12690,1173],[12691,12693,1],[12832,12841,1],[12872,12879,1],[12881,12895,1],[12928,12937,1],[12977,12991,1],[43056,43061,1],[65799,65843,1],[65909,65912,1],[65930,65931,1],[66273,66299,1],[66336,66339,1],[67672,67679,1],[67705,67711,1],[67751,67759,1],[67835,67839,1],[67862,67867,1],[68028,68029,1],[68032,68047,1],[68050,68095,1],[68160,68168,1],[68221,68222,1],[68253,68255,1],[68331,68335,1],[68440,68447,1],[68472,68479,1],[68521,68527,1],[68858,68863,1],[69216,69246,1],[69405,69414,1],[69457,69460,1],[69573,69579,1],[69714,69733,1],[70113,70132,1],[71482,71483,1],[71914,71922,1],[72794,72812,1],[73664,73684,1],[93019,93025,1],[93824,93846,1],[119488,119507,1],[119520,119539,1],[119648,119672,1],[125127,125135,1],[126065,126123,1],[126125,126127,1],[126129,126132,1],[126209,126253,1],[126255,126269,1],[127232,127244,1]];static P=[[33,35,1],[37,42,1],[44,47,1],[58,59,1],[63,64,1],[91,93,1],[95,123,28],[125,161,36],[167,171,4],[182,183,1],[187,191,4],[894,903,9],[1370,1375,1],[1417,1418,1],[1470,1472,2],[1475,1478,3],[1523,1524,1],[1545,1546,1],[1548,1549,1],[1563,1565,2],[1566,1567,1],[1642,1645,1],[1748,1792,44],[1793,1805,1],[2039,2041,1],[2096,2110,1],[2142,2404,262],[2405,2416,11],[2557,2678,121],[2800,3191,391],[3204,3572,368],[3663,3674,11],[3675,3844,169],[3845,3858,1],[3860,3898,38],[3899,3901,1],[3973,4048,75],[4049,4052,1],[4057,4058,1],[4170,4175,1],[4347,4960,613],[4961,4968,1],[5120,5742,622],[5787,5788,1],[5867,5869,1],[5941,5942,1],[6100,6102,1],[6104,6106,1],[6144,6154,1],[6468,6469,1],[6686,6687,1],[6816,6822,1],[6824,6829,1],[7002,7008,1],[7037,7038,1],[7164,7167,1],[7227,7231,1],[7294,7295,1],[7360,7367,1],[7379,8208,829],[8209,8231,1],[8240,8259,1],[8261,8273,1],[8275,8286,1],[8317,8318,1],[8333,8334,1],[8968,8971,1],[9001,9002,1],[10088,10101,1],[10181,10182,1],[10214,10223,1],[10627,10648,1],[10712,10715,1],[10748,10749,1],[11513,11516,1],[11518,11519,1],[11632,11776,144],[11777,11822,1],[11824,11855,1],[11858,11869,1],[12289,12291,1],[12296,12305,1],[12308,12319,1],[12336,12349,13],[12448,12539,91],[42238,42239,1],[42509,42511,1],[42611,42622,11],[42738,42743,1],[43124,43127,1],[43214,43215,1],[43256,43258,1],[43260,43310,50],[43311,43359,48],[43457,43469,1],[43486,43487,1],[43612,43615,1],[43742,43743,1],[43760,43761,1],[44011,64830,20819],[64831,65040,209],[65041,65049,1],[65072,65106,1],[65108,65121,1],[65123,65128,5],[65130,65131,1],[65281,65283,1],[65285,65290,1],[65292,65295,1],[65306,65307,1],[65311,65312,1],[65339,65341,1],[65343,65371,28],[65373,65375,2],[65376,65381,1],[65792,65794,1],[66463,66512,49],[66927,67671,744],[67871,67903,32],[68176,68184,1],[68223,68336,113],[68337,68342,1],[68409,68415,1],[68505,68508,1],[69293,69461,168],[69462,69465,1],[69510,69513,1],[69703,69709,1],[69819,69820,1],[69822,69825,1],[69952,69955,1],[70004,70005,1],[70085,70088,1],[70093,70107,14],[70109,70111,1],[70200,70205,1],[70313,70731,418],[70732,70735,1],[70746,70747,1],[70749,70854,105],[71105,71127,1],[71233,71235,1],[71264,71276,1],[71353,71484,131],[71485,71486,1],[71739,72004,265],[72005,72006,1],[72162,72255,93],[72256,72262,1],[72346,72348,1],[72350,72354,1],[72448,72457,1],[72769,72773,1],[72816,72817,1],[73463,73464,1],[73539,73551,1],[73727,74864,1137],[74865,74868,1],[77809,77810,1],[92782,92783,1],[92917,92983,66],[92984,92987,1],[92996,93847,851],[93848,93850,1],[94178,113823,19645],[121479,121483,1],[125278,125279,1]];static Pc=[[95,8255,8160],[8256,8276,20],[65075,65076,1],[65101,65103,1],[65343,65343,1]];static Pd=[[45,1418,1373],[1470,5120,3650],[6150,8208,2058],[8209,8213,1],[11799,11802,3],[11834,11835,1],[11840,11869,29],[12316,12336,20],[12448,65073,52625],[65074,65112,38],[65123,65293,170],[69293,69293,1]];static Pe=[[41,93,52],[125,3899,3774],[3901,5788,1887],[8262,8318,56],[8334,8969,635],[8971,9002,31],[10089,10101,2],[10182,10215,33],[10217,10223,2],[10628,10648,2],[10713,10715,2],[10749,11811,1062],[11813,11817,2],[11862,11868,2],[12297,12305,2],[12309,12315,2],[12318,12319,1],[64830,65048,218],[65078,65092,2],[65096,65114,18],[65116,65118,2],[65289,65341,52],[65373,65379,3]];static Pf=[[187,8217,8030],[8221,8250,29],[11779,11781,2],[11786,11789,3],[11805,11809,4]];static Pi=[[171,8216,8045],[8219,8220,1],[8223,8249,26],[11778,11780,2],[11785,11788,3],[11804,11808,4]];static Po=[[33,35,1],[37,39,1],[42,46,2],[47,58,11],[59,63,4],[64,92,28],[161,167,6],[182,183,1],[191,894,703],[903,1370,467],[1371,1375,1],[1417,1472,55],[1475,1478,3],[1523,1524,1],[1545,1546,1],[1548,1549,1],[1563,1565,2],[1566,1567,1],[1642,1645,1],[1748,1792,44],[1793,1805,1],[2039,2041,1],[2096,2110,1],[2142,2404,262],[2405,2416,11],[2557,2678,121],[2800,3191,391],[3204,3572,368],[3663,3674,11],[3675,3844,169],[3845,3858,1],[3860,3973,113],[4048,4052,1],[4057,4058,1],[4170,4175,1],[4347,4960,613],[4961,4968,1],[5742,5867,125],[5868,5869,1],[5941,5942,1],[6100,6102,1],[6104,6106,1],[6144,6149,1],[6151,6154,1],[6468,6469,1],[6686,6687,1],[6816,6822,1],[6824,6829,1],[7002,7008,1],[7037,7038,1],[7164,7167,1],[7227,7231,1],[7294,7295,1],[7360,7367,1],[7379,8214,835],[8215,8224,9],[8225,8231,1],[8240,8248,1],[8251,8254,1],[8257,8259,1],[8263,8273,1],[8275,8277,2],[8278,8286,1],[11513,11516,1],[11518,11519,1],[11632,11776,144],[11777,11782,5],[11783,11784,1],[11787,11790,3],[11791,11798,1],[11800,11801,1],[11803,11806,3],[11807,11818,11],[11819,11822,1],[11824,11833,1],[11836,11839,1],[11841,11843,2],[11844,11855,1],[11858,11860,1],[12289,12291,1],[12349,12539,190],[42238,42239,1],[42509,42511,1],[42611,42622,11],[42738,42743,1],[43124,43127,1],[43214,43215,1],[43256,43258,1],[43260,43310,50],[43311,43359,48],[43457,43469,1],[43486,43487,1],[43612,43615,1],[43742,43743,1],[43760,43761,1],[44011,65040,21029],[65041,65046,1],[65049,65072,23],[65093,65094,1],[65097,65100,1],[65104,65106,1],[65108,65111,1],[65119,65121,1],[65128,65130,2],[65131,65281,150],[65282,65283,1],[65285,65287,1],[65290,65294,2],[65295,65306,11],[65307,65311,4],[65312,65340,28],[65377,65380,3],[65381,65792,411],[65793,65794,1],[66463,66512,49],[66927,67671,744],[67871,67903,32],[68176,68184,1],[68223,68336,113],[68337,68342,1],[68409,68415,1],[68505,68508,1],[69461,69465,1],[69510,69513,1],[69703,69709,1],[69819,69820,1],[69822,69825,1],[69952,69955,1],[70004,70005,1],[70085,70088,1],[70093,70107,14],[70109,70111,1],[70200,70205,1],[70313,70731,418],[70732,70735,1],[70746,70747,1],[70749,70854,105],[71105,71127,1],[71233,71235,1],[71264,71276,1],[71353,71484,131],[71485,71486,1],[71739,72004,265],[72005,72006,1],[72162,72255,93],[72256,72262,1],[72346,72348,1],[72350,72354,1],[72448,72457,1],[72769,72773,1],[72816,72817,1],[73463,73464,1],[73539,73551,1],[73727,74864,1137],[74865,74868,1],[77809,77810,1],[92782,92783,1],[92917,92983,66],[92984,92987,1],[92996,93847,851],[93848,93850,1],[94178,113823,19645],[121479,121483,1],[125278,125279,1]];static Ps=[[40,91,51],[123,3898,3775],[3900,5787,1887],[8218,8222,4],[8261,8317,56],[8333,8968,635],[8970,9001,31],[10088,10100,2],[10181,10214,33],[10216,10222,2],[10627,10647,2],[10712,10714,2],[10748,11810,1062],[11812,11816,2],[11842,11861,19],[11863,11867,2],[12296,12304,2],[12308,12314,2],[12317,64831,52514],[65047,65077,30],[65079,65091,2],[65095,65113,18],[65115,65117,2],[65288,65339,51],[65371,65375,4],[65378,65378,1]];static S=[[36,43,7],[60,62,1],[94,96,2],[124,126,2],[162,166,1],[168,169,1],[172,174,2],[175,177,1],[180,184,4],[215,247,32],[706,709,1],[722,735,1],[741,747,1],[749,751,2],[752,767,1],[885,900,15],[901,1014,113],[1154,1421,267],[1422,1423,1],[1542,1544,1],[1547,1550,3],[1551,1758,207],[1769,1789,20],[1790,2038,248],[2046,2047,1],[2184,2546,362],[2547,2554,7],[2555,2801,246],[2928,3059,131],[3060,3066,1],[3199,3407,208],[3449,3647,198],[3841,3843,1],[3859,3861,2],[3862,3863,1],[3866,3871,1],[3892,3896,2],[4030,4037,1],[4039,4044,1],[4046,4047,1],[4053,4056,1],[4254,4255,1],[5008,5017,1],[5741,6107,366],[6464,6622,158],[6623,6655,1],[7009,7018,1],[7028,7036,1],[8125,8127,2],[8128,8129,1],[8141,8143,1],[8157,8159,1],[8173,8175,1],[8189,8190,1],[8260,8274,14],[8314,8316,1],[8330,8332,1],[8352,8384,1],[8448,8449,1],[8451,8454,1],[8456,8457,1],[8468,8470,2],[8471,8472,1],[8478,8483,1],[8485,8489,2],[8494,8506,12],[8507,8512,5],[8513,8516,1],[8522,8525,1],[8527,8586,59],[8587,8592,5],[8593,8967,1],[8972,9e3,1],[9003,9254,1],[9280,9290,1],[9372,9449,1],[9472,10087,1],[10132,10180,1],[10183,10213,1],[10224,10626,1],[10649,10711,1],[10716,10747,1],[10750,11123,1],[11126,11157,1],[11159,11263,1],[11493,11498,1],[11856,11857,1],[11904,11929,1],[11931,12019,1],[12032,12245,1],[12272,12287,1],[12292,12306,14],[12307,12320,13],[12342,12343,1],[12350,12351,1],[12443,12444,1],[12688,12689,1],[12694,12703,1],[12736,12771,1],[12783,12800,17],[12801,12830,1],[12842,12871,1],[12880,12896,16],[12897,12927,1],[12938,12976,1],[12992,13311,1],[19904,19967,1],[42128,42182,1],[42752,42774,1],[42784,42785,1],[42889,42890,1],[43048,43051,1],[43062,43065,1],[43639,43641,1],[43867,43882,15],[43883,64297,20414],[64434,64450,1],[64832,64847,1],[64975,65020,45],[65021,65023,1],[65122,65124,2],[65125,65126,1],[65129,65284,155],[65291,65308,17],[65309,65310,1],[65342,65344,2],[65372,65374,2],[65504,65510,1],[65512,65518,1],[65532,65533,1],[65847,65855,1],[65913,65929,1],[65932,65934,1],[65936,65948,1],[65952,66e3,48],[66001,66044,1],[67703,67704,1],[68296,71487,3191],[73685,73713,1],[92988,92991,1],[92997,113820,20823],[118608,118723,1],[118784,119029,1],[119040,119078,1],[119081,119140,1],[119146,119148,1],[119171,119172,1],[119180,119209,1],[119214,119274,1],[119296,119361,1],[119365,119552,187],[119553,119638,1],[120513,120539,26],[120571,120597,26],[120629,120655,26],[120687,120713,26],[120745,120771,26],[120832,121343,1],[121399,121402,1],[121453,121460,1],[121462,121475,1],[121477,121478,1],[123215,123647,432],[126124,126128,4],[126254,126704,450],[126705,126976,271],[126977,127019,1],[127024,127123,1],[127136,127150,1],[127153,127167,1],[127169,127183,1],[127185,127221,1],[127245,127405,1],[127462,127490,1],[127504,127547,1],[127552,127560,1],[127568,127569,1],[127584,127589,1],[127744,128727,1],[128732,128748,1],[128752,128764,1],[128768,128886,1],[128891,128985,1],[128992,129003,1],[129008,129024,16],[129025,129035,1],[129040,129095,1],[129104,129113,1],[129120,129159,1],[129168,129197,1],[129200,129201,1],[129280,129619,1],[129632,129645,1],[129648,129660,1],[129664,129672,1],[129680,129725,1],[129727,129733,1],[129742,129755,1],[129760,129768,1],[129776,129784,1],[129792,129938,1],[129940,129994,1]];static Sc=[[36,162,126],[163,165,1],[1423,1547,124],[2046,2047,1],[2546,2547,1],[2555,2801,246],[3065,3647,582],[6107,8352,2245],[8353,8384,1],[43064,65020,21956],[65129,65284,155],[65504,65505,1],[65509,65510,1],[73693,73696,1],[123647,126128,2481]];static Sk=[[94,96,2],[168,175,7],[180,184,4],[706,709,1],[722,735,1],[741,747,1],[749,751,2],[752,767,1],[885,900,15],[901,2184,1283],[8125,8127,2],[8128,8129,1],[8141,8143,1],[8157,8159,1],[8173,8175,1],[8189,8190,1],[12443,12444,1],[42752,42774,1],[42784,42785,1],[42889,42890,1],[43867,43882,15],[43883,64434,20551],[64435,64450,1],[65342,65344,2],[65507,127995,62488],[127996,127999,1]];static Sm=[[43,60,17],[61,62,1],[124,126,2],[172,177,5],[215,247,32],[1014,1542,528],[1543,1544,1],[8260,8274,14],[8314,8316,1],[8330,8332,1],[8472,8512,40],[8513,8516,1],[8523,8592,69],[8593,8596,1],[8602,8603,1],[8608,8614,3],[8622,8654,32],[8655,8658,3],[8660,8692,32],[8693,8959,1],[8992,8993,1],[9084,9115,31],[9116,9139,1],[9180,9185,1],[9655,9665,10],[9720,9727,1],[9839,10176,337],[10177,10180,1],[10183,10213,1],[10224,10239,1],[10496,10626,1],[10649,10711,1],[10716,10747,1],[10750,11007,1],[11056,11076,1],[11079,11084,1],[64297,65122,825],[65124,65126,1],[65291,65308,17],[65309,65310,1],[65372,65374,2],[65506,65513,7],[65514,65516,1],[120513,120539,26],[120571,120597,26],[120629,120655,26],[120687,120713,26],[120745,120771,26],[126704,126705,1]];static So=[[166,169,3],[174,176,2],[1154,1421,267],[1422,1550,128],[1551,1758,207],[1769,1789,20],[1790,2038,248],[2554,2928,374],[3059,3064,1],[3066,3199,133],[3407,3449,42],[3841,3843,1],[3859,3861,2],[3862,3863,1],[3866,3871,1],[3892,3896,2],[4030,4037,1],[4039,4044,1],[4046,4047,1],[4053,4056,1],[4254,4255,1],[5008,5017,1],[5741,6464,723],[6622,6655,1],[7009,7018,1],[7028,7036,1],[8448,8449,1],[8451,8454,1],[8456,8457,1],[8468,8470,2],[8471,8478,7],[8479,8483,1],[8485,8489,2],[8494,8506,12],[8507,8522,15],[8524,8525,1],[8527,8586,59],[8587,8597,10],[8598,8601,1],[8604,8607,1],[8609,8610,1],[8612,8613,1],[8615,8621,1],[8623,8653,1],[8656,8657,1],[8659,8661,2],[8662,8691,1],[8960,8967,1],[8972,8991,1],[8994,9e3,1],[9003,9083,1],[9085,9114,1],[9140,9179,1],[9186,9254,1],[9280,9290,1],[9372,9449,1],[9472,9654,1],[9656,9664,1],[9666,9719,1],[9728,9838,1],[9840,10087,1],[10132,10175,1],[10240,10495,1],[11008,11055,1],[11077,11078,1],[11085,11123,1],[11126,11157,1],[11159,11263,1],[11493,11498,1],[11856,11857,1],[11904,11929,1],[11931,12019,1],[12032,12245,1],[12272,12287,1],[12292,12306,14],[12307,12320,13],[12342,12343,1],[12350,12351,1],[12688,12689,1],[12694,12703,1],[12736,12771,1],[12783,12800,17],[12801,12830,1],[12842,12871,1],[12880,12896,16],[12897,12927,1],[12938,12976,1],[12992,13311,1],[19904,19967,1],[42128,42182,1],[43048,43051,1],[43062,43063,1],[43065,43639,574],[43640,43641,1],[64832,64847,1],[64975,65021,46],[65022,65023,1],[65508,65512,4],[65517,65518,1],[65532,65533,1],[65847,65855,1],[65913,65929,1],[65932,65934,1],[65936,65948,1],[65952,66e3,48],[66001,66044,1],[67703,67704,1],[68296,71487,3191],[73685,73692,1],[73697,73713,1],[92988,92991,1],[92997,113820,20823],[118608,118723,1],[118784,119029,1],[119040,119078,1],[119081,119140,1],[119146,119148,1],[119171,119172,1],[119180,119209,1],[119214,119274,1],[119296,119361,1],[119365,119552,187],[119553,119638,1],[120832,121343,1],[121399,121402,1],[121453,121460,1],[121462,121475,1],[121477,121478,1],[123215,126124,2909],[126254,126976,722],[126977,127019,1],[127024,127123,1],[127136,127150,1],[127153,127167,1],[127169,127183,1],[127185,127221,1],[127245,127405,1],[127462,127490,1],[127504,127547,1],[127552,127560,1],[127568,127569,1],[127584,127589,1],[127744,127994,1],[128e3,128727,1],[128732,128748,1],[128752,128764,1],[128768,128886,1],[128891,128985,1],[128992,129003,1],[129008,129024,16],[129025,129035,1],[129040,129095,1],[129104,129113,1],[129120,129159,1],[129168,129197,1],[129200,129201,1],[129280,129619,1],[129632,129645,1],[129648,129660,1],[129664,129672,1],[129680,129725,1],[129727,129733,1],[129742,129755,1],[129760,129768,1],[129776,129784,1],[129792,129938,1],[129940,129994,1]];static Z=[[32,160,128],[5760,8192,2432],[8193,8202,1],[8232,8233,1],[8239,8287,48],[12288,12288,1]];static Zl=[[8232,8232,1]];static Zp=[[8233,8233,1]];static Zs=[[32,160,128],[5760,8192,2432],[8193,8202,1],[8239,8287,48],[12288,12288,1]];static Adlam=[[125184,125259,1],[125264,125273,1],[125278,125279,1]];static Ahom=[[71424,71450,1],[71453,71467,1],[71472,71494,1]];static Anatolian_Hieroglyphs=[[82944,83526,1]];static Arabic=[[1536,1540,1],[1542,1547,1],[1549,1562,1],[1564,1566,1],[1568,1599,1],[1601,1610,1],[1622,1647,1],[1649,1756,1],[1758,1791,1],[1872,1919,1],[2160,2190,1],[2192,2193,1],[2200,2273,1],[2275,2303,1],[64336,64450,1],[64467,64829,1],[64832,64911,1],[64914,64967,1],[64975,65008,33],[65009,65023,1],[65136,65140,1],[65142,65276,1],[69216,69246,1],[69373,69375,1],[126464,126467,1],[126469,126495,1],[126497,126498,1],[126500,126503,3],[126505,126514,1],[126516,126519,1],[126521,126523,2],[126530,126535,5],[126537,126541,2],[126542,126543,1],[126545,126546,1],[126548,126551,3],[126553,126561,2],[126562,126564,2],[126567,126570,1],[126572,126578,1],[126580,126583,1],[126585,126588,1],[126590,126592,2],[126593,126601,1],[126603,126619,1],[126625,126627,1],[126629,126633,1],[126635,126651,1],[126704,126705,1]];static Armenian=[[1329,1366,1],[1369,1418,1],[1421,1423,1],[64275,64279,1]];static Avestan=[[68352,68405,1],[68409,68415,1]];static Balinese=[[6912,6988,1],[6992,7038,1]];static Bamum=[[42656,42743,1],[92160,92728,1]];static Bassa_Vah=[[92880,92909,1],[92912,92917,1]];static Batak=[[7104,7155,1],[7164,7167,1]];static Bengali=[[2432,2435,1],[2437,2444,1],[2447,2448,1],[2451,2472,1],[2474,2480,1],[2482,2486,4],[2487,2489,1],[2492,2500,1],[2503,2504,1],[2507,2510,1],[2519,2524,5],[2525,2527,2],[2528,2531,1],[2534,2558,1]];static Bhaiksuki=[[72704,72712,1],[72714,72758,1],[72760,72773,1],[72784,72812,1]];static Bopomofo=[[746,747,1],[12549,12591,1],[12704,12735,1]];static Brahmi=[[69632,69709,1],[69714,69749,1],[69759,69759,1]];static Braille=[[10240,10495,1]];static Buginese=[[6656,6683,1],[6686,6687,1]];static Buhid=[[5952,5971,1]];static Canadian_Aboriginal=[[5120,5759,1],[6320,6389,1],[72368,72383,1]];static Carian=[[66208,66256,1]];static Caucasian_Albanian=[[66864,66915,1],[66927,66927,1]];static Chakma=[[69888,69940,1],[69942,69959,1]];static Cham=[[43520,43574,1],[43584,43597,1],[43600,43609,1],[43612,43615,1]];static Cherokee=[[5024,5109,1],[5112,5117,1],[43888,43967,1]];static Chorasmian=[[69552,69579,1]];static Common=[[0,64,1],[91,96,1],[123,169,1],[171,185,1],[187,191,1],[215,247,32],[697,735,1],[741,745,1],[748,767,1],[884,894,10],[901,903,2],[1541,1548,7],[1563,1567,4],[1600,1757,157],[2274,2404,130],[2405,3647,1242],[4053,4056,1],[4347,5867,1520],[5868,5869,1],[5941,5942,1],[6146,6147,1],[6149,7379,1230],[7393,7401,8],[7402,7404,1],[7406,7411,1],[7413,7415,1],[7418,8192,774],[8193,8203,1],[8206,8292,1],[8294,8304,1],[8308,8318,1],[8320,8334,1],[8352,8384,1],[8448,8485,1],[8487,8489,1],[8492,8497,1],[8499,8525,1],[8527,8543,1],[8585,8587,1],[8592,9254,1],[9280,9290,1],[9312,10239,1],[10496,11123,1],[11126,11157,1],[11159,11263,1],[11776,11869,1],[12272,12292,1],[12294,12296,2],[12297,12320,1],[12336,12343,1],[12348,12351,1],[12443,12444,1],[12448,12539,91],[12540,12688,148],[12689,12703,1],[12736,12771,1],[12783,12832,49],[12833,12895,1],[12927,13007,1],[13055,13144,89],[13145,13311,1],[19904,19967,1],[42752,42785,1],[42888,42890,1],[43056,43065,1],[43310,43471,161],[43867,43882,15],[43883,64830,20947],[64831,65040,209],[65041,65049,1],[65072,65106,1],[65108,65126,1],[65128,65131,1],[65279,65281,2],[65282,65312,1],[65339,65344,1],[65371,65381,1],[65392,65438,46],[65439,65504,65],[65505,65510,1],[65512,65518,1],[65529,65533,1],[65792,65794,1],[65799,65843,1],[65847,65855,1],[65936,65948,1],[66e3,66044,1],[66273,66299,1],[113824,113827,1],[118608,118723,1],[118784,119029,1],[119040,119078,1],[119081,119142,1],[119146,119162,1],[119171,119172,1],[119180,119209,1],[119214,119274,1],[119488,119507,1],[119520,119539,1],[119552,119638,1],[119648,119672,1],[119808,119892,1],[119894,119964,1],[119966,119967,1],[119970,119973,3],[119974,119977,3],[119978,119980,1],[119982,119993,1],[119995,119997,2],[119998,120003,1],[120005,120069,1],[120071,120074,1],[120077,120084,1],[120086,120092,1],[120094,120121,1],[120123,120126,1],[120128,120132,1],[120134,120138,4],[120139,120144,1],[120146,120485,1],[120488,120779,1],[120782,120831,1],[126065,126132,1],[126209,126269,1],[126976,127019,1],[127024,127123,1],[127136,127150,1],[127153,127167,1],[127169,127183,1],[127185,127221,1],[127232,127405,1],[127462,127487,1],[127489,127490,1],[127504,127547,1],[127552,127560,1],[127568,127569,1],[127584,127589,1],[127744,128727,1],[128732,128748,1],[128752,128764,1],[128768,128886,1],[128891,128985,1],[128992,129003,1],[129008,129024,16],[129025,129035,1],[129040,129095,1],[129104,129113,1],[129120,129159,1],[129168,129197,1],[129200,129201,1],[129280,129619,1],[129632,129645,1],[129648,129660,1],[129664,129672,1],[129680,129725,1],[129727,129733,1],[129742,129755,1],[129760,129768,1],[129776,129784,1],[129792,129938,1],[129940,129994,1],[130032,130041,1],[917505,917536,31],[917537,917631,1]];static foldCommon=[[924,956,32]];static Coptic=[[994,1007,1],[11392,11507,1],[11513,11519,1]];static Cuneiform=[[73728,74649,1],[74752,74862,1],[74864,74868,1],[74880,75075,1]];static Cypriot=[[67584,67589,1],[67592,67594,2],[67595,67637,1],[67639,67640,1],[67644,67647,3]];static Cypro_Minoan=[[77712,77810,1]];static Cyrillic=[[1024,1156,1],[1159,1327,1],[7296,7304,1],[7467,7544,77],[11744,11775,1],[42560,42655,1],[65070,65071,1],[122928,122989,1],[123023,123023,1]];static Deseret=[[66560,66639,1]];static Devanagari=[[2304,2384,1],[2389,2403,1],[2406,2431,1],[43232,43263,1],[72448,72457,1]];static Dives_Akuru=[[71936,71942,1],[71945,71948,3],[71949,71955,1],[71957,71958,1],[71960,71989,1],[71991,71992,1],[71995,72006,1],[72016,72025,1]];static Dogra=[[71680,71739,1]];static Duployan=[[113664,113770,1],[113776,113788,1],[113792,113800,1],[113808,113817,1],[113820,113823,1]];static Egyptian_Hieroglyphs=[[77824,78933,1]];static Elbasan=[[66816,66855,1]];static Elymaic=[[69600,69622,1]];static Ethiopic=[[4608,4680,1],[4682,4685,1],[4688,4694,1],[4696,4698,2],[4699,4701,1],[4704,4744,1],[4746,4749,1],[4752,4784,1],[4786,4789,1],[4792,4798,1],[4800,4802,2],[4803,4805,1],[4808,4822,1],[4824,4880,1],[4882,4885,1],[4888,4954,1],[4957,4988,1],[4992,5017,1],[11648,11670,1],[11680,11686,1],[11688,11694,1],[11696,11702,1],[11704,11710,1],[11712,11718,1],[11720,11726,1],[11728,11734,1],[11736,11742,1],[43777,43782,1],[43785,43790,1],[43793,43798,1],[43808,43814,1],[43816,43822,1],[124896,124902,1],[124904,124907,1],[124909,124910,1],[124912,124926,1]];static Georgian=[[4256,4293,1],[4295,4301,6],[4304,4346,1],[4348,4351,1],[7312,7354,1],[7357,7359,1],[11520,11557,1],[11559,11565,6]];static Glagolitic=[[11264,11359,1],[122880,122886,1],[122888,122904,1],[122907,122913,1],[122915,122916,1],[122918,122922,1]];static Gothic=[[66352,66378,1]];static Grantha=[[70400,70403,1],[70405,70412,1],[70415,70416,1],[70419,70440,1],[70442,70448,1],[70450,70451,1],[70453,70457,1],[70460,70468,1],[70471,70472,1],[70475,70477,1],[70480,70487,7],[70493,70499,1],[70502,70508,1],[70512,70516,1]];static Greek=[[880,883,1],[885,887,1],[890,893,1],[895,900,5],[902,904,2],[905,906,1],[908,910,2],[911,929,1],[931,993,1],[1008,1023,1],[7462,7466,1],[7517,7521,1],[7526,7530,1],[7615,7936,321],[7937,7957,1],[7960,7965,1],[7968,8005,1],[8008,8013,1],[8016,8023,1],[8025,8031,2],[8032,8061,1],[8064,8116,1],[8118,8132,1],[8134,8147,1],[8150,8155,1],[8157,8175,1],[8178,8180,1],[8182,8190,1],[8486,43877,35391],[65856,65934,1],[65952,119296,53344],[119297,119365,1]];static foldGreek=[[181,837,656]];static Gujarati=[[2689,2691,1],[2693,2701,1],[2703,2705,1],[2707,2728,1],[2730,2736,1],[2738,2739,1],[2741,2745,1],[2748,2757,1],[2759,2761,1],[2763,2765,1],[2768,2784,16],[2785,2787,1],[2790,2801,1],[2809,2815,1]];static Gunjala_Gondi=[[73056,73061,1],[73063,73064,1],[73066,73102,1],[73104,73105,1],[73107,73112,1],[73120,73129,1]];static Gurmukhi=[[2561,2563,1],[2565,2570,1],[2575,2576,1],[2579,2600,1],[2602,2608,1],[2610,2611,1],[2613,2614,1],[2616,2617,1],[2620,2622,2],[2623,2626,1],[2631,2632,1],[2635,2637,1],[2641,2649,8],[2650,2652,1],[2654,2662,8],[2663,2678,1]];static Han=[[11904,11929,1],[11931,12019,1],[12032,12245,1],[12293,12295,2],[12321,12329,1],[12344,12347,1],[13312,19903,1],[19968,40959,1],[63744,64109,1],[64112,64217,1],[94178,94179,1],[94192,94193,1],[131072,173791,1],[173824,177977,1],[177984,178205,1],[178208,183969,1],[183984,191456,1],[191472,192093,1],[194560,195101,1],[196608,201546,1],[201552,205743,1]];static Hangul=[[4352,4607,1],[12334,12335,1],[12593,12686,1],[12800,12830,1],[12896,12926,1],[43360,43388,1],[44032,55203,1],[55216,55238,1],[55243,55291,1],[65440,65470,1],[65474,65479,1],[65482,65487,1],[65490,65495,1],[65498,65500,1]];static Hanifi_Rohingya=[[68864,68903,1],[68912,68921,1]];static Hanunoo=[[5920,5940,1]];static Hatran=[[67808,67826,1],[67828,67829,1],[67835,67839,1]];static Hebrew=[[1425,1479,1],[1488,1514,1],[1519,1524,1],[64285,64310,1],[64312,64316,1],[64318,64320,2],[64321,64323,2],[64324,64326,2],[64327,64335,1]];static Hiragana=[[12353,12438,1],[12445,12447,1],[110593,110879,1],[110898,110928,30],[110929,110930,1],[127488,127488,1]];static Imperial_Aramaic=[[67648,67669,1],[67671,67679,1]];static Inherited=[[768,879,1],[1157,1158,1],[1611,1621,1],[1648,2385,737],[2386,2388,1],[6832,6862,1],[7376,7378,1],[7380,7392,1],[7394,7400,1],[7405,7412,7],[7416,7417,1],[7616,7679,1],[8204,8205,1],[8400,8432,1],[12330,12333,1],[12441,12442,1],[65024,65039,1],[65056,65069,1],[66045,66272,227],[70459,118528,48069],[118529,118573,1],[118576,118598,1],[119143,119145,1],[119163,119170,1],[119173,119179,1],[119210,119213,1],[917760,917999,1]];static foldInherited=[[921,953,32],[8126,8126,1]];static Inscriptional_Pahlavi=[[68448,68466,1],[68472,68479,1]];static Inscriptional_Parthian=[[68416,68437,1],[68440,68447,1]];static Javanese=[[43392,43469,1],[43472,43481,1],[43486,43487,1]];static Kaithi=[[69760,69826,1],[69837,69837,1]];static Kannada=[[3200,3212,1],[3214,3216,1],[3218,3240,1],[3242,3251,1],[3253,3257,1],[3260,3268,1],[3270,3272,1],[3274,3277,1],[3285,3286,1],[3293,3294,1],[3296,3299,1],[3302,3311,1],[3313,3315,1]];static Katakana=[[12449,12538,1],[12541,12543,1],[12784,12799,1],[13008,13054,1],[13056,13143,1],[65382,65391,1],[65393,65437,1],[110576,110579,1],[110581,110587,1],[110589,110590,1],[110592,110880,288],[110881,110882,1],[110933,110948,15],[110949,110951,1]];static Kawi=[[73472,73488,1],[73490,73530,1],[73534,73561,1]];static Kayah_Li=[[43264,43309,1],[43311,43311,1]];static Kharoshthi=[[68096,68099,1],[68101,68102,1],[68108,68115,1],[68117,68119,1],[68121,68149,1],[68152,68154,1],[68159,68168,1],[68176,68184,1]];static Khitan_Small_Script=[[94180,101120,6940],[101121,101589,1]];static Khmer=[[6016,6109,1],[6112,6121,1],[6128,6137,1],[6624,6655,1]];static Khojki=[[70144,70161,1],[70163,70209,1]];static Khudawadi=[[70320,70378,1],[70384,70393,1]];static Lao=[[3713,3714,1],[3716,3718,2],[3719,3722,1],[3724,3747,1],[3749,3751,2],[3752,3773,1],[3776,3780,1],[3782,3784,2],[3785,3790,1],[3792,3801,1],[3804,3807,1]];static Latin=[[65,90,1],[97,122,1],[170,186,16],[192,214,1],[216,246,1],[248,696,1],[736,740,1],[7424,7461,1],[7468,7516,1],[7522,7525,1],[7531,7543,1],[7545,7614,1],[7680,7935,1],[8305,8319,14],[8336,8348,1],[8490,8491,1],[8498,8526,28],[8544,8584,1],[11360,11391,1],[42786,42887,1],[42891,42954,1],[42960,42961,1],[42963,42965,2],[42966,42969,1],[42994,43007,1],[43824,43866,1],[43868,43876,1],[43878,43881,1],[64256,64262,1],[65313,65338,1],[65345,65370,1],[67456,67461,1],[67463,67504,1],[67506,67514,1],[122624,122654,1],[122661,122666,1]];static Lepcha=[[7168,7223,1],[7227,7241,1],[7245,7247,1]];static Limbu=[[6400,6430,1],[6432,6443,1],[6448,6459,1],[6464,6468,4],[6469,6479,1]];static Linear_A=[[67072,67382,1],[67392,67413,1],[67424,67431,1]];static Linear_B=[[65536,65547,1],[65549,65574,1],[65576,65594,1],[65596,65597,1],[65599,65613,1],[65616,65629,1],[65664,65786,1]];static Lisu=[[42192,42239,1],[73648,73648,1]];static Lycian=[[66176,66204,1]];static Lydian=[[67872,67897,1],[67903,67903,1]];static Mahajani=[[69968,70006,1]];static Makasar=[[73440,73464,1]];static Malayalam=[[3328,3340,1],[3342,3344,1],[3346,3396,1],[3398,3400,1],[3402,3407,1],[3412,3427,1],[3430,3455,1]];static Mandaic=[[2112,2139,1],[2142,2142,1]];static Manichaean=[[68288,68326,1],[68331,68342,1]];static Marchen=[[72816,72847,1],[72850,72871,1],[72873,72886,1]];static Masaram_Gondi=[[72960,72966,1],[72968,72969,1],[72971,73014,1],[73018,73020,2],[73021,73023,2],[73024,73031,1],[73040,73049,1]];static Medefaidrin=[[93760,93850,1]];static Meetei_Mayek=[[43744,43766,1],[43968,44013,1],[44016,44025,1]];static Mende_Kikakui=[[124928,125124,1],[125127,125142,1]];static Meroitic_Cursive=[[68e3,68023,1],[68028,68047,1],[68050,68095,1]];static Meroitic_Hieroglyphs=[[67968,67999,1]];static Miao=[[93952,94026,1],[94031,94087,1],[94095,94111,1]];static Modi=[[71168,71236,1],[71248,71257,1]];static Mongolian=[[6144,6145,1],[6148,6150,2],[6151,6169,1],[6176,6264,1],[6272,6314,1],[71264,71276,1]];static Mro=[[92736,92766,1],[92768,92777,1],[92782,92783,1]];static Multani=[[70272,70278,1],[70280,70282,2],[70283,70285,1],[70287,70301,1],[70303,70313,1]];static Myanmar=[[4096,4255,1],[43488,43518,1],[43616,43647,1]];static Nabataean=[[67712,67742,1],[67751,67759,1]];static Nag_Mundari=[[124112,124153,1]];static Nandinagari=[[72096,72103,1],[72106,72151,1],[72154,72164,1]];static New_Tai_Lue=[[6528,6571,1],[6576,6601,1],[6608,6618,1],[6622,6623,1]];static Newa=[[70656,70747,1],[70749,70753,1]];static Nko=[[1984,2042,1],[2045,2047,1]];static Nushu=[[94177,110960,16783],[110961,111355,1]];static Nyiakeng_Puachue_Hmong=[[123136,123180,1],[123184,123197,1],[123200,123209,1],[123214,123215,1]];static Ogham=[[5760,5788,1]];static Ol_Chiki=[[7248,7295,1]];static Old_Hungarian=[[68736,68786,1],[68800,68850,1],[68858,68863,1]];static Old_Italic=[[66304,66339,1],[66349,66351,1]];static Old_North_Arabian=[[68224,68255,1]];static Old_Permic=[[66384,66426,1]];static Old_Persian=[[66464,66499,1],[66504,66517,1]];static Old_Sogdian=[[69376,69415,1]];static Old_South_Arabian=[[68192,68223,1]];static Old_Turkic=[[68608,68680,1]];static Old_Uyghur=[[69488,69513,1]];static Oriya=[[2817,2819,1],[2821,2828,1],[2831,2832,1],[2835,2856,1],[2858,2864,1],[2866,2867,1],[2869,2873,1],[2876,2884,1],[2887,2888,1],[2891,2893,1],[2901,2903,1],[2908,2909,1],[2911,2915,1],[2918,2935,1]];static Osage=[[66736,66771,1],[66776,66811,1]];static Osmanya=[[66688,66717,1],[66720,66729,1]];static Pahawh_Hmong=[[92928,92997,1],[93008,93017,1],[93019,93025,1],[93027,93047,1],[93053,93071,1]];static Palmyrene=[[67680,67711,1]];static Pau_Cin_Hau=[[72384,72440,1]];static Phags_Pa=[[43072,43127,1]];static Phoenician=[[67840,67867,1],[67871,67871,1]];static Psalter_Pahlavi=[[68480,68497,1],[68505,68508,1],[68521,68527,1]];static Rejang=[[43312,43347,1],[43359,43359,1]];static Runic=[[5792,5866,1],[5870,5880,1]];static Samaritan=[[2048,2093,1],[2096,2110,1]];static Saurashtra=[[43136,43205,1],[43214,43225,1]];static Sharada=[[70016,70111,1]];static Shavian=[[66640,66687,1]];static Siddham=[[71040,71093,1],[71096,71133,1]];static SignWriting=[[120832,121483,1],[121499,121503,1],[121505,121519,1]];static Sinhala=[[3457,3459,1],[3461,3478,1],[3482,3505,1],[3507,3515,1],[3517,3520,3],[3521,3526,1],[3530,3535,5],[3536,3540,1],[3542,3544,2],[3545,3551,1],[3558,3567,1],[3570,3572,1],[70113,70132,1]];static Sogdian=[[69424,69465,1]];static Sora_Sompeng=[[69840,69864,1],[69872,69881,1]];static Soyombo=[[72272,72354,1]];static Sundanese=[[7040,7103,1],[7360,7367,1]];static Syloti_Nagri=[[43008,43052,1]];static Syriac=[[1792,1805,1],[1807,1866,1],[1869,1871,1],[2144,2154,1]];static Tagalog=[[5888,5909,1],[5919,5919,1]];static Tagbanwa=[[5984,5996,1],[5998,6e3,1],[6002,6003,1]];static Tai_Le=[[6480,6509,1],[6512,6516,1]];static Tai_Tham=[[6688,6750,1],[6752,6780,1],[6783,6793,1],[6800,6809,1],[6816,6829,1]];static Tai_Viet=[[43648,43714,1],[43739,43743,1]];static Takri=[[71296,71353,1],[71360,71369,1]];static Tamil=[[2946,2947,1],[2949,2954,1],[2958,2960,1],[2962,2965,1],[2969,2970,1],[2972,2974,2],[2975,2979,4],[2980,2984,4],[2985,2986,1],[2990,3001,1],[3006,3010,1],[3014,3016,1],[3018,3021,1],[3024,3031,7],[3046,3066,1],[73664,73713,1],[73727,73727,1]];static Tangsa=[[92784,92862,1],[92864,92873,1]];static Tangut=[[94176,94208,32],[94209,100343,1],[100352,101119,1],[101632,101640,1]];static Telugu=[[3072,3084,1],[3086,3088,1],[3090,3112,1],[3114,3129,1],[3132,3140,1],[3142,3144,1],[3146,3149,1],[3157,3158,1],[3160,3162,1],[3165,3168,3],[3169,3171,1],[3174,3183,1],[3191,3199,1]];static Thaana=[[1920,1969,1]];static Thai=[[3585,3642,1],[3648,3675,1]];static Tibetan=[[3840,3911,1],[3913,3948,1],[3953,3991,1],[3993,4028,1],[4030,4044,1],[4046,4052,1],[4057,4058,1]];static Tifinagh=[[11568,11623,1],[11631,11632,1],[11647,11647,1]];static Tirhuta=[[70784,70855,1],[70864,70873,1]];static Toto=[[123536,123566,1]];static Ugaritic=[[66432,66461,1],[66463,66463,1]];static Vai=[[42240,42539,1]];static Vithkuqi=[[66928,66938,1],[66940,66954,1],[66956,66962,1],[66964,66965,1],[66967,66977,1],[66979,66993,1],[66995,67001,1],[67003,67004,1]];static Wancho=[[123584,123641,1],[123647,123647,1]];static Warang_Citi=[[71840,71922,1],[71935,71935,1]];static Yezidi=[[69248,69289,1],[69291,69293,1],[69296,69297,1]];static Yi=[[40960,42124,1],[42128,42182,1]];static Zanabazar_Square=[[72192,72263,1]];static CATEGORIES=new Map([["C",r.C],["Cc",r.Cc],["Cf",r.Cf],["Co",r.Co],["Cs",r.Cs],["L",r.L],["Ll",r.Ll],["Lm",r.Lm],["Lo",r.Lo],["Lt",r.Lt],["Lu",r.Lu],["M",r.M],["Mc",r.Mc],["Me",r.Me],["Mn",r.Mn],["N",r.N],["Nd",r.Nd],["Nl",r.Nl],["No",r.No],["P",r.P],["Pc",r.Pc],["Pd",r.Pd],["Pe",r.Pe],["Pf",r.Pf],["Pi",r.Pi],["Po",r.Po],["Ps",r.Ps],["S",r.S],["Sc",r.Sc],["Sk",r.Sk],["Sm",r.Sm],["So",r.So],["Z",r.Z],["Zl",r.Zl],["Zp",r.Zp],["Zs",r.Zs]]);static SCRIPTS=new Map([["Adlam",r.Adlam],["Ahom",r.Ahom],["Anatolian_Hieroglyphs",r.Anatolian_Hieroglyphs],["Arabic",r.Arabic],["Armenian",r.Armenian],["Avestan",r.Avestan],["Balinese",r.Balinese],["Bamum",r.Bamum],["Bassa_Vah",r.Bassa_Vah],["Batak",r.Batak],["Bengali",r.Bengali],["Bhaiksuki",r.Bhaiksuki],["Bopomofo",r.Bopomofo],["Brahmi",r.Brahmi],["Braille",r.Braille],["Buginese",r.Buginese],["Buhid",r.Buhid],["Canadian_Aboriginal",r.Canadian_Aboriginal],["Carian",r.Carian],["Caucasian_Albanian",r.Caucasian_Albanian],["Chakma",r.Chakma],["Cham",r.Cham],["Cherokee",r.Cherokee],["Chorasmian",r.Chorasmian],["Common",r.Common],["Coptic",r.Coptic],["Cuneiform",r.Cuneiform],["Cypriot",r.Cypriot],["Cypro_Minoan",r.Cypro_Minoan],["Cyrillic",r.Cyrillic],["Deseret",r.Deseret],["Devanagari",r.Devanagari],["Dives_Akuru",r.Dives_Akuru],["Dogra",r.Dogra],["Duployan",r.Duployan],["Egyptian_Hieroglyphs",r.Egyptian_Hieroglyphs],["Elbasan",r.Elbasan],["Elymaic",r.Elymaic],["Ethiopic",r.Ethiopic],["Georgian",r.Georgian],["Glagolitic",r.Glagolitic],["Gothic",r.Gothic],["Grantha",r.Grantha],["Greek",r.Greek],["Gujarati",r.Gujarati],["Gunjala_Gondi",r.Gunjala_Gondi],["Gurmukhi",r.Gurmukhi],["Han",r.Han],["Hangul",r.Hangul],["Hanifi_Rohingya",r.Hanifi_Rohingya],["Hanunoo",r.Hanunoo],["Hatran",r.Hatran],["Hebrew",r.Hebrew],["Hiragana",r.Hiragana],["Imperial_Aramaic",r.Imperial_Aramaic],["Inherited",r.Inherited],["Inscriptional_Pahlavi",r.Inscriptional_Pahlavi],["Inscriptional_Parthian",r.Inscriptional_Parthian],["Javanese",r.Javanese],["Kaithi",r.Kaithi],["Kannada",r.Kannada],["Katakana",r.Katakana],["Kawi",r.Kawi],["Kayah_Li",r.Kayah_Li],["Kharoshthi",r.Kharoshthi],["Khitan_Small_Script",r.Khitan_Small_Script],["Khmer",r.Khmer],["Khojki",r.Khojki],["Khudawadi",r.Khudawadi],["Lao",r.Lao],["Latin",r.Latin],["Lepcha",r.Lepcha],["Limbu",r.Limbu],["Linear_A",r.Linear_A],["Linear_B",r.Linear_B],["Lisu",r.Lisu],["Lycian",r.Lycian],["Lydian",r.Lydian],["Mahajani",r.Mahajani],["Makasar",r.Makasar],["Malayalam",r.Malayalam],["Mandaic",r.Mandaic],["Manichaean",r.Manichaean],["Marchen",r.Marchen],["Masaram_Gondi",r.Masaram_Gondi],["Medefaidrin",r.Medefaidrin],["Meetei_Mayek",r.Meetei_Mayek],["Mende_Kikakui",r.Mende_Kikakui],["Meroitic_Cursive",r.Meroitic_Cursive],["Meroitic_Hieroglyphs",r.Meroitic_Hieroglyphs],["Miao",r.Miao],["Modi",r.Modi],["Mongolian",r.Mongolian],["Mro",r.Mro],["Multani",r.Multani],["Myanmar",r.Myanmar],["Nabataean",r.Nabataean],["Nag_Mundari",r.Nag_Mundari],["Nandinagari",r.Nandinagari],["New_Tai_Lue",r.New_Tai_Lue],["Newa",r.Newa],["Nko",r.Nko],["Nushu",r.Nushu],["Nyiakeng_Puachue_Hmong",r.Nyiakeng_Puachue_Hmong],["Ogham",r.Ogham],["Ol_Chiki",r.Ol_Chiki],["Old_Hungarian",r.Old_Hungarian],["Old_Italic",r.Old_Italic],["Old_North_Arabian",r.Old_North_Arabian],["Old_Permic",r.Old_Permic],["Old_Persian",r.Old_Persian],["Old_Sogdian",r.Old_Sogdian],["Old_South_Arabian",r.Old_South_Arabian],["Old_Turkic",r.Old_Turkic],["Old_Uyghur",r.Old_Uyghur],["Oriya",r.Oriya],["Osage",r.Osage],["Osmanya",r.Osmanya],["Pahawh_Hmong",r.Pahawh_Hmong],["Palmyrene",r.Palmyrene],["Pau_Cin_Hau",r.Pau_Cin_Hau],["Phags_Pa",r.Phags_Pa],["Phoenician",r.Phoenician],["Psalter_Pahlavi",r.Psalter_Pahlavi],["Rejang",r.Rejang],["Runic",r.Runic],["Samaritan",r.Samaritan],["Saurashtra",r.Saurashtra],["Sharada",r.Sharada],["Shavian",r.Shavian],["Siddham",r.Siddham],["SignWriting",r.SignWriting],["Sinhala",r.Sinhala],["Sogdian",r.Sogdian],["Sora_Sompeng",r.Sora_Sompeng],["Soyombo",r.Soyombo],["Sundanese",r.Sundanese],["Syloti_Nagri",r.Syloti_Nagri],["Syriac",r.Syriac],["Tagalog",r.Tagalog],["Tagbanwa",r.Tagbanwa],["Tai_Le",r.Tai_Le],["Tai_Tham",r.Tai_Tham],["Tai_Viet",r.Tai_Viet],["Takri",r.Takri],["Tamil",r.Tamil],["Tangsa",r.Tangsa],["Tangut",r.Tangut],["Telugu",r.Telugu],["Thaana",r.Thaana],["Thai",r.Thai],["Tibetan",r.Tibetan],["Tifinagh",r.Tifinagh],["Tirhuta",r.Tirhuta],["Toto",r.Toto],["Ugaritic",r.Ugaritic],["Vai",r.Vai],["Vithkuqi",r.Vithkuqi],["Wancho",r.Wancho],["Warang_Citi",r.Warang_Citi],["Yezidi",r.Yezidi],["Yi",r.Yi],["Zanabazar_Square",r.Zanabazar_Square]]);static FOLD_CATEGORIES=new Map([["L",r.foldL],["Ll",r.foldLl],["Lt",r.foldLt],["Lu",r.foldLu],["M",r.foldM],["Mn",r.foldMn]]);static FOLD_SCRIPT=new Map([["Common",r.foldCommon],["Greek",r.foldGreek],["Inherited",r.foldInherited]])}class d{static MAX_RUNE=1114111;static MAX_ASCII=127;static MAX_LATIN1=255;static MAX_BMP=65535;static MIN_FOLD=65;static MAX_FOLD=125251;static is32(e,t){let r=0,n=e.length;for(;r<n;){var i=r+Math.floor((n-r)/2),s=e[i];if(s[0]<=t&&t<=s[1])return(t-s[0])%s[2]==0;t<s[0]?n=i:r=i+1}return!1}static is(e,t){if(t<=this.MAX_LATIN1){for(var r of e)if(!(t>r[1]))return!(t<r[0])&&(t-r[0])%r[2]==0;return!1}return 0<e.length&&t>=e[0][0]&&this.is32(e,t)}static isUpper(e){var t;return e<=this.MAX_LATIN1?(t=String.fromCodePoint(e)).toUpperCase()===t&&t.toLowerCase()!==t:this.is(r.Upper,e)}static isPrint(e){return e<=this.MAX_LATIN1?32<=e&&e<127||161<=e&&173!==e:this.is(r.L,e)||this.is(r.M,e)||this.is(r.N,e)||this.is(r.P,e)||this.is(r.S,e)}static simpleFold(e){var t;return r.CASE_ORBIT.has(e)?r.CASE_ORBIT.get(e):(t=p.toLowerCase(e))!==e?t:p.toUpperCase(e)}static equalsIgnoreCase(e,t){if(e<0||t<0||e===t)return!0;if(e<=this.MAX_ASCII&&t<=this.MAX_ASCII)return p.CODES.get("A")<=e&&e<=p.CODES.get("Z")&&(e|=32),p.CODES.get("A")<=t&&t<=p.CODES.get("Z")&&(t|=32),e===t;for(let r=this.simpleFold(e);r!==e;r=this.simpleFold(r))if(r===t)return!0;return!1}}class f{static METACHARACTERS="\\.+*?()|[]{}^$";static EMPTY_BEGIN_LINE=1;static EMPTY_END_LINE=2;static EMPTY_BEGIN_TEXT=4;static EMPTY_END_TEXT=8;static EMPTY_WORD_BOUNDARY=16;static EMPTY_NO_WORD_BOUNDARY=32;static EMPTY_ALL=-1;static emptyInts(){return[]}static isalnum(e){return p.CODES.get("0")<=e&&e<=p.CODES.get("9")||p.CODES.get("a")<=e&&e<=p.CODES.get("z")||p.CODES.get("A")<=e&&e<=p.CODES.get("Z")}static unhex(e){return p.CODES.get("0")<=e&&e<=p.CODES.get("9")?e-p.CODES.get("0"):p.CODES.get("a")<=e&&e<=p.CODES.get("f")?e-p.CODES.get("a")+10:p.CODES.get("A")<=e&&e<=p.CODES.get("F")?e-p.CODES.get("A")+10:-1}static escapeRune(e){let t="";if(d.isPrint(e))0<=this.METACHARACTERS.indexOf(String.fromCodePoint(e))&&(t+="\\"),t+=String.fromCodePoint(e);else switch(e){case p.CODES.get('"'):t+='\\"';break;case p.CODES.get("\\"):t+="\\\\";break;case p.CODES.get("\t"):t+="\\t";break;case p.CODES.get("\n"):t+="\\n";break;case p.CODES.get("\r"):t+="\\r";break;case p.CODES.get("\b"):t+="\\b";break;case p.CODES.get("\f"):t+="\\f";break;default:var r=e.toString(16);e<256?(t+="\\x",1===r.length&&(t+="0"),t+=r):t+=`\\x{${r}}`}return t}static stringToRunes(e){return String(e).split("").map(e=>e.codePointAt(0))}static runeToString(e){return String.fromCodePoint(e)}static isWordRune(e){return p.CODES.get("a")<=e&&e<=p.CODES.get("z")||p.CODES.get("A")<=e&&e<=p.CODES.get("Z")||p.CODES.get("0")<=e&&e<=p.CODES.get("9")||e===p.CODES.get("_")}static emptyOpContext(e,t){let r=0;return e<0&&(r|=this.EMPTY_BEGIN_TEXT|this.EMPTY_BEGIN_LINE),e===p.CODES.get("\n")&&(r|=this.EMPTY_BEGIN_LINE),t<0&&(r|=this.EMPTY_END_TEXT|this.EMPTY_END_LINE),t===p.CODES.get("\n")&&(r|=this.EMPTY_END_LINE),this.isWordRune(e)!==this.isWordRune(t)?r|=this.EMPTY_WORD_BOUNDARY:r|=this.EMPTY_NO_WORD_BOUNDARY,r}static quoteMeta(e){return e.split("").map(e=>0<=this.METACHARACTERS.indexOf(e)?"\\"+e:e).join("")}static charCount(e){return e>d.MAX_BMP?2:1}static stringToUtf8ByteArray(i){if(globalThis.TextEncoder)return Array.from((new TextEncoder).encode(i));{let t=[],r=0;for(let n=0;n<i.length;n++){let e=i.charCodeAt(n);e<128?t[r++]=e:(e<2048?t[r++]=e>>6|192:(55296==(64512&e)&&n+1<i.length&&56320==(64512&i.charCodeAt(n+1))?(e=65536+((1023&e)<<10)+(1023&i.charCodeAt(++n)),t[r++]=e>>18|240,t[r++]=e>>12&63|128):t[r++]=e>>12|224,t[r++]=e>>6&63|128),t[r++]=63&e|128)}return t}}static utf8ByteArrayToString(n){if(globalThis.TextDecoder)return new TextDecoder("utf-8").decode(new Uint8Array(n));{let e=[],t=0,r=0;for(;t<n.length;){var i,s,a,o=n[t++];o<128?e[r++]=String.fromCharCode(o):191<o&&o<224?(i=n[t++],e[r++]=String.fromCharCode((31&o)<<6|63&i)):239<o&&o<365?(i=((7&o)<<18|(63&n[t++])<<12|(63&n[t++])<<6|63&n[t++])-65536,e[r++]=String.fromCharCode(55296+(i>>10)),e[r++]=String.fromCharCode(56320+(1023&i))):(s=n[t++],a=n[t++],e[r++]=String.fromCharCode((15&o)<<12|(63&s)<<6|63&a))}return e.join("")}}}let fe=(e=[],t=0)=>{var r={};for(let s=0;s<e.length;s++){var n=e[s],i=t+s;r[n]=i,r[i]=n}return Object.freeze(r)};class ge{static Encoding=fe(["UTF_16","UTF_8"]);getEncoding(){throw Error("not implemented")}isUTF8Encoding(){return this.getEncoding()===ge.Encoding.UTF_8}isUTF16Encoding(){return this.getEncoding()===ge.Encoding.UTF_16}}class me extends ge{constructor(e=null){super(),this.bytes=e}getEncoding(){return ge.Encoding.UTF_8}asCharSequence(){return f.utf8ByteArrayToString(this.bytes)}asBytes(){return this.bytes}length(){return this.bytes.length}}class ve extends ge{constructor(e=null){super(),this.charSequence=e}getEncoding(){return ge.Encoding.UTF_16}asCharSequence(){return this.charSequence}asBytes(){return this.charSequence.toString().split("").map(e=>e.codePointAt(0))}length(){return this.charSequence.length}}class ye{static utf16(e){return new ve(e)}static utf8(e){return Array.isArray(e)?new me(e):new me(f.stringToUtf8ByteArray(e))}}class we extends Error{constructor(e){super(e),this.name="RE2JSException"}}class _e extends we{constructor(e,t=null){let r="error parsing regexp: "+e;t&&(r+=`: \`${t}\``),super(r),this.name="RE2JSSyntaxException",this.message=r,this.error=e,this.input=t}getDescription(){return this.error}getPattern(){return this.input}}class Ee extends we{constructor(e){super(e),this.name="RE2JSCompileException"}}class Te extends we{constructor(e){super(e),this.name="RE2JSGroupException"}}class be extends we{constructor(e){super(e),this.name="RE2JSFlagsException"}}class Se{static quoteReplacement(e){return e.indexOf("\\")<0&&e.indexOf("$")<0?e:e.split("").map(e=>{var t=e.codePointAt(0);return t===p.CODES["\\"]||t===p.CODES.$?"\\"+e:e}).join("")}constructor(e,t){if(null===e)throw new Error("pattern is null");this.patternInput=e;var r=this.patternInput.re2();this.patternGroupCount=r.numberOfCapturingGroups(),this.groups=[],this.namedGroups=r.namedGroups,t instanceof ge?this.resetMatcherInput(t):Array.isArray(t)?this.resetMatcherInput(ye.utf8(t)):this.resetMatcherInput(ye.utf16(t))}pattern(){return this.patternInput}reset(){return this.matcherInputLength=this.matcherInput.length(),this.appendPos=0,this.hasMatch=!1,this.hasGroups=!1,this.anchorFlag=0,this}resetMatcherInput(e){if(null===e)throw new Error("input is null");return this.matcherInput=e,this.reset(),this}start(e=0){if("string"==typeof e){var t=this.namedGroups[e];if(!Number.isFinite(t))throw new Te(`group '${e}' not found`);e=t}return this.loadGroup(e),this.groups[2*e]}end(e=0){if("string"==typeof e){var t=this.namedGroups[e];if(!Number.isFinite(t))throw new Te(`group '${e}' not found`);e=t}return this.loadGroup(e),this.groups[2*e+1]}group(e=0){if("string"==typeof e){var t=this.namedGroups[e];if(!Number.isFinite(t))throw new Te(`group '${e}' not found`);e=t}var t=this.start(e),r=this.end(e);return t<0&&r<0?null:this.substring(t,r)}groupCount(){return this.patternGroupCount}loadGroup(e){if(e<0||e>this.patternGroupCount)throw new Te("Group index out of bounds: "+e);if(!this.hasMatch)throw new Te("perhaps no match attempted");if(0!==e&&!this.hasGroups){let e=this.groups[1]+1;e>this.matcherInputLength&&(e=this.matcherInputLength);var t=this.patternInput.re2().matchMachineInput(this.matcherInput,this.groups[0],e,this.anchorFlag,1+this.patternGroupCount);if(!t[0])throw new Te("inconsistency in matching group data");this.groups=t[1],this.hasGroups=!0}}matches(){return this.genMatch(0,b.ANCHOR_BOTH)}lookingAt(){return this.genMatch(0,b.ANCHOR_START)}find(e=null){if(null===e)return e=0,this.hasMatch&&(e=this.groups[1],this.groups[0]===this.groups[1])&&e++,this.genMatch(e,b.UNANCHORED);if(e<0||e>this.matcherInputLength)throw new Te("start index out of bounds: "+e);return this.reset(),this.genMatch(e,0)}genMatch(e,t){var r=this.patternInput.re2().matchMachineInput(this.matcherInput,e,this.matcherInputLength,t,1);return!!r[0]&&(this.groups=r[1],this.hasMatch=!0,this.hasGroups=!1,this.anchorFlag=t,!0)}substring(e,t){return this.matcherInput.isUTF8Encoding()?f.utf8ByteArrayToString(this.matcherInput.asBytes().slice(e,t)):this.matcherInput.asCharSequence().substring(e,t).toString()}inputLength(){return this.matcherInputLength}appendReplacement(e,t=!1){let r="";var n=this.start(),i=this.end();return this.appendPos<n&&(r+=this.substring(this.appendPos,n)),this.appendPos=i,r+=t?this.appendReplacementInternalPerl(e):this.appendReplacementInternal(e)}appendReplacementInternal(r){let n="",i=0;var s=r.length;for(let o=0;o<s-1;o++)if(r.codePointAt(o)===p.CODES.get("\\"))i<o&&(n+=r.substring(i,o)),o++,i=o;else if(r.codePointAt(o)===p.CODES.get("$")){let t=r.codePointAt(o+1);if(p.CODES.get("0")<=t&&t<=p.CODES.get("9")){let e=t-p.CODES.get("0");for(i<o&&(n+=r.substring(i,o)),o+=2;o<s&&!((t=r.codePointAt(o))<p.CODES.get("0")||t>p.CODES.get("9")||10*e+t-p.CODES.get("0")>this.patternGroupCount);o++)e=10*e+t-p.CODES.get("0");if(e>this.patternGroupCount)throw new Te("n > number of groups: "+e);var a=this.group(e);null!==a&&(n+=a),i=o,o--}else if(t===p.CODES.get("{")){i<o&&(n+=r.substring(i,o));let e=++o+1;for(;e<r.length&&r.codePointAt(e)!==p.CODES.get("}")&&r.codePointAt(e)!==p.CODES.get(" ");)e++;if(e===r.length||r.codePointAt(e)!==p.CODES.get("}"))throw new Te("named capture group is missing trailing '}'");a=r.substring(o+1,e);n+=this.group(a),i=e+1}}return i<s&&(n+=r.substring(i,s)),n}appendReplacementInternalPerl(r){let n="",i=0;var s,a=r.length;for(let u=0;u<a-1;u++)if(r.codePointAt(u)===p.CODES.get("$")){let t=r.codePointAt(u+1);if(p.CODES.get("$")===t)i<u&&(n+=r.substring(i,u)),n+="$",u++,i=u+1;else if(p.CODES.get("&")===t){i<u&&(n+=r.substring(i,u));var o=this.group(0);n+=null!==o?o:"$&",u++,i=u+1}else if(p.CODES.get("1")<=t&&t<=p.CODES.get("9")){let e=t-p.CODES.get("0");for(i<u&&(n+=r.substring(i,u)),u+=2;u<a&&!((t=r.codePointAt(u))<p.CODES.get("0")||t>p.CODES.get("9")||10*e+t-p.CODES.get("0")>this.patternGroupCount);u++)e=10*e+t-p.CODES.get("0");e>this.patternGroupCount?(n+="$"+e,i=u,u--):(null!==(o=this.group(e))&&(n+=o),i=u,u--)}else if(t===p.CODES.get("<")){i<u&&(n+=r.substring(i,u));let e=++u+1;for(;e<r.length&&r.codePointAt(e)!==p.CODES.get(">")&&r.codePointAt(e)!==p.CODES.get(" ");)e++;e===r.length||r.codePointAt(e)!==p.CODES.get(">")?(n+=r.substring(u-1,e+1),i=e+1):(s=r.substring(u+1,e),Object.prototype.hasOwnProperty.call(this.namedGroups,s)?n+=this.group(s):n+=`$<${s}>`,i=e+1)}}return i<a&&(n+=r.substring(i,a)),n}appendTail(){return this.substring(this.appendPos,this.matcherInputLength)}replaceAll(e,t=!1){return this.replace(e,!0,t)}replaceFirst(e,t=!1){return this.replace(e,!1,t)}replace(e,t=!0,r=!1){let n="";for(this.reset();this.find()&&(n+=this.appendReplacement(e,r),t););return n+=this.appendTail()}}class Ie{static EOF(){return-8}canCheckPrefix(){return!0}endPos(){return this.end}}class Ae extends Ie{constructor(e,t=0,r=e.length){super(),this.bytes=e,this.start=t,this.end=r}step(e){if((e+=this.start)>=this.end)return Ie.EOF();let t=255&this.bytes[e++];return 0==(128&t)?t<<3|1:192==(224&t)?(t&=31,e>=this.end?Ie.EOF():(t=t<<6|63&this.bytes[e++])<<3|2):224==(240&t)?(t&=15,e+1>=this.end?Ie.EOF():(t=(t=t<<6|63&this.bytes[e++])<<6|63&this.bytes[e++])<<3|3):(t&=7,e+2>=this.end?Ie.EOF():(t=(t=(t=t<<6|63&this.bytes[e++])<<6|63&this.bytes[e++])<<6|63&this.bytes[e++])<<3|4)}index(e,t){t+=this.start;var r=this.indexOf(this.bytes,e.prefixUTF8,t);return r<0?r:r-t}context(r){let n=-1;if((r+=this.start)>this.start&&r<=this.end){let t=r-1;if(128<=(n=this.bytes[t--])){let e=r-4;for(e<this.start&&(e=this.start);t>=e&&128==(192&this.bytes[t]);)t--;t<this.start&&(t=this.start),n=this.step(t)>>3}}var e=r<this.end?this.step(r)>>3:-1;return f.emptyOpContext(n,e)}indexOf(r,n,i=0){var s=n.length;if(0!==s){var a=r.length;for(let t=i;t<=a-s;t++)for(let e=0;e<s&&r[t+e]===n[e];e++)if(e===s-1)return t}return-1}}class Ce extends Ie{constructor(e,t=0,r=e.length){super(),this.charSequence=e,this.start=t,this.end=r}step(e){var t;return(e+=this.start)<this.end?(t=this.charSequence.codePointAt(e))<<3|f.charCount(t):Ie.EOF()}index(e,t){t+=this.start;var r=this.charSequence.indexOf(e.prefix,t);return r<0?r:r-t}context(e){var t=0<(e+=this.start)&&e<=this.charSequence.length?this.charSequence.codePointAt(e-1):-1,r=e<this.charSequence.length?this.charSequence.codePointAt(e):-1;return f.emptyOpContext(t,r)}}class xe{static fromUTF8(e,t=0,r=e.length){return new Ae(e,t,r)}static fromUTF16(e,t=0,r=e.length){return new Ce(e,t,r)}}class S{static Op=fe(["NO_MATCH","EMPTY_MATCH","LITERAL","CHAR_CLASS","ANY_CHAR_NOT_NL","ANY_CHAR","BEGIN_LINE","END_LINE","BEGIN_TEXT","END_TEXT","WORD_BOUNDARY","NO_WORD_BOUNDARY","CAPTURE","STAR","PLUS","QUEST","REPEAT","CONCAT","ALTERNATE","LEFT_PAREN","VERTICAL_BAR"]);static isPseudoOp(e){return e>=S.Op.LEFT_PAREN}static emptySubs(){return[]}static quoteIfHyphen(e){return e===p.CODES.get("-")?"\\":""}static fromRegexp(e){var t=new S(e.op);return t.flags=e.flags,t.subs=e.subs,t.runes=e.runes,t.cap=e.cap,t.min=e.min,t.max=e.max,t.name=e.name,t.namedGroups=e.namedGroups,t}constructor(e){this.op=e,this.flags=0,this.subs=S.emptySubs(),this.runes=null,this.min=0,this.max=0,this.cap=0,this.name=null,this.namedGroups={}}reinit(){this.flags=0,this.subs=S.emptySubs(),this.runes=null,this.cap=0,this.min=0,this.max=0,this.name=null,this.namedGroups={}}toString(){return this.appendTo()}appendTo(){let t="";switch(this.op){case S.Op.NO_MATCH:t+="[^\\x00-\\x{10FFFF}]";break;case S.Op.EMPTY_MATCH:t+="(?:)";break;case S.Op.STAR:case S.Op.PLUS:case S.Op.QUEST:case S.Op.REPEAT:var e=this.subs[0];switch(e.op>S.Op.CAPTURE||e.op===S.Op.LITERAL&&1<e.runes.length?t+=`(?:${e.appendTo()})`:t+=e.appendTo(),this.op){case S.Op.STAR:t+="*";break;case S.Op.PLUS:t+="+";break;case S.Op.QUEST:t+="?";break;case S.Op.REPEAT:t+="{"+this.min,this.min!==this.max&&(t+=",",0<=this.max)&&(t+=this.max),t+="}"}0!=(this.flags&b.NON_GREEDY)&&(t+="?");break;case S.Op.CONCAT:for(var r of this.subs)r.op===S.Op.ALTERNATE?t+=`(?:${r.appendTo()})`:t+=r.appendTo();break;case S.Op.ALTERNATE:{let e="";for(var n of this.subs)t+=e,e="|",t+=n.appendTo();break}case S.Op.LITERAL:0!=(this.flags&b.FOLD_CASE)&&(t+="(?i:");for(var i of this.runes)t+=f.escapeRune(i);0!=(this.flags&b.FOLD_CASE)&&(t+=")");break;case S.Op.ANY_CHAR_NOT_NL:t+="(?-s:.)";break;case S.Op.ANY_CHAR:t+="(?s:.)";break;case S.Op.CAPTURE:null===this.name||0===this.name.length?t+="(":t+=`(?P<${this.name}>`,this.subs[0].op!==S.Op.EMPTY_MATCH&&(t+=this.subs[0].appendTo()),t+=")";break;case S.Op.BEGIN_TEXT:t+="\\A";break;case S.Op.END_TEXT:0!=(this.flags&b.WAS_DOLLAR)?t+="(?-m:$)":t+="\\z";break;case S.Op.BEGIN_LINE:t+="^";break;case S.Op.END_LINE:t+="$";break;case S.Op.WORD_BOUNDARY:t+="\\b";break;case S.Op.NO_WORD_BOUNDARY:t+="\\B";break;case S.Op.CHAR_CLASS:if(this.runes.length%2!=0)t+="[invalid char class]";else{if(t+="[",0===this.runes.length)t+="^\\x00-\\x{10FFFF}";else if(0===this.runes[0]&&this.runes[this.runes.length-1]===d.MAX_RUNE){t+="^";for(let e=1;e<this.runes.length-1;e+=2){var s=this.runes[e]+1,a=this.runes[e+1]-1;t=(t+=S.quoteIfHyphen(s))+f.escapeRune(s),s!==a&&(t=(t=(t+="-")+S.quoteIfHyphen(a))+f.escapeRune(a))}}else for(let e=0;e<this.runes.length;e+=2){var o=this.runes[e],u=this.runes[e+1];t=(t+=S.quoteIfHyphen(o))+f.escapeRune(o),o!==u&&(t=(t=(t+="-")+S.quoteIfHyphen(u))+f.escapeRune(u))}t+="]"}break;default:t+=this.op}return t}maxCap(){let e=0;if(this.op===S.Op.CAPTURE&&(e=this.cap),null!==this.subs)for(var t of this.subs){t=t.maxCap();e<t&&(e=t)}return e}equals(t){if(!(null!==t&&t instanceof S))return!1;if(this.op!==t.op)return!1;switch(this.op){case S.Op.END_TEXT:if((this.flags&b.WAS_DOLLAR)!=(t.flags&b.WAS_DOLLAR))return!1;break;case S.Op.LITERAL:case S.Op.CHAR_CLASS:if(null!==this.runes||null!==t.runes){if(null===this.runes||null===t.runes)return!1;if(this.runes.length!==t.runes.length)return!1;for(let e=0;e<this.runes.length;e++)if(this.runes[e]!==t.runes[e])return!1}break;case S.Op.ALTERNATE:case S.Op.CONCAT:if(this.subs.length!==t.subs.length)return!1;for(let e=0;e<this.subs.length;++e)if(!this.subs[e].equals(t.subs[e]))return!1;break;case S.Op.STAR:case S.Op.PLUS:case S.Op.QUEST:if((this.flags&b.NON_GREEDY)==(t.flags&b.NON_GREEDY)&&this.subs[0].equals(t.subs[0]))break;return!1;case S.Op.REPEAT:if((this.flags&b.NON_GREEDY)==(t.flags&b.NON_GREEDY)&&this.min===t.min&&this.max===t.max&&this.subs[0].equals(t.subs[0]))break;return!1;case S.Op.CAPTURE:if(this.cap!==t.cap||(null===this.name?null!==t.name:this.name!==t.name)||!this.subs[0].equals(t.subs[0]))return!1}return!0}}class g{static ALT=1;static ALT_MATCH=2;static CAPTURE=3;static EMPTY_WIDTH=4;static FAIL=5;static MATCH=6;static NOP=7;static RUNE=8;static RUNE1=9;static RUNE_ANY=10;static RUNE_ANY_NOT_NL=11;static isRuneOp(e){return g.RUNE<=e&&e<=g.RUNE_ANY_NOT_NL}static escapeRunes(e){let t='"';for(var r of e)t+=f.escapeRune(r);return t+='"'}constructor(e){this.op=e,this.out=0,this.arg=0,this.runes=null}matchRune(e){var t;if(1===this.runes.length)return t=this.runes[0],0!=(this.arg&b.FOLD_CASE)?d.equalsIgnoreCase(t,e):e===t;for(let s=0;s<this.runes.length&&s<=8;s+=2){if(e<this.runes[s])return!1;if(e<=this.runes[s+1])return!0}let r=0,n=this.runes.length/2|0;for(;r<n;){var i=r+((n-r)/2|0);if(this.runes[2*i]<=e){if(e<=this.runes[2*i+1])return!0;r=i+1}else n=i}return!1}toString(){switch(this.op){case g.ALT:return`alt -> ${this.out}, `+this.arg;case g.ALT_MATCH:return`altmatch -> ${this.out}, `+this.arg;case g.CAPTURE:return`cap ${this.arg} -> `+this.out;case g.EMPTY_WIDTH:return`empty ${this.arg} -> `+this.out;case g.MATCH:return"match";case g.FAIL:return"fail";case g.NOP:return"nop -> "+this.out;case g.RUNE:return null===this.runes?"rune <null>":["rune ",g.escapeRunes(this.runes),0!=(this.arg&b.FOLD_CASE)?"/i":""," -> ",this.out].join("");case g.RUNE1:return`rune1 ${g.escapeRunes(this.runes)} -> `+this.out;case g.RUNE_ANY:return"any -> "+this.out;case g.RUNE_ANY_NOT_NL:return"anynotnl -> "+this.out;default:throw new Error("unhandled case in Inst.toString")}}}class Ne{constructor(){this.inst=[],this.start=0,this.numCap=2}getInst(e){return this.inst[e]}numInst(){return this.inst.length}addInst(e){this.inst.push(new g(e))}skipNop(e){let t=this.inst[e];for(;t.op===g.NOP||t.op===g.CAPTURE;)e=(t=this.inst[e]).out;return t}prefix(){let e="",t=this.skipNop(this.start);if(g.isRuneOp(t.op)&&1===t.runes.length)for(;g.isRuneOp(t.op)&&1===t.runes.length&&0==(t.arg&b.FOLD_CASE);)e+=String.fromCodePoint(t.runes[0]),t=this.skipNop(t.out);return[t.op===g.MATCH,e]}startCond(){let e=0,t=this.start;e:for(;;){var r=this.inst[t];switch(r.op){case g.EMPTY_WIDTH:e|=r.arg;break;case g.FAIL:return-1;case g.CAPTURE:case g.NOP:break;default:break e}t=r.out}return e}next(e){var t=this.inst[e>>1];return 0==(1&e)?t.out:t.arg}patch(e,t){for(;0!==e;){var r=this.inst[e>>1];0==(1&e)?(e=r.out,r.out=t):(e=r.arg,r.arg=t)}}append(t,r){if(0===t)return r;if(0!==r){let e=t;for(;;){var n=this.next(e);if(0===n)break;e=n}var i=this.inst[e>>1];0==(1&e)?i.out=r:i.arg=r}return t}toString(){let e="";for(let r=0;r<this.inst.length;r++){var t=e.length;e+=r,r===this.start&&(e+="*"),e=(e+="        ".substring(e.length-t))+this.inst[r]+"\n"}return e}}class De{constructor(e=0,t=0,r=!1){this.i=e,this.out=t,this.nullable=r}}class Oe{static ANY_RUNE_NOT_NL(){return[0,p.CODES.get("\n")-1,p.CODES.get("\n")+1,d.MAX_RUNE]}static ANY_RUNE(){return[0,d.MAX_RUNE]}static compileRegexp(e){var t=new Oe,r=t.compile(e);return t.prog.patch(r.out,t.newInst(g.MATCH).i),t.prog.start=r.i,t.prog}constructor(){this.prog=new Ne,this.newInst(g.FAIL)}newInst(e){return this.prog.addInst(e),new De(this.prog.numInst()-1,0,!0)}nop(){var e=this.newInst(g.NOP);return e.out=e.i<<1,e}fail(){return new De}cap(e){var t=this.newInst(g.CAPTURE);return t.out=t.i<<1,this.prog.getInst(t.i).arg=e,this.prog.numCap<e+1&&(this.prog.numCap=e+1),t}cat(e,t){return 0===e.i||0===t.i?this.fail():(this.prog.patch(e.out,t.i),new De(e.i,t.out,e.nullable&&t.nullable))}alt(e,t){var r,n;return 0===e.i?t:0===t.i?e:(r=this.newInst(g.ALT),(n=this.prog.getInst(r.i)).out=e.i,n.arg=t.i,r.out=this.prog.append(e.out,t.out),r.nullable=e.nullable||t.nullable,r)}loop(e,t){var r=this.newInst(g.ALT),n=this.prog.getInst(r.i);return t?(n.arg=e.i,r.out=r.i<<1):(n.out=e.i,r.out=r.i<<1|1),this.prog.patch(e.out,r.i),r}quest(e,t){var r=this.newInst(g.ALT),n=this.prog.getInst(r.i);return t?(n.arg=e.i,r.out=r.i<<1):(n.out=e.i,r.out=r.i<<1|1),r.out=this.prog.append(r.out,e.out),r}star(e,t){return e.nullable?this.quest(this.plus(e,t),t):this.loop(e,t)}plus(e,t){return new De(e.i,this.loop(e,t).out,e.nullable)}empty(e){var t=this.newInst(g.EMPTY_WIDTH);return this.prog.getInst(t.i).arg=e,t.out=t.i<<1,t}rune(e,t){var r=this.newInst(g.RUNE),n=(r.nullable=!1,this.prog.getInst(r.i));return n.runes=e,t&=b.FOLD_CASE,1===e.length&&d.simpleFold(e[0])!==e[0]||(t&=~b.FOLD_CASE),n.arg=t,r.out=r.i<<1,0==(t&b.FOLD_CASE)&&1===e.length||2===e.length&&e[0]===e[1]?n.op=g.RUNE1:2===e.length&&0===e[0]&&e[1]===d.MAX_RUNE?n.op=g.RUNE_ANY:4===e.length&&0===e[0]&&e[1]===p.CODES.get("\n")-1&&e[2]===p.CODES.get("\n")+1&&e[3]===d.MAX_RUNE&&(n.op=g.RUNE_ANY_NOT_NL),r}compile(t){switch(t.op){case S.Op.NO_MATCH:return this.fail();case S.Op.EMPTY_MATCH:return this.nop();case S.Op.LITERAL:if(0===t.runes.length)return this.nop();{let e=null;for(var r of t.runes){r=this.rune([r],t.flags);e=null===e?r:this.cat(e,r)}return e}case S.Op.CHAR_CLASS:return this.rune(t.runes,t.flags);case S.Op.ANY_CHAR_NOT_NL:return this.rune(Oe.ANY_RUNE_NOT_NL(),0);case S.Op.ANY_CHAR:return this.rune(Oe.ANY_RUNE(),0);case S.Op.BEGIN_LINE:return this.empty(f.EMPTY_BEGIN_LINE);case S.Op.END_LINE:return this.empty(f.EMPTY_END_LINE);case S.Op.BEGIN_TEXT:return this.empty(f.EMPTY_BEGIN_TEXT);case S.Op.END_TEXT:return this.empty(f.EMPTY_END_TEXT);case S.Op.WORD_BOUNDARY:return this.empty(f.EMPTY_WORD_BOUNDARY);case S.Op.NO_WORD_BOUNDARY:return this.empty(f.EMPTY_NO_WORD_BOUNDARY);case S.Op.CAPTURE:var e=this.cap(t.cap<<1),n=this.compile(t.subs[0]),i=this.cap(t.cap<<1|1);return this.cat(this.cat(e,n),i);case S.Op.STAR:return this.star(this.compile(t.subs[0]),0!=(t.flags&b.NON_GREEDY));case S.Op.PLUS:return this.plus(this.compile(t.subs[0]),0!=(t.flags&b.NON_GREEDY));case S.Op.QUEST:return this.quest(this.compile(t.subs[0]),0!=(t.flags&b.NON_GREEDY));case S.Op.CONCAT:if(0===t.subs.length)return this.nop();{let e=null;for(var s of t.subs){s=this.compile(s);e=null===e?s:this.cat(e,s)}return e}case S.Op.ALTERNATE:if(0===t.subs.length)return this.nop();{let e=null;for(var a of t.subs){a=this.compile(a);e=null===e?a:this.alt(e,a)}return e}default:throw new Ee("regexp: unhandled case in compile")}}}class Re{static simplify(n){if(null===n)return null;switch(n.op){case S.Op.CAPTURE:case S.Op.CONCAT:case S.Op.ALTERNATE:{let e=n;for(let t=0;t<n.subs.length;t++){var r=n.subs[t],i=Re.simplify(r);e===n&&i!==r&&((e=S.fromRegexp(n)).runes=null,e.subs=n.subs.slice(0,n.subs.length)),e!==n&&(e.subs[t]=i)}return e}case S.Op.STAR:case S.Op.PLUS:case S.Op.QUEST:var t=Re.simplify(n.subs[0]);return Re.simplify1(n.op,n.flags,t,n);case S.Op.REPEAT:{if(0===n.min&&0===n.max)return new S(S.Op.EMPTY_MATCH);var s=Re.simplify(n.subs[0]);if(-1===n.max){if(0===n.min)return Re.simplify1(S.Op.STAR,n.flags,s,null);if(1===n.min)return Re.simplify1(S.Op.PLUS,n.flags,s,null);var t=new S(S.Op.CONCAT),a=[];for(let e=0;e<n.min-1;e++)a.push(s);return a.push(Re.simplify1(S.Op.PLUS,n.flags,s,null)),t.subs=a.slice(0),t}if(1===n.min&&1===n.max)return s;let r=null;if(0<n.min){r=[];for(let e=0;e<n.min;e++)r.push(s)}if(n.min<n.max){let e=Re.simplify1(S.Op.QUEST,n.flags,s,null);for(let t=n.min+1;t<n.max;t++){var o=new S(S.Op.CONCAT);o.subs=[s,e],e=Re.simplify1(S.Op.QUEST,n.flags,o,null)}if(null===r)return e;r.push(e)}return null!==r?((t=new S(S.Op.CONCAT)).subs=r.slice(0),t):new S(S.Op.NO_MATCH)}}return n}static simplify1(e,t,r,n){return r.op===S.Op.EMPTY_MATCH||e===r.op&&(t&b.NON_GREEDY)==(r.flags&b.NON_GREEDY)?r:(null!==n&&n.op===e&&(n.flags&b.NON_GREEDY)==(t&b.NON_GREEDY)&&r===n.subs[0]||((n=new S(e)).flags=t,n.subs=[r]),n)}}class t{constructor(e,t){this.sign=e,this.cls=t}}var e=[48,57],ke=[9,10,12,13,32,32],Le=[48,57,65,90,95,95,97,122];let Pe=new Map([["\\d",new t(1,e)],["\\D",new t(-1,e)],["\\s",new t(1,ke)],["\\S",new t(-1,ke)],["\\w",new t(1,Le)],["\\W",new t(-1,Le)]]);var Me,Ve,e=[48,57,65,90,97,122],ke=[65,90,97,122],Le=[0,127],Fe=[9,9,32,32],Ue=[0,31,127,127],Be=[48,57],qe=[33,126],Ge=[97,122],je=[32,126],ze=[33,47,58,64,91,96,123,126],He=[9,13,32,32],Ke=[65,90],$e=[48,57,65,90,95,95,97,122],Qe=[48,57,65,70,97,102];let Ye=new Map([["[:alnum:]",new t(1,e)],["[:^alnum:]",new t(-1,e)],["[:alpha:]",new t(1,ke)],["[:^alpha:]",new t(-1,ke)],["[:ascii:]",new t(1,Le)],["[:^ascii:]",new t(-1,Le)],["[:blank:]",new t(1,Fe)],["[:^blank:]",new t(-1,Fe)],["[:cntrl:]",new t(1,Ue)],["[:^cntrl:]",new t(-1,Ue)],["[:digit:]",new t(1,Be)],["[:^digit:]",new t(-1,Be)],["[:graph:]",new t(1,qe)],["[:^graph:]",new t(-1,qe)],["[:lower:]",new t(1,Ge)],["[:^lower:]",new t(-1,Ge)],["[:print:]",new t(1,je)],["[:^print:]",new t(-1,je)],["[:punct:]",new t(1,ze)],["[:^punct:]",new t(-1,ze)],["[:space:]",new t(1,He)],["[:^space:]",new t(-1,He)],["[:upper:]",new t(1,Ke)],["[:^upper:]",new t(-1,Ke)],["[:word:]",new t(1,$e)],["[:^word:]",new t(-1,$e)],["[:xdigit:]",new t(1,Qe)],["[:^xdigit:]",new t(-1,Qe)]]);class We{static charClassToString(e,t){let r="[";for(let s=0;s<t;s+=2){0<s&&(r+=" ");var n=e[s],i=e[s+1];r+=n===i?"0x"+n.toString(16):`0x${n.toString(16)}-0x`+i.toString(16)}return r+="]"}static cmp(e,t,r,n){var i=e[t]-r;return 0!=i?i:n-e[t+1]}static qsortIntPair(e,t,r){var n,i=-2&((t+r)/2|0),s=e[i],a=e[1+i];let o=t,u=r;for(;o<=u;){for(;o<r&&We.cmp(e,o,s,a)<0;)o+=2;for(;u>t&&0<We.cmp(e,u,s,a);)u-=2;o<=u&&(o!==u&&(n=e[o],e[o]=e[u],e[u]=n,n=e[o+1],e[o+1]=e[u+1],e[u+1]=n),o+=2,u-=2)}t<u&&We.qsortIntPair(e,t,u),o<r&&We.qsortIntPair(e,o,r)}constructor(e=f.emptyInts()){this.r=e,this.len=e.length}toArray(){return this.len===this.r.length?this.r:this.r.slice(0,this.len)}cleanClass(){if(!(this.len<4)){We.qsortIntPair(this.r,0,this.len-2);let e=2;for(let t=2;t<this.len;t+=2){var r=this.r[t],n=this.r[t+1];r<=this.r[e-1]+1?n>this.r[e-1]&&(this.r[e-1]=n):(this.r[e]=r,this.r[e+1]=n,e+=2)}this.len=e}return this}appendLiteral(e,t){return 0!=(t&b.FOLD_CASE)?this.appendFoldedRange(e,e):this.appendRange(e,e)}appendRange(t,r){if(0<this.len)for(let e=2;e<=4;e+=2)if(this.len>=e){var n=this.r[this.len-e],i=this.r[this.len-e+1];if(t<=i+1&&n<=r+1)return t<n&&(this.r[this.len-e]=t),i<r&&(this.r[this.len-e+1]=r),this}return this.r[this.len++]=t,this.r[this.len++]=r,this}appendFoldedRange(e,t){if(e<=d.MIN_FOLD&&t>=d.MAX_FOLD)return this.appendRange(e,t);if(t<d.MIN_FOLD||e>d.MAX_FOLD)return this.appendRange(e,t);e<d.MIN_FOLD&&(this.appendRange(e,d.MIN_FOLD-1),e=d.MIN_FOLD),t>d.MAX_FOLD&&(this.appendRange(d.MAX_FOLD+1,t),t=d.MAX_FOLD);for(let r=e;r<=t;r++){this.appendRange(r,r);for(let e=d.simpleFold(r);e!==r;e=d.simpleFold(e))this.appendRange(e,e)}return this}appendClass(e){for(let t=0;t<e.length;t+=2)this.appendRange(e[t],e[t+1]);return this}appendFoldedClass(e){for(let t=0;t<e.length;t+=2)this.appendFoldedRange(e[t],e[t+1]);return this}appendNegatedClass(e){let t=0;for(let i=0;i<e.length;i+=2){var r=e[i],n=e[i+1];t<=r-1&&this.appendRange(t,r-1),t=n+1}return t<=d.MAX_RUNE&&this.appendRange(t,d.MAX_RUNE),this}appendTable(e){for(var t of e){var r=t[0],n=t[1],i=t[2];if(1===i)this.appendRange(r,n);else for(let e=r;e<=n;e+=i)this.appendRange(e,e)}return this}appendNegatedTable(e){let t=0;for(var r of e){var n=r[0],i=r[1],s=r[2];if(1===s)t<=n-1&&this.appendRange(t,n-1),t=i+1;else for(let e=n;e<=i;e+=s)t<=e-1&&this.appendRange(t,e-1),t=e+1}return t<=d.MAX_RUNE&&this.appendRange(t,d.MAX_RUNE),this}appendTableWithSign(e,t){return t<0?this.appendNegatedTable(e):this.appendTable(e)}negateClass(){let e=0,t=0;for(let i=0;i<this.len;i+=2){var r=this.r[i],n=this.r[i+1];e<=r-1&&(this.r[t]=e,this.r[t+1]=r-1,t+=2),e=n+1}return this.len=t,e<=d.MAX_RUNE&&(this.r[this.len++]=e,this.r[this.len++]=d.MAX_RUNE),this}appendClassWithSign(e,t){return t<0?this.appendNegatedClass(e):this.appendClass(e)}appendGroup(e,t){let r=e.cls;return t&&(r=(new We).appendFoldedClass(r).cleanClass().toArray()),this.appendClassWithSign(r,e.sign)}toString(){return We.charClassToString(this.r,this.len)}}class Xe{static of(e,t){return new Xe(e,t)}constructor(e,t){this.first=e,this.second=t}}class Je{constructor(e){this.str=e,this.position=0}pos(){return this.position}rewindTo(e){this.position=e}more(){return this.position<this.str.length}peek(){return this.str.codePointAt(this.position)}skip(e){this.position+=e}skipString(e){this.position+=e.length}pop(){var e=this.str.codePointAt(this.position);return this.position+=f.charCount(e),e}lookingAt(e){return this.rest().startsWith(e)}rest(){return this.str.substring(this.position)}from(e){return this.str.substring(e,this.position)}toString(){return this.rest()}}class I{static ERR_INTERNAL_ERROR="regexp/syntax: internal error";static ERR_INVALID_CHAR_RANGE="invalid character class range";static ERR_INVALID_ESCAPE="invalid escape sequence";static ERR_INVALID_NAMED_CAPTURE="invalid named capture";static ERR_INVALID_PERL_OP="invalid or unsupported Perl syntax";static ERR_INVALID_REPEAT_OP="invalid nested repetition operator";static ERR_INVALID_REPEAT_SIZE="invalid repeat count";static ERR_MISSING_BRACKET="missing closing ]";static ERR_MISSING_PAREN="missing closing )";static ERR_MISSING_REPEAT_ARGUMENT="missing argument to repetition operator";static ERR_TRAILING_BACKSLASH="trailing backslash at end of expression";static ERR_DUPLICATE_NAMED_CAPTURE="duplicate capture group name";static ANY_TABLE(){return[[0,d.MAX_RUNE,1]]}static unicodeTable(e){return"Any"===e?Xe.of(I.ANY_TABLE(),I.ANY_TABLE()):r.CATEGORIES.has(e)?Xe.of(r.CATEGORIES.get(e),r.FOLD_CATEGORIES.get(e)):r.SCRIPTS.has(e)?Xe.of(r.SCRIPTS.get(e),r.FOLD_SCRIPT.get(e)):null}static minFoldRune(e){if(e<d.MIN_FOLD||e>d.MAX_FOLD)return e;let t=e;var r=e;for(e=d.simpleFold(e);e!==r;e=d.simpleFold(e))t>e&&(t=e);return t}static leadingRegexp(e){var t;return e.op===S.Op.EMPTY_MATCH?null:e.op===S.Op.CONCAT&&0<e.subs.length?(t=e.subs[0]).op===S.Op.EMPTY_MATCH?null:t:e}static literalRegexp(e,t){var r=new S(S.Op.LITERAL);return r.flags=t,r.runes=f.stringToRunes(e),r}static parse(e,t){return new I(e,t).parseInternal()}static parseRepeat(e){var t=e.pos();if(!e.more()||!e.lookingAt("{"))return-1;e.skip(1);var r=I.parseInt(e);if(-1===r)return-1;if(!e.more())return-1;let n;if(e.lookingAt(",")){if(e.skip(1),!e.more())return-1;if(e.lookingAt("}"))n=-1;else if(-1===(n=I.parseInt(e)))return-1}else n=r;if(!e.more()||!e.lookingAt("}"))return-1;if(e.skip(1),r<0||1e3<r||-2===n||1e3<n||0<=n&&r>n)throw new _e(I.ERR_INVALID_REPEAT_SIZE,e.from(t));return r<<16|n&d.MAX_BMP}static isValidCaptureName(e){if(0===e.length)return!1;for(let r=0;r<e.length;r++){var t=e.codePointAt(r);if(t!==p.CODES.get("_")&&!f.isalnum(t))return!1}return!0}static parseInt(e){for(var t=e.pos();e.more()&&e.peek()>=p.CODES.get("0")&&e.peek()<=p.CODES.get("9");)e.skip(1);t=e.from(t);return 0===t.length||1<t.length&&t.codePointAt(0)===p.CODES.get("0")?-1:8<t.length?-2:parseFloat(t,10)}static isCharClass(e){return e.op===S.Op.LITERAL&&1===e.runes.length||e.op===S.Op.CHAR_CLASS||e.op===S.Op.ANY_CHAR_NOT_NL||e.op===S.Op.ANY_CHAR}static matchRune(t,r){switch(t.op){case S.Op.LITERAL:return 1===t.runes.length&&t.runes[0]===r;case S.Op.CHAR_CLASS:for(let e=0;e<t.runes.length;e+=2)if(t.runes[e]<=r&&r<=t.runes[e+1])return!0;return!1;case S.Op.ANY_CHAR_NOT_NL:return r!==p.CODES.get("\n");case S.Op.ANY_CHAR:return!0}return!1}static mergeCharClass(e,t){switch(e.op){case S.Op.ANY_CHAR:break;case S.Op.ANY_CHAR_NOT_NL:I.matchRune(t,p.CODES.get("\n"))&&(e.op=S.Op.ANY_CHAR);break;case S.Op.CHAR_CLASS:t.op===S.Op.LITERAL?e.runes=new We(e.runes).appendLiteral(t.runes[0],t.flags).toArray():e.runes=new We(e.runes).appendClass(t.runes).toArray();break;case S.Op.LITERAL:t.runes[0]===e.runes[0]&&t.flags===e.flags||(e.op=S.Op.CHAR_CLASS,e.runes=(new We).appendLiteral(e.runes[0],e.flags).appendLiteral(t.runes[0],t.flags).toArray())}}static parseEscape(r){var e=r.pos();if(r.skip(1),!r.more())throw new _e(I.ERR_TRAILING_BACKSLASH);let n=r.pop();e:switch(n){case p.CODES.get("1"):case p.CODES.get("2"):case p.CODES.get("3"):case p.CODES.get("4"):case p.CODES.get("5"):case p.CODES.get("6"):case p.CODES.get("7"):if(!r.more()||r.peek()<p.CODES.get("0")||r.peek()>p.CODES.get("7"))break;case p.CODES.get("0"):{let e=n-p.CODES.get("0");for(let t=1;t<3&&!(!r.more()||r.peek()<p.CODES.get("0")||r.peek()>p.CODES.get("7"));t++)e=8*e+r.peek()-p.CODES.get("0"),r.skip(1);return e}case p.CODES.get("x"):if(!r.more())break;if((n=r.pop())===p.CODES.get("{")){let e=0,t=0;for(;;){if(!r.more())break e;if((n=r.pop())===p.CODES.get("}"))break;var i=f.unhex(n);if(i<0)break e;if((t=16*t+i)>d.MAX_RUNE)break e;e++}if(0===e)break;return t}var t=f.unhex(n);if(!r.more())break;n=r.pop();var s=f.unhex(n);if(t<0||s<0)break;return 16*t+s;case p.CODES.get("a"):return p.CODES.get("");case p.CODES.get("f"):return p.CODES.get("\f");case p.CODES.get("n"):return p.CODES.get("\n");case p.CODES.get("r"):return p.CODES.get("\r");case p.CODES.get("t"):return p.CODES.get("\t");case p.CODES.get("v"):return p.CODES.get("\v");default:if(f.isalnum(n))break;return n}throw new _e(I.ERR_INVALID_ESCAPE,r.from(e))}static parseClassChar(e,t){if(e.more())return e.lookingAt("\\")?I.parseEscape(e):e.pop();throw new _e(I.ERR_MISSING_BRACKET,e.from(t))}static concatRunes(e,t){return[...e,...t]}constructor(e,t=0){this.wholeRegexp=e,this.flags=t,this.numCap=0,this.namedGroups={},this.stack=[],this.free=null}newRegexp(e){let t=this.free;return null!==t&&null!==t.subs&&0<t.subs.length?(this.free=t.subs[0],t.reinit(),t.op=e):t=new S(e),t}reuse(e){null!==e.subs&&0<e.subs.length&&(e.subs[0]=this.free),this.free=e}pop(){return this.stack.pop()}popToPseudo(){var e=this.stack.length;let t=e;for(;0<t&&!S.isPseudoOp(this.stack[t-1].op);)t--;e=this.stack.slice(t,e);return this.stack=this.stack.slice(0,t),e}push(e){if(e.op===S.Op.CHAR_CLASS&&2===e.runes.length&&e.runes[0]===e.runes[1]){if(this.maybeConcat(e.runes[0],this.flags&~b.FOLD_CASE))return null;e.op=S.Op.LITERAL,e.runes=[e.runes[0]],e.flags=this.flags&~b.FOLD_CASE}else if(e.op===S.Op.CHAR_CLASS&&4===e.runes.length&&e.runes[0]===e.runes[1]&&e.runes[2]===e.runes[3]&&d.simpleFold(e.runes[0])===e.runes[2]&&d.simpleFold(e.runes[2])===e.runes[0]||e.op===S.Op.CHAR_CLASS&&2===e.runes.length&&e.runes[0]+1===e.runes[1]&&d.simpleFold(e.runes[0])===e.runes[1]&&d.simpleFold(e.runes[1])===e.runes[0]){if(this.maybeConcat(e.runes[0],this.flags|b.FOLD_CASE))return null;e.op=S.Op.LITERAL,e.runes=[e.runes[0]],e.flags=this.flags|b.FOLD_CASE}else this.maybeConcat(-1,0);return this.stack.push(e),e}maybeConcat(e,t){var r=this.stack.length;if(!(r<2)){var n=this.stack[r-1],r=this.stack[r-2];if(n.op===S.Op.LITERAL&&r.op===S.Op.LITERAL&&(n.flags&b.FOLD_CASE)==(r.flags&b.FOLD_CASE)){if(r.runes=I.concatRunes(r.runes,n.runes),0<=e)return n.runes=[e],n.flags=t,!0;this.pop(),this.reuse(n)}}return!1}newLiteral(e,t){var r=this.newRegexp(S.Op.LITERAL);return 0!=((r.flags=t)&b.FOLD_CASE)&&(e=I.minFoldRune(e)),r.runes=[e],r}literal(e){this.push(this.newLiteral(e,this.flags))}op(e){var t=this.newRegexp(e);return t.flags=this.flags,this.push(t)}repeat(e,t,r,n,i,s){let a=this.flags;if(0!=(a&b.PERL_X)&&(i.more()&&i.lookingAt("?")&&(i.skip(1),a^=b.NON_GREEDY),-1!==s))throw new _e(I.ERR_INVALID_REPEAT_OP,i.from(s));var o=this.stack.length;if(0===o)throw new _e(I.ERR_MISSING_REPEAT_ARGUMENT,i.from(n));var u=this.stack[o-1];if(S.isPseudoOp(u.op))throw new _e(I.ERR_MISSING_REPEAT_ARGUMENT,i.from(n));var l=this.newRegexp(e);l.min=t,l.max=r,l.flags=a,l.subs=[u],this.stack[o-1]=l}concat(){this.maybeConcat(-1,0);var e=this.popToPseudo();return 0===e.length?this.push(this.newRegexp(S.Op.EMPTY_MATCH)):this.push(this.collapse(e,S.Op.CONCAT))}alternate(){var e=this.popToPseudo();return 0<e.length&&this.cleanAlt(e[e.length-1]),0===e.length?this.push(this.newRegexp(S.Op.NO_MATCH)):this.push(this.collapse(e,S.Op.ALTERNATE))}cleanAlt(e){e.op===S.Op.CHAR_CLASS&&(e.runes=new We(e.runes).cleanClass().toArray(),2===e.runes.length&&0===e.runes[0]&&e.runes[1]===d.MAX_RUNE?(e.runes=null,e.op=S.Op.ANY_CHAR):4===e.runes.length&&0===e.runes[0]&&e.runes[1]===p.CODES.get("\n")-1&&e.runes[2]===p.CODES.get("\n")+1&&e.runes[3]===d.MAX_RUNE&&(e.runes=null,e.op=S.Op.ANY_CHAR_NOT_NL))}collapse(e,t){if(1===e.length)return e[0];let r=0;for(var n of e)r+=n.op===t?n.subs.length:1;var i,s,a=new Array(r).fill(null);let o=0;for(i of e)i.op===t?(a.splice(o,i.subs.length,...i.subs),o+=i.subs.length,this.reuse(i)):a[o++]=i;let u=this.newRegexp(t);return u.subs=a,t===S.Op.ALTERNATE&&(u.subs=this.factor(u.subs),1===u.subs.length)&&(u=(s=u).subs[0],this.reuse(s)),u}factor(i){if(i.length<2)return i;let s=0,a=i.length,o=0,u=null,l=0,h=0,c=0;for(let _=0;_<=a;_++){let t=null,r=0,n=0;if(_<a){let e=i[s+_];if((e=e.op===S.Op.CONCAT&&0<e.subs.length?e.subs[0]:e).op===S.Op.LITERAL&&(t=e.runes,r=e.runes.length,n=e.flags&b.FOLD_CASE),n===h){let e=0;for(;e<l&&e<r&&u[e]===t[e];)e++;if(0<e){l=e;continue}}}if(_!==c)if(_===c+1)i[o++]=i[s+c];else{var d=this.newRegexp(S.Op.LITERAL);d.flags=h,d.runes=u.slice(0,l);for(let e=c;e<_;e++)i[s+e]=this.removeLeadingString(i[s+e],l);var p=this.collapse(i.slice(s+c,s+_),S.Op.ALTERNATE),f=this.newRegexp(S.Op.CONCAT);f.subs=[d,p],i[o++]=f}c=_,u=t,l=r,h=n}a=o,s=0,c=0;let t=null;for(let E=o=0;E<=a;E++){let e=null;if(!(E<a&&(e=I.leadingRegexp(i[s+E]),null!==t)&&t.equals(e)&&(I.isCharClass(t)||t.op===S.Op.REPEAT&&t.min===t.max&&I.isCharClass(t.subs[0])))){if(E!==c)if(E===c+1)i[o++]=i[s+c];else{var r=t;for(let e=c;e<E;e++){var n=e!==c;i[s+e]=this.removeLeadingRegexp(i[s+e],n)}var g=this.collapse(i.slice(s+c,s+E),S.Op.ALTERNATE),m=this.newRegexp(S.Op.CONCAT);m.subs=[r,g],i[o++]=m}c=E,t=e}}a=o,s=0,c=0;for(let T=o=0;T<=a;T++)if(!(T<a&&I.isCharClass(i[s+T]))){if(T!==c){if(T!==c+1){let e=c;for(let t=c+1;t<T;t++){var v=i[s+e],y=i[s+t];(v.op<y.op||v.op===y.op&&(null!==v.runes?v.runes.length:0)<(null!==y.runes?y.runes.length:0))&&(e=t)}var w=i[s+c];i[s+c]=i[s+e],i[s+e]=w;for(let r=c+1;r<T;r++)I.mergeCharClass(i[s+c],i[s+r]),this.reuse(i[s+r]);this.cleanAlt(i[s+c])}i[o++]=i[s+c]}T<a&&(i[o++]=i[s+T]),c=T+1}a=o,s=0,c=0;for(let e=o=0;e<a;++e)e+1<a&&i[s+e].op===S.Op.EMPTY_MATCH&&i[s+e+1].op===S.Op.EMPTY_MATCH||(i[o++]=i[s+e]);return a=o,s=0,i.slice(s,a)}removeLeadingString(e,t){if(e.op===S.Op.CONCAT&&0<e.subs.length){var r=this.removeLeadingString(e.subs[0],t);if((e.subs[0]=r).op===S.Op.EMPTY_MATCH)switch(this.reuse(r),e.subs.length){case 0:case 1:e.op=S.Op.EMPTY_MATCH,e.subs=null;break;case 2:var n=e;e=e.subs[1],this.reuse(n);break;default:e.subs=e.subs.slice(1,e.subs.length)}}else e.op===S.Op.LITERAL&&(e.runes=e.runes.slice(t,e.runes.length),0===e.runes.length)&&(e.op=S.Op.EMPTY_MATCH);return e}removeLeadingRegexp(e,t){if(e.op===S.Op.CONCAT&&0<e.subs.length){switch(t&&this.reuse(e.subs[0]),e.subs=e.subs.slice(1,e.subs.length),e.subs.length){case 0:e.op=S.Op.EMPTY_MATCH,e.subs=S.emptySubs();break;case 1:var r=e;e=e.subs[0],this.reuse(r)}return e}return t&&this.reuse(e),this.newRegexp(S.Op.EMPTY_MATCH)}parseInternal(){if(0!=(this.flags&b.LITERAL))return I.literalRegexp(this.wholeRegexp,this.flags);let r=-1,n=-1,i=-1;for(var s=new Je(this.wholeRegexp);s.more();){let t=-1;e:switch(s.peek()){case p.CODES.get("("):0!=(this.flags&b.PERL_X)&&s.lookingAt("(?")?this.parsePerlFlags(s):(this.op(S.Op.LEFT_PAREN).cap=++this.numCap,s.skip(1));break;case p.CODES.get("|"):this.parseVerticalBar(),s.skip(1);break;case p.CODES.get(")"):this.parseRightParen(),s.skip(1);break;case p.CODES.get("^"):0!=(this.flags&b.ONE_LINE)?this.op(S.Op.BEGIN_TEXT):this.op(S.Op.BEGIN_LINE),s.skip(1);break;case p.CODES.get("$"):0!=(this.flags&b.ONE_LINE)?this.op(S.Op.END_TEXT).flags|=b.WAS_DOLLAR:this.op(S.Op.END_LINE),s.skip(1);break;case p.CODES.get("."):0!=(this.flags&b.DOT_NL)?this.op(S.Op.ANY_CHAR):this.op(S.Op.ANY_CHAR_NOT_NL),s.skip(1);break;case p.CODES.get("["):this.parseClass(s);break;case p.CODES.get("*"):case p.CODES.get("+"):case p.CODES.get("?"):{t=s.pos();let e=null;switch(s.pop()){case p.CODES.get("*"):e=S.Op.STAR;break;case p.CODES.get("+"):e=S.Op.PLUS;break;case p.CODES.get("?"):e=S.Op.QUEST}this.repeat(e,n,i,t,s,r);break}case p.CODES.get("{"):t=s.pos();var e=I.parseRepeat(s);e<0?(s.rewindTo(t),this.literal(s.pop())):(n=e>>16,i=(e&d.MAX_BMP)<<16>>16,this.repeat(S.Op.REPEAT,n,i,t,s,r));break;case p.CODES.get("\\"):var a=s.pos();if(s.skip(1),0!=(this.flags&b.PERL_X)&&s.more())switch(s.pop()){case p.CODES.get("A"):this.op(S.Op.BEGIN_TEXT);break e;case p.CODES.get("b"):this.op(S.Op.WORD_BOUNDARY);break e;case p.CODES.get("B"):this.op(S.Op.NO_WORD_BOUNDARY);break e;case p.CODES.get("C"):throw new _e(I.ERR_INVALID_ESCAPE,"\\C");case p.CODES.get("Q"):{let e=s.rest();var o=e.indexOf("\\E");0<=o&&(e=e.substring(0,o)),s.skipString(e),s.skipString("\\E");let t=0;for(;t<e.length;){var u=e.codePointAt(t);this.literal(u),t+=f.charCount(u)}break e}case p.CODES.get("z"):this.op(S.Op.END_TEXT);break e;default:s.rewindTo(a)}var l=this.newRegexp(S.Op.CHAR_CLASS);if(l.flags=this.flags,s.lookingAt("\\p")||s.lookingAt("\\P")){e=new We;if(this.parseUnicodeClass(s,e)){l.runes=e.toArray(),this.push(l);break}}var h=new We;this.parsePerlClassEscape(s,h)?(l.runes=h.toArray(),this.push(l)):(s.rewindTo(a),this.reuse(l),this.literal(I.parseEscape(s)));break;default:this.literal(s.pop())}r=t}if(this.concat(),this.swapVerticalBar()&&this.pop(),this.alternate(),1!==this.stack.length)throw new _e(I.ERR_MISSING_PAREN,this.wholeRegexp);return this.stack[0].namedGroups=this.namedGroups,this.stack[0]}parsePerlFlags(n){var i=n.pos(),e=n.rest();if(!e.startsWith("(?P<")&&!e.startsWith("(?<")){n.skip(2);let e=this.flags,t=1,r=!1;e:for(;n.more();){var s=n.pop();switch(s){case p.CODES.get("i"):e|=b.FOLD_CASE,r=!0;break;case p.CODES.get("m"):e&=~b.ONE_LINE,r=!0;break;case p.CODES.get("s"):e|=b.DOT_NL,r=!0;break;case p.CODES.get("U"):e|=b.NON_GREEDY,r=!0;break;case p.CODES.get("-"):if(t<0)break e;t=-1,e=~e,r=!1;break;case p.CODES.get(":"):case p.CODES.get(")"):if(t<0){if(!r)break e;e=~e}return s===p.CODES.get(":")&&this.op(S.Op.LEFT_PAREN),void(this.flags=e);default:break e}}throw new _e(I.ERR_INVALID_PERL_OP,n.from(i))}var i="P"===e.charAt(2)?4:3,t=e.indexOf(">");if(t<0)throw new _e(I.ERR_INVALID_NAMED_CAPTURE,e);var r=e.substring(i,t);if(n.skipString(r),n.skip(1+i),!I.isValidCaptureName(r))throw new _e(I.ERR_INVALID_NAMED_CAPTURE,e.substring(0,t+1));i=this.op(S.Op.LEFT_PAREN);if(i.cap=++this.numCap,this.namedGroups[r])throw new _e(I.ERR_DUPLICATE_NAMED_CAPTURE,r);this.namedGroups[r]=this.numCap,i.name=r}parseVerticalBar(){this.concat(),this.swapVerticalBar()||this.op(S.Op.VERTICAL_BAR)}swapVerticalBar(){var r=this.stack.length;if(3<=r&&this.stack[r-2].op===S.Op.VERTICAL_BAR&&I.isCharClass(this.stack[r-1])&&I.isCharClass(this.stack[r-3])){let e=this.stack[r-1],t=this.stack[r-3];return e.op>t.op&&(n=t,t=e,e=n,this.stack[r-3]=t),I.mergeCharClass(t,e),this.reuse(e),this.pop(),!0}if(2<=r){var n=this.stack[r-1],e=this.stack[r-2];if(e.op===S.Op.VERTICAL_BAR)return 3<=r&&this.cleanAlt(this.stack[r-3]),this.stack[r-2]=n,this.stack[r-1]=e,!0}return!1}parseRightParen(){if(this.concat(),this.swapVerticalBar()&&this.pop(),this.alternate(),this.stack.length<2)throw new _e(I.ERR_INTERNAL_ERROR,"stack underflow");var e=this.pop(),t=this.pop();if(t.op!==S.Op.LEFT_PAREN)throw new _e(I.ERR_MISSING_PAREN,this.wholeRegexp);this.flags=t.flags,0===t.cap?this.push(e):(t.op=S.Op.CAPTURE,t.subs=[e],this.push(t))}parsePerlClassEscape(e,t){var r=e.pos();if(0==(this.flags&b.PERL_X)||!e.more()||e.pop()!==p.CODES.get("\\")||!e.more())return!1;e.pop();r=e.from(r),r=Pe.has(r)?Pe.get(r):null;return null!==r&&(t.appendGroup(r,0!=(this.flags&b.FOLD_CASE)),!0)}parseNamedClass(e,t){var r=e.rest(),n=r.indexOf(":]");if(n<0)return!1;r=r.substring(0,n+2),e.skipString(r),n=Ye.has(r)?Ye.get(r):null;if(null===n)throw new _e(I.ERR_INVALID_CHAR_RANGE,r);return t.appendGroup(n,0!=(this.flags&b.FOLD_CASE)),!0}parseUnicodeClass(e,t){var r=e.pos();if(0==(this.flags&b.UNICODE_GROUPS)||!e.lookingAt("\\p")&&!e.lookingAt("\\P"))return!1;e.skip(1);let n=1;if(e.pop()===p.CODES.get("P")&&(n=-1),!e.more())throw e.rewindTo(r),new _e(I.ERR_INVALID_CHAR_RANGE,e.rest());let i;if((s=e.pop())!==p.CODES.get("{"))i=f.runeToString(s);else{var s=e.rest(),a=s.indexOf("}");if(a<0)throw e.rewindTo(r),new _e(I.ERR_INVALID_CHAR_RANGE,e.rest());i=s.substring(0,a),e.skipString(i),e.skip(1)}0!==i.length&&i.codePointAt(0)===p.CODES.get("^")&&(n=0-n,i=i.substring(1));s=I.unicodeTable(i);if(null===s)throw new _e(I.ERR_INVALID_CHAR_RANGE,e.from(r));a=s.first,r=s.second;return 0==(this.flags&b.FOLD_CASE)||null===r?t.appendTableWithSign(a,n):(s=(new We).appendTable(a).appendTable(r).cleanClass().toArray(),t.appendClassWithSign(s,n)),!0}parseClass(t){var r=t.pos(),e=(t.skip(1),this.newRegexp(S.Op.CHAR_CLASS)),n=(e.flags=this.flags,new We);let i=1,s=(t.more()&&t.lookingAt("^")&&(i=-1,t.skip(1),0==(this.flags&b.CLASS_NL))&&n.appendRange(p.CODES.get("\n"),p.CODES.get("\n")),!0);for(;!t.more()||t.peek()!==p.CODES.get("]")||s;){if(t.more()&&t.lookingAt("-")&&0==(this.flags&b.PERL_X)&&!s){var a=t.rest();if("-"===a||!a.startsWith("-]"))throw t.rewindTo(r),new _e(I.ERR_INVALID_CHAR_RANGE,t.rest())}s=!1;a=t.pos();if(t.lookingAt("[:")){if(this.parseNamedClass(t,n))continue;t.rewindTo(a)}if(!this.parseUnicodeClass(t,n)&&!this.parsePerlClassEscape(t,n)){t.rewindTo(a);var o=I.parseClassChar(t,r);let e=o;if(t.more()&&t.lookingAt("-"))if(t.skip(1),t.more()&&t.lookingAt("]"))t.skip(-1);else if((e=I.parseClassChar(t,r))<o)throw new _e(I.ERR_INVALID_CHAR_RANGE,t.from(a));0==(this.flags&b.FOLD_CASE)?n.appendRange(o,e):n.appendFoldedRange(o,e)}}t.skip(1),n.cleanClass(),i<0&&n.negateClass(),e.runes=n.toArray(),this.push(e)}}class Ze{constructor(){this.inst=null,this.cap=[]}}class et{constructor(){this.sparse=[],this.densePcs=[],this.denseThreads=[],this.size=0}contains(e){var t=this.sparse[e];return t<this.size&&this.densePcs[t]===e}isEmpty(){return 0===this.size}add(e){var t=this.size++;return this.sparse[e]=t,this.denseThreads[t]=null,this.densePcs[t]=e,t}clear(){this.sparse=[],this.densePcs=[],this.denseThreads=[],this.size=0}toString(){let e="{";for(let t=0;t<this.size;t++)0!==t&&(e+=", "),e+=this.densePcs[t];return e+="}"}}class tt{static fromRE2(e){var t=new tt;return t.prog=e.prog,t.re2=e,t.q0=new et(t.prog.numInst()),t.q1=new et(t.prog.numInst()),t.pool=[],t.poolSize=0,t.matched=!1,t.matchcap=Array(t.prog.numCap<2?2:t.prog.numCap).fill(0),t.ncap=0,t}static fromMachine(e){var t=new tt;return t.re2=e.re2,t.prog=e.prog,t.q0=e.q0,t.q1=e.q1,t.pool=e.pool,t.poolSize=e.poolSize,t.matched=e.matched,t.matchcap=e.matchcap,t.ncap=e.ncap,t}init(e){(this.ncap=e)>this.matchcap.length?this.initNewCap(e):this.resetCap(e)}resetCap(e){for(let t=0;t<this.poolSize;t++)this.pool[t].cap=Array(e).fill(0)}initNewCap(e){for(let t=0;t<this.poolSize;t++)this.pool[t].cap=Array(e).fill(0);this.matchcap=Array(e).fill(0)}submatches(){return 0===this.ncap?f.emptyInts():this.matchcap.slice(0,this.ncap)}alloc(e){let t;return(t=0<this.poolSize?(this.poolSize--,this.pool[this.poolSize]):new Ze).inst=e,t}freeQueue(e,t=0){var r=e.size-t,r=this.poolSize+r;this.pool.length<r&&(this.pool=this.pool.slice(0,Math.max(2*this.pool.length,r)));for(let i=t;i<e.size;i++){var n=e.denseThreads[i];null!==n&&(this.pool[this.poolSize]=n,this.poolSize++)}e.clear()}freeThread(e){this.pool.length<=this.poolSize&&(this.pool=this.pool.slice(0,2*this.pool.length)),this.pool[this.poolSize]=e,this.poolSize++}match(e,t,r){var n=this.re2.cond;if(n===f.EMPTY_ALL)return!1;if((r===b.ANCHOR_START||r===b.ANCHOR_BOTH)&&0!==t)return!1;this.matched=!1,this.matchcap=Array(this.prog.numCap).fill(-1);let i=this.q0,s=this.q1,a=e.step(t),o=a>>3,u=7&a,l=-1,h=0;a!==Ie.EOF()&&(a=e.step(t+u),l=a>>3,h=7&a);let c;for(c=0===t?f.emptyOpContext(-1,o):e.context(t);;){if(i.isEmpty()){if(0!=(n&f.EMPTY_BEGIN_TEXT)&&0!==t)break;if(this.matched)break;if(0!==this.re2.prefix.length&&l!==this.re2.prefixRune&&e.canCheckPrefix()){var d=e.index(this.re2,t);if(d<0)break;t+=d,a=e.step(t),o=a>>3,u=7&a,a=e.step(t+u),l=a>>3,h=7&a}}this.matched||0!==t&&r!==b.UNANCHORED||(0<this.ncap&&(this.matchcap[0]=t),this.add(i,this.prog.start,t,this.matchcap,c,null));d=t+u;if(c=e.context(d),this.step(i,s,t,d,o,c,r,t===e.endPos()),0===u)break;if(0===this.ncap&&this.matched)break;t+=u,o=l,u=h,-1!==o&&(a=e.step(t+u),l=a>>3,h=7&a);var p=i;i=s,s=p}return this.freeQueue(s),this.matched}step(r,n,i,s,a,o,u,l){var h=this.re2.longest;for(let d=0;d<r.size;d++){let t=r.denseThreads[d];if(null!==t)if(h&&this.matched&&0<this.ncap&&this.matchcap[0]<t.cap[0])this.freeThread(t);else{var c=t.inst;let e=!1;switch(c.op){case g.MATCH:u===b.ANCHOR_BOTH&&!l||(0<this.ncap&&(!h||!this.matched||this.matchcap[1]<i)&&(t.cap[1]=i,this.matchcap=t.cap.slice(0,this.ncap)),h||this.freeQueue(r,d+1),this.matched=!0);break;case g.RUNE:e=c.matchRune(a);break;case g.RUNE1:e=a===c.runes[0];break;case g.RUNE_ANY:e=!0;break;case g.RUNE_ANY_NOT_NL:e=a!==p.CODES.get("\n");break;default:throw new Error("bad inst")}null!==(t=e?this.add(n,c.out,s,t.cap,o,t):t)&&(this.freeThread(t),r.denseThreads[d]=null)}}r.clear()}add(e,t,r,n,i,s){if(0!==t&&!e.contains(t)){var a,o=e.add(t),u=this.prog.inst[t];switch(u.op){case g.FAIL:break;case g.ALT:case g.ALT_MATCH:s=this.add(e,u.out,r,n,i,s),s=this.add(e,u.arg,r,n,i,s);break;case g.EMPTY_WIDTH:0==(u.arg&~i)&&(s=this.add(e,u.out,r,n,i,s));break;case g.NOP:s=this.add(e,u.out,r,n,i,s);break;case g.CAPTURE:u.arg<this.ncap?(a=n[u.arg],n[u.arg]=r,this.add(e,u.out,r,n,i,null),n[u.arg]=a):s=this.add(e,u.out,r,n,i,s);break;case g.MATCH:case g.RUNE:case g.RUNE1:case g.RUNE_ANY:case g.RUNE_ANY_NOT_NL:null===s?s=this.alloc(u):s.inst=u,0<this.ncap&&s.cap!==n&&(s.cap=n.slice(0,this.ncap)),e.denseThreads[o]=s,s=null;break;default:throw new Error("unhandled")}}return s}}class rt{constructor(e){this.value=e}get(){return this.value}set(e){this.value=e}compareAndSet(e,t){return this.value===e&&(this.value=t,!0)}}class nt{static initTest(e){var t=nt.compile(e),r=new nt(t.expr,t.prog,t.numSubexp,t.longest);return r.cond=t.cond,r.prefix=t.prefix,r.prefixUTF8=t.prefixUTF8,r.prefixComplete=t.prefixComplete,r.prefixRune=t.prefixRune,r}static compile(e){return nt.compileImpl(e,b.PERL,!1)}static compilePOSIX(e){return nt.compileImpl(e,b.POSIX,!0)}static compileImpl(e,t,r){let n=I.parse(e,t);var i=n.maxCap(),s=(n=Re.simplify(n),Oe.compileRegexp(n)),i=new nt(e,s,i,r),[s,a]=s.prefix();return i.prefixComplete=s,i.prefix=a,i.prefixUTF8=f.stringToUtf8ByteArray(i.prefix),0<i.prefix.length&&(i.prefixRune=i.prefix.codePointAt(0)),i.namedGroups=n.namedGroups,i}static match(e,t){return nt.compile(e).match(t)}constructor(e,t,r=0,n=0){this.expr=e,this.prog=t,this.numSubexp=r,this.longest=n,this.cond=t.startCond(),this.prefix=null,this.prefixUTF8=null,this.prefixComplete=!1,this.prefixRune=0,this.pooled=new rt}numberOfCapturingGroups(){return this.numSubexp}get(){let e;for(;(e=this.pooled.get())&&!this.pooled.compareAndSet(e,e.next););return e}reset(){this.pooled.set(null)}put(e,t){var r;for(this.pooled.get();r=this.pooled.get(),!t&&r&&(e=tt.fromMachine(e),t=!0),e.next!==r&&(e.next=r),!this.pooled.compareAndSet(r,e););}toString(){return this.expr}doExecute(e,t,r,n){let i=this.get(),s=!1;i?null!==i.next&&(i=tt.fromMachine(i),s=!0):(i=tt.fromRE2(this),s=!0),i.init(n);var a=i.match(e,t,r)?i.submatches():null;return this.put(i,s),a}match(e){return null!==this.doExecute(xe.fromUTF16(e),0,b.UNANCHORED,0)}matchWithGroup(e,t,r,n,i){return e instanceof ge||(e=ye.utf16(e)),this.matchMachineInput(e,t,r,n,i)}matchMachineInput(e,t,r,n,i){var s;return r<t||(s=e.isUTF16Encoding()?xe.fromUTF16(e.asCharSequence(),0,r):xe.fromUTF8(e.asBytes(),0,r),null===(s=this.doExecute(s,t,n,2*i)))?[!1,null]:[!0,s]}matchUTF8(e){return null!==this.doExecute(xe.fromUTF8(e),0,b.UNANCHORED,0)}replaceAll(e,t){return this.replaceAllFunc(e,()=>t,2*e.length+1)}replaceFirst(e,t){return this.replaceAllFunc(e,()=>t,1)}replaceAllFunc(e,t,r){let n=0,i=0,s="";var a=xe.fromUTF16(e);let o=0;for(;i<=e.length;){var u=this.doExecute(a,i,b.UNANCHORED,2);if(null===u||0===u.length)break;s+=e.substring(n,u[0]),(u[1]>n||0===u[0])&&(s+=t(e.substring(u[0],u[1])),o++),n=u[1];var l=7&a.step(i);if(i+l>u[1]?i+=l:i+1>u[1]?i++:i=u[1],o>=r)break}return s+=e.substring(n)}pad(t){if(null===t)return null;var r=2*(1+this.numSubexp);if(t.length<r){var n=new Array(r).fill(-1);for(let e=0;e<t.length;e++)n[e]=t[e];t=n}return t}allMatches(t,e,r=e=>e){var n=[],i=t.endPos();e<0&&(e=i+1);let s=0,a=0,o=-1;for(;a<e&&s<=i;){var u,l=this.doExecute(t,s,b.UNANCHORED,this.prog.numCap);if(null===l||0===l.length)break;let e=!0;l[1]===s?(l[0]===o&&(e=!1),(u=t.step(s))<0?s=i+1:s+=7&u):s=l[1],o=l[1],e&&(n.push(r(this.pad(l))),a++)}return n}findUTF8(e){var t=this.doExecute(xe.fromUTF8(e),0,b.UNANCHORED,2);return null===t?null:e.slice(t[0],t[1])}findUTF8Index(e){var t=this.doExecute(xe.fromUTF8(e),0,b.UNANCHORED,2);return null===t?null:t.slice(0,2)}find(e){var t=this.doExecute(xe.fromUTF16(e),0,b.UNANCHORED,2);return null===t?"":e.substring(t[0],t[1])}findIndex(e){return this.doExecute(xe.fromUTF16(e),0,b.UNANCHORED,2)}findUTF8Submatch(e){var t=this.doExecute(xe.fromUTF8(e),0,b.UNANCHORED,this.prog.numCap);if(null===t)return null;var r=new Array(1+this.numSubexp).fill(null);for(let n=0;n<r.length;n++)2*n<t.length&&0<=t[2*n]&&(r[n]=e.slice(t[2*n],t[2*n+1]));return r}findUTF8SubmatchIndex(e){return this.pad(this.doExecute(xe.fromUTF8(e),0,b.UNANCHORED,this.prog.numCap))}findSubmatch(e){var t=this.doExecute(xe.fromUTF16(e),0,b.UNANCHORED,this.prog.numCap);if(null===t)return null;var r=new Array(1+this.numSubexp).fill(null);for(let n=0;n<r.length;n++)2*n<t.length&&0<=t[2*n]&&(r[n]=e.substring(t[2*n],t[2*n+1]));return r}findSubmatchIndex(e){return this.pad(this.doExecute(xe.fromUTF16(e),0,b.UNANCHORED,this.prog.numCap))}findAllUTF8(t,e){var r=this.allMatches(xe.fromUTF8(t),e,e=>t.slice(e[0],e[1]));return 0===r.length?null:r}findAllUTF8Index(e,t){var r=this.allMatches(xe.fromUTF8(e),t,e=>e.slice(0,2));return 0===r.length?null:r}findAll(t,e){var r=this.allMatches(xe.fromUTF16(t),e,e=>t.substring(e[0],e[1]));return 0===r.length?null:r}findAllIndex(e,t){var r=this.allMatches(xe.fromUTF16(e),t,e=>e.slice(0,2));return 0===r.length?null:r}findAllUTF8Submatch(n,e){var t=this.allMatches(xe.fromUTF8(n),e,e=>{var t=new Array(e.length/2|0).fill(null);for(let r=0;r<t.length;r++)0<=e[2*r]&&(t[r]=n.slice(e[2*r],e[2*r+1]));return t});return 0===t.length?null:t}findAllUTF8SubmatchIndex(e,t){var r=this.allMatches(xe.fromUTF8(e),t);return 0===r.length?null:r}findAllSubmatch(n,e){var t=this.allMatches(xe.fromUTF16(n),e,e=>{var t=new Array(e.length/2|0).fill(null);for(let r=0;r<t.length;r++)0<=e[2*r]&&(t[r]=n.substring(e[2*r],e[2*r+1]));return t});return 0===t.length?null:t}findAllSubmatchIndex(e,t){var r=this.allMatches(xe.fromUTF16(e),t);return 0===r.length?null:r}}class it{static CASE_INSENSITIVE=1;static DOTALL=2;static MULTILINE=4;static DISABLE_UNICODE_GROUPS=8;static LONGEST_MATCH=16;static quote(e){return f.quoteMeta(e)}static compile(e,t=0){let r=e;if(0!=(t&it.CASE_INSENSITIVE)&&(r="(?i)"+r),0!=(t&it.DOTALL)&&(r="(?s)"+r),0!=(t&it.MULTILINE)&&(r="(?m)"+r),0!=(t&~(it.MULTILINE|it.DOTALL|it.CASE_INSENSITIVE|it.DISABLE_UNICODE_GROUPS|it.LONGEST_MATCH)))throw new be("Flags should only be a combination of MULTILINE, DOTALL, CASE_INSENSITIVE, DISABLE_UNICODE_GROUPS, LONGEST_MATCH");let n=b.PERL;0!=(t&it.DISABLE_UNICODE_GROUPS)&&(n&=~b.UNICODE_GROUPS);var i=new it(e,t);return i.re2Input=nt.compileImpl(r,n,0!=(t&it.LONGEST_MATCH)),i}static matches(e,t){return it.compile(e).matcher(t).matches()}static initTest(e,t,r){if(null==e)throw new Error("pattern is null");if(null==r)throw new Error("re2 is null");var n=new it(e,t);return n.re2Input=r,n}constructor(e,t){this.patternInput=e,this.flagsInput=t}reset(){this.re2Input.reset()}flags(){return this.flagsInput}pattern(){return this.patternInput}re2(){return this.re2Input}matches(e){return this.matcher(e).matches()}matcher(e){return Array.isArray(e)&&(e=ye.utf8(e)),new Se(this,e)}split(e,t=0){var r=this.matcher(e),n=[];let i=0,s=0;for(;r.find();){if(0===s&&0===r.end());else{if(0<t&&n.length===t-1)break;if(s===r.start()){if(0===t){i+=1,s=r.end();continue}}else for(;0<i;)n.push(""),--i;n.push(r.substring(s,r.start()))}s=r.end()}if(0===t&&s!==r.inputLength()){for(;0<i;)n.push(""),--i;n.push(r.substring(s,r.inputLength()))}return 0===t&&0!==n.length||n.push(r.substring(s,r.inputLength())),n}toString(){return this.patternInput}groupCount(){return this.re2Input.numberOfCapturingGroups()}namedGroups(){return this.re2Input.namedGroups}equals(e){return this===e||null!==e&&this.constructor===e.constructor&&this.flagsInput===e.flagsInput&&this.patternInput===e.patternInput}}class st{constructor(e){this.uid=e}isAuthenticated(){return null!=this.uid}toKey(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"}isEqual(e){return e.uid===this.uid}}st.UNAUTHENTICATED=new st(null),st.GOOGLE_CREDENTIALS=new st("google-credentials-uid"),st.FIRST_PARTY=new st("first-party-uid"),st.MOCK_USER=new st("mock-user");let at="12.15.0";let ot=new class{constructor(e){this.name=e,this._logLevel=ce,this._logHandler=pe,this._userLogHandler=null}get logLevel(){return this._logLevel}set logLevel(e){if(!(e in c))throw new TypeError(`Invalid value "${e}" assigned to \`logLevel\``);this._logLevel=e}setLogLevel(e){this._logLevel="string"==typeof e?he[e]:e}get logHandler(){return this._logHandler}set logHandler(e){if("function"!=typeof e)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=e}get userLogHandler(){return this._userLogHandler}set userLogHandler(e){this._userLogHandler=e}debug(...e){this._userLogHandler&&this._userLogHandler(this,c.DEBUG,...e),this._logHandler(this,c.DEBUG,...e)}log(...e){this._userLogHandler&&this._userLogHandler(this,c.VERBOSE,...e),this._logHandler(this,c.VERBOSE,...e)}info(...e){this._userLogHandler&&this._userLogHandler(this,c.INFO,...e),this._logHandler(this,c.INFO,...e)}warn(...e){this._userLogHandler&&this._userLogHandler(this,c.WARN,...e),this._logHandler(this,c.WARN,...e)}error(...e){this._userLogHandler&&this._userLogHandler(this,c.ERROR,...e),this._logHandler(this,c.ERROR,...e)}}("@firebase/firestore");function ut(){return ot.logLevel}function m(e,...t){var r;ot.logLevel<=c.DEBUG&&(r=t.map(ct),ot.debug(`Firestore (${at}): `+e,...r))}function lt(e,...t){var r;ot.logLevel<=c.ERROR&&(r=t.map(ct),ot.error(`Firestore (${at}): `+e,...r))}function ht(e,...t){var r;ot.logLevel<=c.WARN&&(r=t.map(ct),ot.warn(`Firestore (${at}): `+e,...r))}function ct(t){if("string"==typeof t)return t;try{return JSON.stringify(t)}catch(e){return t}}function A(e,t,r){let n="Unexpected state";"string"==typeof t?n=t:r=t,dt(e,n,r)}function dt(e,t,r){let n=`FIRESTORE (${at}) INTERNAL ASSERTION FAILED: ${t} (ID: ${e.toString(16)})`;if(void 0!==r)try{n+=" CONTEXT: "+JSON.stringify(r)}catch(e){n+=" CONTEXT: "+r}throw lt(n),new Error(n)}function v(e,t,r,n){let i="Unexpected state";"string"==typeof r?i=r:n=r,e||dt(t,i,n)}let _={OK:"ok",CANCELLED:"cancelled",UNKNOWN:"unknown",INVALID_ARGUMENT:"invalid-argument",DEADLINE_EXCEEDED:"deadline-exceeded",NOT_FOUND:"not-found",ALREADY_EXISTS:"already-exists",PERMISSION_DENIED:"permission-denied",UNAUTHENTICATED:"unauthenticated",RESOURCE_EXHAUSTED:"resource-exhausted",FAILED_PRECONDITION:"failed-precondition",ABORTED:"aborted",OUT_OF_RANGE:"out-of-range",UNIMPLEMENTED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"};class E extends ee{constructor(e,t){super(e,t),this.code=e,this.message=t,this.toString=()=>`${this.name}: [code=${this.code}]: `+this.message}}class pt{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}class ft{constructor(e,t){this.user=t,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization","Bearer "+e)}}class gt{getToken(){return Promise.resolve(null)}invalidateToken(){}start(e,t){e.enqueueRetryable(()=>t(st.UNAUTHENTICATED))}shutdown(){}}class mt{constructor(e){this.token=e,this.changeListener=null}getToken(){return Promise.resolve(this.token)}invalidateToken(){}start(e,t){this.changeListener=t,e.enqueueRetryable(()=>t(this.token.user))}shutdown(){this.changeListener=null}}class vt{constructor(e){this.t=e,this.currentUser=st.UNAUTHENTICATED,this.i=0,this.forceRefresh=!1,this.auth=null}start(t,r){v(void 0===this.o,42304);let n=this.i,i=e=>this.i!==n?(n=this.i,r(e)):Promise.resolve(),s=new pt,a=(this.o=()=>{this.i++,this.currentUser=this.u(),s.resolve(),s=new pt,t.enqueueRetryable(()=>i(this.currentUser))},()=>{let e=s;t.enqueueRetryable(async()=>{await e.promise,await i(this.currentUser)})}),o=e=>{m("FirebaseAuthCredentialsProvider","Auth detected"),this.auth=e,this.o&&(this.auth.addAuthTokenListener(this.o),a())};this.t.onInit(e=>o(e)),setTimeout(()=>{var e;this.auth||((e=this.t.getImmediate({optional:!0}))?o(e):(m("FirebaseAuthCredentialsProvider","Auth not yet detected"),s.resolve(),s=new pt))},0),a()}getToken(){let t=this.i,e=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(e).then(e=>this.i!==t?(m("FirebaseAuthCredentialsProvider","getToken aborted due to token change."),this.getToken()):e?(v("string"==typeof e.accessToken,31837,{l:e}),new ft(e.accessToken,this.currentUser)):null):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.auth&&this.o&&this.auth.removeAuthTokenListener(this.o),this.o=void 0}u(){var e=this.auth&&this.auth.getUid();return v(null===e||"string"==typeof e,2055,{h:e}),new st(e)}}class yt{constructor(e,t,r){this.T=e,this.P=t,this.R=r,this.type="FirstParty",this.user=st.FIRST_PARTY,this.I=new Map}A(){return this.R?this.R():null}get headers(){this.I.set("X-Goog-AuthUser",this.T);var e=this.A();return e&&this.I.set("Authorization",e),this.P&&this.I.set("X-Goog-Iam-Authorization-Token",this.P),this.I}}class wt{constructor(e,t,r){this.T=e,this.P=t,this.R=r}getToken(){return Promise.resolve(new yt(this.T,this.P,this.R))}start(e,t){e.enqueueRetryable(()=>t(st.FIRST_PARTY))}shutdown(){}invalidateToken(){}}class _t{constructor(e){this.value=e,this.type="AppCheck",this.headers=new Map,e&&0<e.length&&this.headers.set("x-firebase-appcheck",this.value)}}class Et{constructor(e,t){this.V=t,this.forceRefresh=!1,this.appCheck=null,this.m=null,this.p=null,n7._isFirebaseServerApp(e)&&e.settings.appCheckToken&&(this.p=e.settings.appCheckToken)}start(t,r){v(void 0===this.o,3512);let n=e=>{null!=e.error&&m("FirebaseAppCheckTokenProvider","Error getting App Check token; using placeholder token instead. Error: "+e.error.message);var t=e.token!==this.m;return this.m=e.token,m("FirebaseAppCheckTokenProvider",`Received ${t?"new":"existing"} token.`),t?r(e.token):Promise.resolve()},i=(this.o=e=>{t.enqueueRetryable(()=>n(e))},e=>{m("FirebaseAppCheckTokenProvider","AppCheck detected"),this.appCheck=e,this.o&&this.appCheck.addTokenListener(this.o)});this.V.onInit(e=>i(e)),setTimeout(()=>{var e;this.appCheck||((e=this.V.getImmediate({optional:!0}))?i(e):m("FirebaseAppCheckTokenProvider","AppCheck not yet detected"))},0)}getToken(){var e;return this.p?Promise.resolve(new _t(this.p)):(e=this.forceRefresh,this.forceRefresh=!1,this.appCheck?this.appCheck.getToken(e).then(e=>e?(v("string"==typeof e.token,44558,{tokenResult:e}),this.m=e.token,new _t(e.token)):null):Promise.resolve(null))}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.o&&this.appCheck.removeTokenListener(this.o),this.o=void 0}}class Tt{static newId(){var t=62*Math.floor(256/62);let r="";for(;r.length<20;){var n=(t=>{var r="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(t);if(r&&"function"==typeof r.getRandomValues)r.getRandomValues(n);else for(let e=0;e<t;e++)n[e]=Math.floor(256*Math.random());return n})(40);for(let e=0;e<n.length;++e)r.length<20&&n[e]<t&&(r+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(n[e]%62))}return r}}function C(e,t){return e<t?-1:t<e?1:0}function bt(r,n){let e=Math.min(r.length,n.length);for(let i=0;i<e;i++){let e=r.charAt(i),t=n.charAt(i);if(e!==t)return At(e)===At(t)?C(e,t):At(e)?1:-1}return C(r.length,n.length)}let St=55296,It=57343;function At(e){var t=e.charCodeAt(0);return t>=St&&t<=It}function Ct(e,r,n){return e.length===r.length&&e.every((e,t)=>n(e,r[t]))}function xt(e){return e+"\0"}let Nt="__name__";class Dt{constructor(e,t,r){void 0===t?t=0:t>e.length&&A(637,{offset:t,range:e.length}),void 0===r?r=e.length-t:r>e.length-t&&A(1746,{length:r,range:e.length-t}),this.segments=e,this.offset=t,this.len=r}get length(){return this.len}isEqual(e){return 0===Dt.comparator(this,e)}child(e){let t=this.segments.slice(this.offset,this.limit());return e instanceof Dt?e.forEach(e=>{t.push(e)}):t.push(e),this.construct(t)}limit(){return this.offset+this.length}popFirst(e){return this.construct(this.segments,this.offset+(e=void 0===e?1:e),this.length-e)}popLast(){return this.construct(this.segments,this.offset,this.length-1)}firstSegment(){return this.segments[this.offset]}lastSegment(){return this.get(this.length-1)}get(e){return this.segments[this.offset+e]}isEmpty(){return 0===this.length}isPrefixOf(e){if(e.length<this.length)return!1;for(let t=0;t<this.length;t++)if(this.get(t)!==e.get(t))return!1;return!0}isImmediateParentOf(e){if(this.length+1!==e.length)return!1;for(let t=0;t<this.length;t++)if(this.get(t)!==e.get(t))return!1;return!0}forEach(e){for(let t=this.offset,r=this.limit();t<r;t++)e(this.segments[t])}toArray(){return this.segments.slice(this.offset,this.limit())}static comparator(t,r){let e=Math.min(t.length,r.length);for(let n=0;n<e;n++){let e=Dt.compareSegments(t.get(n),r.get(n));if(0!==e)return e}return C(t.length,r.length)}static compareSegments(e,t){var r=Dt.isNumericId(e),n=Dt.isNumericId(t);return r&&!n?-1:!r&&n?1:r&&n?Dt.extractNumericId(e).compare(Dt.extractNumericId(t)):bt(e,t)}static isNumericId(e){return e.startsWith("__id")&&e.endsWith("__")}static extractNumericId(e){return ue.fromString(e.substring(4,e.length-2))}}class T extends Dt{construct(e,t,r){return new T(e,t,r)}canonicalString(){return this.toArray().join("/")}toString(){return this.canonicalString()}toStringWithLeadingSlash(){return"/"+this.canonicalString()}toUriEncodedString(){return this.toArray().map(encodeURIComponent).join("/")}static fromString(...e){var t,r=[];for(t of e){if(0<=t.indexOf("//"))throw new E(_.INVALID_ARGUMENT,`Invalid segment (${t}). Paths must not contain // in them.`);r.push(...t.split("/").filter(e=>0<e.length))}return new T(r)}static emptyPath(){return new T([])}}let Ot=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class h extends Dt{construct(e,t,r){return new h(e,t,r)}static isValidIdentifier(e){return Ot.test(e)}canonicalString(){return this.toArray().map(e=>(e=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),e=h.isValidIdentifier(e)?e:"`"+e+"`")).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&this.get(0)===Nt}static keyField(){return new h([Nt])}static fromServerFormat(t){let e=[],r="",n=0;var i=()=>{if(0===r.length)throw new E(_.INVALID_ARGUMENT,`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);e.push(r),r=""};let s=!1;for(;n<t.length;){let e=t[n];if("\\"===e){if(n+1===t.length)throw new E(_.INVALID_ARGUMENT,"Path has trailing escape character: "+t);let e=t[n+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new E(_.INVALID_ARGUMENT,"Path has invalid escape sequence: "+t);r+=e,n+=2}else"`"===e?s=!s:"."!==e||s?r+=e:i(),n++}if(i(),s)throw new E(_.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new h(e)}static emptyPath(){return new h([])}}class x{constructor(e){this.path=e}static fromPath(e){return new x(T.fromString(e))}static fromName(e){return new x(T.fromString(e).popFirst(5))}static empty(){return new x(T.emptyPath())}get collectionGroup(){return this.path.popLast().lastSegment()}hasCollectionId(e){return 2<=this.path.length&&this.path.get(this.path.length-2)===e}getCollectionGroup(){return this.path.get(this.path.length-2)}getCollectionPath(){return this.path.popLast()}isEqual(e){return null!==e&&0===T.comparator(this.path,e.path)}toString(){return this.path.toString()}static comparator(e,t){return T.comparator(e.path,t.path)}static isDocumentKey(e){return e.length%2==0}static fromSegments(e){return new x(new T(e.slice()))}}function Rt(e,t,r){if(!r)throw new E(_.INVALID_ARGUMENT,`Function ${e}() cannot be called with an empty ${t}.`)}function kt(e,t,r,n){if(!0===t&&!0===n)throw new E(_.INVALID_ARGUMENT,e+` and ${r} cannot be used together.`)}function Lt(e){if(!x.isDocumentKey(e))throw new E(_.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${e} has ${e.length}.`)}function Pt(e){if(x.isDocumentKey(e))throw new E(_.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${e} has ${e.length}.`)}function Mt(e){return"object"==typeof e&&null!==e&&(Object.getPrototypeOf(e)===Object.prototype||null===Object.getPrototypeOf(e))}function Vt(e){var t,r;return void 0===e?"undefined":null===e?"null":"string"==typeof e?(20<e.length&&(e=e.substring(0,20)+"..."),JSON.stringify(e)):"number"==typeof e||"boolean"==typeof e?""+e:"object"==typeof e?e instanceof Array?"an array":(t=(r=e).constructor?r.constructor.name:null)?`a custom ${t} object`:"an object":"function"==typeof e?"a function":A(12329,{type:typeof e})}function y(e,t){if((e="_delegate"in e?e._delegate:e)instanceof t)return e;if(t.name===e.constructor.name)throw new E(_.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");var r=Vt(e);throw new E(_.INVALID_ARGUMENT,`Expected type '${t.name}', but it was: `+r)}function Ft(e,t){if(t<=0)throw new E(_.INVALID_ARGUMENT,`Function ${e}() requires a positive number, but it was: ${t}.`)}function Ut(e,t){var r={typeString:e};return t&&(r.value=t),r}function Bt(e,t){if(!Mt(e))throw new E(_.INVALID_ARGUMENT,"JSON must be an object");let r;for(var n in t)if(t[n]){var i=t[n].typeString,s="value"in t[n]?{value:t[n].value}:void 0;if(!(n in e)){r=`JSON missing required field: '${n}'`;break}var a=e[n];if(i&&typeof a!==i){r=`JSON field '${n}' must be a ${i}.`;break}if(void 0!==s&&a!==s.value){r=`Expected '${n}' field to equal '${s.value}'`;break}}if(r)throw new E(_.INVALID_ARGUMENT,r);return 1}let qt=-62135596800;class w{static now(){return w.fromMillis(Date.now())}static fromDate(e){return w.fromMillis(e.getTime())}static fromMillis(e){var t=Math.floor(e/1e3),r=Math.floor(1e6*(e-1e3*t));return new w(t,r)}constructor(e,t){if(this.seconds=e,(this.nanoseconds=t)<0)throw new E(_.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(1e9<=t)throw new E(_.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(e<qt)throw new E(_.INVALID_ARGUMENT,"Timestamp seconds out of range: "+e);if(253402300800<=e)throw new E(_.INVALID_ARGUMENT,"Timestamp seconds out of range: "+e)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(e){return this.seconds===e.seconds?C(this.nanoseconds,e.nanoseconds):C(this.seconds,e.seconds)}isEqual(e){return e.seconds===this.seconds&&e.nanoseconds===this.nanoseconds}toString(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"}toJSON(){return{type:w._jsonSchemaVersion,seconds:this.seconds,nanoseconds:this.nanoseconds}}static fromJSON(e){if(Bt(e,w._jsonSchema))return new w(e.seconds,e.nanoseconds)}valueOf(){var e=this.seconds-qt;return String(e).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")}}w._jsonSchemaVersion="firestore/timestamp/1.0",w._jsonSchema={type:Ut("string",w._jsonSchemaVersion),seconds:Ut("number"),nanoseconds:Ut("number")};class N{static fromTimestamp(e){return new N(e)}static min(){return new N(new w(0,0))}static max(){return new N(new w(253402300799,999999999))}constructor(e){this.timestamp=e}compareTo(e){return this.timestamp._compareTo(e.timestamp)}isEqual(e){return this.timestamp.isEqual(e.timestamp)}toMicroseconds(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3}toString(){return"SnapshotVersion("+this.timestamp.toString()+")"}toTimestamp(){return this.timestamp}}let Gt=-1;class jt{constructor(e,t,r,n){this.indexId=e,this.collectionGroup=t,this.fields=r,this.indexState=n}}function zt(e){return e.fields.find(e=>2===e.kind)}function Ht(e){return e.fields.filter(e=>2!==e.kind)}jt.UNKNOWN_ID=-1;class Kt{constructor(e,t){this.fieldPath=e,this.kind=t}}class $t{constructor(e,t){this.sequenceNumber=e,this.offset=t}static empty(){return new $t(0,Wt.min())}}function Qt(e,t){var r=e.toTimestamp().seconds,n=e.toTimestamp().nanoseconds+1,r=N.fromTimestamp(1e9===n?new w(r+1,0):new w(r,n));return new Wt(r,x.empty(),t)}function Yt(e){return new Wt(e.readTime,e.key,Gt)}class Wt{constructor(e,t,r){this.readTime=e,this.documentKey=t,this.largestBatchId=r}static min(){return new Wt(N.min(),x.empty(),Gt)}static max(){return new Wt(N.max(),x.empty(),Gt)}}function Xt(e,t){var r=e.readTime.compareTo(t.readTime);return 0!==r||0!==(r=x.comparator(e.documentKey,t.documentKey))?r:C(e.largestBatchId,t.largestBatchId)}let Jt="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.";class Zt{constructor(){this.onCommittedListeners=[]}addOnCommittedListener(e){this.onCommittedListeners.push(e)}raiseOnCommittedEvent(){this.onCommittedListeners.forEach(e=>e())}}async function er(e){if(e.code!==_.FAILED_PRECONDITION||e.message!==Jt)throw e;m("LocalStore","Unexpectedly lost primary lease")}class D{constructor(e){this.nextCallback=null,this.catchCallback=null,this.result=void 0,this.error=void 0,this.isDone=!1,this.callbackAttached=!1,e(e=>{this.isDone=!0,this.result=e,this.nextCallback&&this.nextCallback(e)},e=>{this.isDone=!0,this.error=e,this.catchCallback&&this.catchCallback(e)})}catch(e){return this.next(void 0,e)}next(n,i){return this.callbackAttached&&A(59440),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(i,this.error):this.wrapSuccess(n,this.result):new D((t,r)=>{this.nextCallback=e=>{this.wrapSuccess(n,e).next(t,r)},this.catchCallback=e=>{this.wrapFailure(i,e).next(t,r)}})}toPromise(){return new Promise((e,t)=>{this.next(e,t)})}wrapUserFunction(e){try{var t=e();return t instanceof D?t:D.resolve(t)}catch(e){return D.reject(e)}}wrapSuccess(e,t){return e?this.wrapUserFunction(()=>e(t)):D.resolve(t)}wrapFailure(e,t){return e?this.wrapUserFunction(()=>e(t)):D.reject(t)}static resolve(r){return new D((e,t)=>{e(r)})}static reject(r){return new D((e,t)=>{t(r)})}static waitFor(e){return new D((t,r)=>{let n=0,i=0,s=!1;e.forEach(e=>{++n,e.next(()=>{++i,s&&i===n&&t()},e=>r(e))}),s=!0,i===n&&t()})}static or(e){let t=D.resolve(!1);for(let r of e)t=t.next(e=>e?D.resolve(e):r());return t}static forEach(e,r){let n=[];return e.forEach((e,t)=>{n.push(r.call(this,e,t))}),this.waitFor(n)}static mapArray(o,u){return new D((r,n)=>{let i=o.length,s=new Array(i),a=0;for(let e=0;e<i;e++){let t=e;u(o[t]).next(e=>{s[t]=e,++a===i&&r(s)},e=>n(e))}})}static doWhile(n,i){return new D((e,t)=>{let r=()=>{!0===n()?i().next(()=>{r()},t):e()};r()})}}let tr="SimpleDb";class rr{static open(e,t,r,n){try{return new rr(t,e.transaction(n,r))}catch(e){throw new gr(t,e)}}constructor(r,e){this.action=r,this.transaction=e,this.aborted=!1,this.v=new pt,this.transaction.oncomplete=()=>{this.v.resolve()},this.transaction.onabort=()=>{e.error?this.v.reject(new gr(r,e.error)):this.v.resolve()},this.transaction.onerror=e=>{var t=_r(e.target.error);this.v.reject(new gr(r,t))}}get S(){return this.v.promise}abort(e){e&&this.v.reject(e),this.aborted||(m(tr,"Aborting transaction:",e?e.message:"Client-initiated abort"),this.aborted=!0,this.transaction.abort())}D(){var e=this.transaction;this.aborted||"function"!=typeof e.commit||e.commit()}store(e){var t=this.transaction.objectStore(e);return new vr(t)}}class nr{static delete(e){return m(tr,"Removing database:",e),yr(H().indexedDB.deleteDatabase(e)).toPromise()}static C(){var e,t,r;return!(!(()=>{try{return"object"==typeof indexedDB}catch(e){}})()||!nr.F()&&(e=W(),t=0<(t=nr.O(e))&&t<10,r=0<(r=ir(e))&&r<4.5,0<e.indexOf("MSIE ")||0<e.indexOf("Trident/")||0<e.indexOf("Edge/")||t||r))}static F(){return"undefined"!=typeof process&&"YES"===process.__PRIVATE_env?.__PRIVATE_USE_MOCK_PERSISTENCE}static M(e,t){return e.store(t)}static O(e){var t=e.match(/i(?:phone|pad|pod) os ([\d_]+)/i),t=t?t[1].split("_").slice(0,2).join("."):"-1";return Number(t)}constructor(e,t,r){this.name=e,this.version=t,this.N=r,this.L=null,12.2===nr.O(W())&&lt("Firestore persistence suffers from a bug in iOS 12.2 Safari that may cause your app to stop working. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.")}async B(s){return this.db||(m(tr,"Opening database:",this.name),this.db=await new Promise((r,n)=>{let i=indexedDB.open(this.name,this.version);i.onsuccess=e=>{var t=e.target.result;r(t)},i.onblocked=()=>{n(new gr(s,"Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."))},i.onerror=e=>{var t=e.target.error;"VersionError"===t.name?n(new E(_.FAILED_PRECONDITION,"A newer version of the Firestore SDK was previously used and so the persisted data is not compatible with the version of the SDK you are now using. The SDK will operate with persistence disabled. If you need persistence, please re-upgrade to a newer version of the SDK or else clear the persisted IndexedDB data for your app to start fresh.")):"InvalidStateError"===t.name?n(new E(_.FAILED_PRECONDITION,"Unable to open an IndexedDB connection. This could be due to running in a private browsing session on a browser whose private browsing sessions do not support IndexedDB: "+t)):n(new gr(s,t))},i.onupgradeneeded=e=>{m(tr,'Database "'+this.name+'" requires upgrade from version:',e.oldVersion);var t=e.target.result;this.N.U(t,i.transaction,e.oldVersion,this.version).next(()=>{m(tr,"Database upgrade to version "+this.version+" complete")})}})),this.k&&(this.db.onversionchange=e=>this.k(e)),this.db}q(t){this.k=t,this.db&&(this.db.onversionchange=e=>t(e))}async runTransaction(r,e,n,i){var s="readonly"===e;let a=0;for(;;){++a;try{this.db=await this.B(r);let t=rr.open(this.db,r,s?"readonly":"readwrite",n),e=i(t).next(e=>(t.D(),e)).catch(e=>(t.abort(e),D.reject(e))).toPromise();return e.catch(()=>{}),await t.S,e}catch(r){let e=r,t="FirebaseError"!==e.name&&a<3;if(m(tr,"Transaction failed with error:",e.message,"Retrying:",t),this.close(),!t)return Promise.reject(e)}}}close(){this.db&&this.db.close(),this.db=void 0}}function ir(e){var t=e.match(/Android ([\d.]+)/i),t=t?t[1].split(".").slice(0,2).join("."):"-1";return Number(t)}class sr{constructor(e){this.$=e,this.K=!1,this.W=null}get isDone(){return this.K}get G(){return this.W}set cursor(e){this.$=e}done(){this.K=!0}j(e){this.W=e}delete(){return yr(this.$.delete())}}class gr extends E{constructor(e,t){super(_.UNAVAILABLE,`IndexedDB transaction '${e}' failed: `+t),this.name="IndexedDbTransactionError"}}function mr(e){return"IndexedDbTransactionError"===e.name}class vr{constructor(e){this.store=e}put(e,t){let r;return yr(r=void 0!==t?(m(tr,"PUT",this.store.name,e,t),this.store.put(t,e)):(m(tr,"PUT",this.store.name,"<auto-key>",e),this.store.put(e)))}add(e){return m(tr,"ADD",this.store.name,e,e),yr(this.store.add(e))}get(t){return yr(this.store.get(t)).next(e=>(void 0===e&&(e=null),m(tr,"GET",this.store.name,t,e),e))}delete(e){return m(tr,"DELETE",this.store.name,e),yr(this.store.delete(e))}count(){return m(tr,"COUNT",this.store.name),yr(this.store.count())}H(e,t){var n=this.options(e,t),r=n.index?this.store.index(n.index):this.store;if("function"==typeof r.getAll){let e=r.getAll(n.range);return new D((t,r)=>{e.onerror=e=>{r(e.target.error)},e.onsuccess=e=>{t(e.target.result)}})}{let e=this.cursor(n),r=[];return this.J(e,(e,t)=>{r.push(t)}).next(()=>r)}}Y(e,t){let n=this.store.getAll(e,null===t?void 0:t);return new D((t,r)=>{n.onerror=e=>{r(e.target.error)},n.onsuccess=e=>{t(e.target.result)}})}Z(e,t){m(tr,"DELETE ALL",this.store.name);var r=this.options(e,t),r=(r.X=!1,this.cursor(r));return this.J(r,(e,t,r)=>r.delete())}ee(e,t){let r;t?r=e:(r={},t=e);var n=this.cursor(r);return this.J(n,t)}te(i){let e=this.cursor({});return new D((r,n)=>{e.onerror=e=>{var t=_r(e.target.error);n(t)},e.onsuccess=e=>{let t=e.target.result;t?i(t.primaryKey,t.value).next(e=>{e?t.continue():r()}):r()}})}J(e,s){let a=[];return new D((i,t)=>{e.onerror=e=>{t(e.target.error)},e.onsuccess=e=>{var n=e.target.result;if(n){let t=new sr(n),r=s(n.primaryKey,n.value,t);if(r instanceof D){let e=r.catch(e=>(t.done(),D.reject(e)));a.push(e)}t.isDone?i():null===t.G?n.continue():n.continue(t.G)}else i()}}).next(()=>D.waitFor(a))}options(e,t){let r;return void 0!==e&&("string"==typeof e?r=e:t=e),{index:r,range:t}}cursor(e){let t="next";var r;return e.reverse&&(t="prev"),e.index?(r=this.store.index(e.index),e.X?r.openKeyCursor(e.range,t):r.openCursor(e.range,t)):this.store.openCursor(e.range,t)}}function yr(e){return new D((r,n)=>{e.onsuccess=e=>{var t=e.target.result;r(t)},e.onerror=e=>{var t=_r(e.target.error);n(t)}})}let wr=!1;function _r(e){let t=nr.O(W());if(12.2<=t&&t<13){let t="An internal error was encountered in the Indexed Database server";if(0<=e.message.indexOf(t)){let e=new E("internal",`IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${t}'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.`);return wr||(wr=!0,setTimeout(()=>{throw e},0)),e}}return e}let Er="IndexBackfiller";class Tr{constructor(e,t){this.asyncQueue=e,this.ne=t,this.task=null}start(){this.re(15e3)}stop(){this.task&&(this.task.cancel(),this.task=null)}get started(){return null!==this.task}re(e){m(Er,`Scheduled in ${e}ms`),this.task=this.asyncQueue.enqueueAfterDelay("index_backfill",e,async()=>{this.task=null;try{var e=await this.ne.ie();m(Er,"Documents written: "+e)}catch(e){mr(e)?m(Er,"Ignoring IndexedDB error during index backfill: ",e):await er(e)}await this.re(6e4)})}}class br{constructor(e,t){this.localStore=e,this.persistence=t}async ie(t=50){return this.persistence.runTransaction("Backfill Indexes","readwrite-primary",e=>this.se(e,t))}se(e,t){let r=new Set,n=t,i=!0;return D.doWhile(()=>!0===i&&0<n,()=>this.localStore.indexManager.getNextCollectionGroupToUpdate(e).next(t=>{if(null!==t&&!r.has(t))return m(Er,"Processing collection: "+t),this._e(e,t,n).next(e=>{n-=e,r.add(t)});i=!1})).next(()=>t-n)}_e(n,i,e){return this.localStore.indexManager.getMinOffsetFromCollectionGroup(n,i).next(r=>this.localStore.localDocuments.getNextDocuments(n,i,r,e).next(e=>{let t=e.changes;return this.localStore.indexManager.updateIndexEntries(n,t).next(()=>this.oe(r,e)).next(e=>(m(Er,"Updating offset: "+e),this.localStore.indexManager.updateCollectionGroup(n,i,e))).next(()=>t.size)}))}oe(e,t){let n=e;return t.changes.forEach((e,t)=>{var r=Yt(t);0<Xt(r,n)&&(n=r)}),new Wt(n.readTime,n.documentKey,Math.max(t.batchId,e.largestBatchId))}}class Sr{constructor(e,t){this.previousValue=e,t&&(t.sequenceNumberHandler=e=>this.ae(e),this.ue=e=>t.writeSequenceNumber(e))}ae(e){return this.previousValue=Math.max(e,this.previousValue),this.previousValue}next(){var e=++this.previousValue;return this.ue&&this.ue(e),e}}let Ir=Sr.ce=-1;function Ar(e){return null==e}function Cr(e){return 0===e&&1/e==-1/0}function xr(e){return"number"==typeof e&&Number.isInteger(e)&&!Cr(e)&&e<=Number.MAX_SAFE_INTEGER&&e>=Number.MIN_SAFE_INTEGER}let Nr="";function Dr(e){let t="";for(let r=0;r<e.length;r++)0<t.length&&(t=Or(t)),t=((t,e)=>{let r=e,n=t.length;for(let i=0;i<n;i++){let e=t.charAt(i);switch(e){case"\0":r+="";break;case Nr:r+="";break;default:r+=e}}return r})(e.get(r),t);return Or(t)}function Or(e){return e+Nr+""}function Rr(r){let e=r.length;if(v(2<=e,64408,{path:r}),2===e)return v(r.charAt(0)===Nr&&""===r.charAt(1),56145,{path:r}),T.emptyPath();var __PRIVATE_lastReasonableEscapeIndex=e-2,n=[];let i="";for(let a=0;a<e;){let t=r.indexOf(Nr,a);switch((t<0||t>__PRIVATE_lastReasonableEscapeIndex)&&A(50515,{path:r}),r.charAt(t+1)){case"":var s=r.substring(a,t);let e;0===i.length?e=s:(i+=s,e=i,i=""),n.push(e);break;case"":i=i+r.substring(a,t)+"\0";break;case"":i+=r.substring(a,t+1);break;default:A(61167,{path:r})}a=t+2}return new T(n)}let kr="remoteDocuments",Lr="owner",Pr="owner",Mr="mutationQueues",Vr="mutations",Fr="batchId",Ur="userMutationsIndex",Br=["userId","batchId"];function qr(e,t){return[e,Dr(t)]}function Gr(e,t,r){return[e,Dr(t),r]}let jr={},zr="documentMutations",Hr="remoteDocumentsV14",Kr=["prefixPath","collectionGroup","readTime","documentId"],$r="documentKeyIndex",Qr=["prefixPath","collectionGroup","documentId"],Yr="collectionGroupIndex",Wr=["collectionGroup","readTime","prefixPath","documentId"],Xr="remoteDocumentGlobal",Jr="remoteDocumentGlobalKey",Zr="targets",en="queryTargetsIndex",tn=["canonicalId","targetId"],rn="targetDocuments",nn=["targetId","path"],sn="documentTargetsIndex",an=["path","targetId"],on="targetGlobalKey",un="targetGlobal",ln="collectionParents",hn=["collectionId","parent"],cn="clientMetadata",dn="bundles",pn="namedQueries",fn="indexConfiguration",gn="collectionGroupIndex",mn="indexState",vn=["indexId","uid"],yn="sequenceNumberIndex",wn=["uid","sequenceNumber"],_n="indexEntries",En=["indexId","uid","arrayValue","directionalValue","orderedDocumentKey","documentKey"],Tn="documentKeyIndex",bn=["indexId","uid","orderedDocumentKey"],Sn="documentOverlays",In=["userId","collectionPath","documentId"],An="collectionPathOverlayIndex",Cn=["userId","collectionPath","largestBatchId"],xn="collectionGroupOverlayIndex",Nn=["userId","collectionGroup","largestBatchId"],Dn="globals",On=[Mr,Vr,zr,kr,Zr,Lr,un,rn,cn,Xr,ln,dn,pn],Rn=[...On,Sn],kn=[Mr,Vr,zr,Hr,Zr,Lr,un,rn,cn,Xr,ln,dn,pn,Sn],Ln=kn,Pn=[...Ln,fn,mn,_n],Mn=Pn,Vn=[...Pn,Dn],Fn=Vn;class Un extends Zt{constructor(e,t){super(),this.le=e,this.currentSequenceNumber=t}}function Bn(e,t){var r=e;return nr.M(r.le,t)}class O{constructor(e,t){this.comparator=e,this.root=t||Gn.EMPTY}insert(e,t){return new O(this.comparator,this.root.insert(e,t,this.comparator).copy(null,null,Gn.BLACK,null,null))}remove(e){return new O(this.comparator,this.root.remove(e,this.comparator).copy(null,null,Gn.BLACK,null,null))}get(e){let t=this.root;for(;!t.isEmpty();){var r=this.comparator(e,t.key);if(0===r)return t.value;r<0?t=t.left:0<r&&(t=t.right)}return null}indexOf(e){let t=0,r=this.root;for(;!r.isEmpty();){var n=this.comparator(e,r.key);if(0===n)return t+r.left.size;r=n<0?r.left:(t+=r.left.size+1,r.right)}return-1}isEmpty(){return this.root.isEmpty()}get size(){return this.root.size}minKey(){return this.root.minKey()}maxKey(){return this.root.maxKey()}inorderTraversal(e){return this.root.inorderTraversal(e)}forEach(r){this.inorderTraversal((e,t)=>(r(e,t),!1))}toString(){let r=[];return this.inorderTraversal((e,t)=>(r.push(e+":"+t),!1)),`{${r.join(", ")}}`}reverseTraversal(e){return this.root.reverseTraversal(e)}getIterator(){return new qn(this.root,null,this.comparator,!1)}getIteratorFrom(e){return new qn(this.root,e,this.comparator,!1)}getReverseIterator(){return new qn(this.root,null,this.comparator,!0)}getReverseIteratorFrom(e){return new qn(this.root,e,this.comparator,!0)}}class qn{constructor(e,t,r,n){this.isReverse=n,this.nodeStack=[];let i=1;for(;!e.isEmpty();)if(i=t?r(e.key,t):1,t&&n&&(i*=-1),i<0)e=this.isReverse?e.left:e.right;else{if(0===i){this.nodeStack.push(e);break}this.nodeStack.push(e),e=this.isReverse?e.right:e.left}}getNext(){let e=this.nodeStack.pop();var t={key:e.key,value:e.value};if(this.isReverse)for(e=e.left;!e.isEmpty();)this.nodeStack.push(e),e=e.right;else for(e=e.right;!e.isEmpty();)this.nodeStack.push(e),e=e.left;return t}hasNext(){return 0<this.nodeStack.length}peek(){var e;return 0===this.nodeStack.length?null:{key:(e=this.nodeStack[this.nodeStack.length-1]).key,value:e.value}}}class Gn{constructor(e,t,r,n,i){this.key=e,this.value=t,this.color=null!=r?r:Gn.RED,this.left=null!=n?n:Gn.EMPTY,this.right=null!=i?i:Gn.EMPTY,this.size=this.left.size+1+this.right.size}copy(e,t,r,n,i){return new Gn(null!=e?e:this.key,null!=t?t:this.value,null!=r?r:this.color,null!=n?n:this.left,null!=i?i:this.right)}isEmpty(){return!1}inorderTraversal(e){return this.left.inorderTraversal(e)||e(this.key,this.value)||this.right.inorderTraversal(e)}reverseTraversal(e){return this.right.reverseTraversal(e)||e(this.key,this.value)||this.left.reverseTraversal(e)}min(){return this.left.isEmpty()?this:this.left.min()}minKey(){return this.min().key}maxKey(){return this.right.isEmpty()?this.key:this.right.maxKey()}insert(e,t,r){var n=this,i=r(e,n.key);return(n=i<0?n.copy(null,null,null,n.left.insert(e,t,r),null):0===i?n.copy(null,t,null,null,null):n.copy(null,null,null,null,n.right.insert(e,t,r))).fixUp()}removeMin(){if(this.left.isEmpty())return Gn.EMPTY;let e=this;return(e=(e=e.left.isRed()||e.left.left.isRed()?e:e.moveRedLeft()).copy(null,null,null,e.left.removeMin(),null)).fixUp()}remove(e,t){let r,n=this;if(t(e,n.key)<0)n=(n=n.left.isEmpty()||n.left.isRed()||n.left.left.isRed()?n:n.moveRedLeft()).copy(null,null,null,n.left.remove(e,t),null);else{if(0===t(e,(n=(n=n.left.isRed()?n.rotateRight():n).right.isEmpty()||n.right.isRed()||n.right.left.isRed()?n:n.moveRedRight()).key)){if(n.right.isEmpty())return Gn.EMPTY;r=n.right.min(),n=n.copy(r.key,r.value,null,null,n.right.removeMin())}n=n.copy(null,null,null,null,n.right.remove(e,t))}return n.fixUp()}isRed(){return this.color}fixUp(){let e=this;return e=(e=(e=e.right.isRed()&&!e.left.isRed()?e.rotateLeft():e).left.isRed()&&e.left.left.isRed()?e.rotateRight():e).left.isRed()&&e.right.isRed()?e.colorFlip():e}moveRedLeft(){let e=this.colorFlip();return e=e.right.left.isRed()?(e=(e=e.copy(null,null,null,null,e.right.rotateRight())).rotateLeft()).colorFlip():e}moveRedRight(){let e=this.colorFlip();return e=e.left.left.isRed()?(e=e.rotateRight()).colorFlip():e}rotateLeft(){var e=this.copy(null,null,Gn.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight(){var e=this.copy(null,null,Gn.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)}colorFlip(){var e=this.left.copy(null,null,!this.left.color,null,null),t=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,e,t)}checkMaxDepth(){var e=this.check();return Math.pow(2,e)<=this.size+1}check(){if(this.isRed()&&this.left.isRed())throw A(43730,{key:this.key,value:this.value});if(this.right.isRed())throw A(14113,{key:this.key,value:this.value});var e=this.left.check();if(e!==this.right.check())throw A(27949);return e+(this.isRed()?0:1)}}Gn.EMPTY=null,Gn.RED=!0,Gn.BLACK=!1,Gn.EMPTY=new class{constructor(){this.size=0}get key(){throw A(57766)}get value(){throw A(16141)}get color(){throw A(16727)}get left(){throw A(29726)}get right(){throw A(36894)}copy(e,t,r,n,i){return this}insert(e,t,r){return new Gn(e,t)}remove(e,t){return this}isEmpty(){return!0}inorderTraversal(e){return!1}reverseTraversal(e){return!1}minKey(){return null}maxKey(){return null}isRed(){return!1}checkMaxDepth(){return!0}check(){return 0}};class R{constructor(e){this.comparator=e,this.data=new O(this.comparator)}has(e){return null!==this.data.get(e)}first(){return this.data.minKey()}last(){return this.data.maxKey()}get size(){return this.data.size}indexOf(e){return this.data.indexOf(e)}forEach(r){this.data.inorderTraversal((e,t)=>(r(e),!1))}forEachInRange(e,t){for(var r=this.data.getIteratorFrom(e[0]);r.hasNext();){var n=r.getNext();if(0<=this.comparator(n.key,e[1]))return;t(n.key)}}forEachWhile(e,t){for(var r=void 0!==t?this.data.getIteratorFrom(t):this.data.getIterator();r.hasNext();)if(!e(r.getNext().key))return}firstAfterOrEqual(e){var t=this.data.getIteratorFrom(e);return t.hasNext()?t.getNext().key:null}getIterator(){return new jn(this.data.getIterator())}getIteratorFrom(e){return new jn(this.data.getIteratorFrom(e))}add(e){return this.copy(this.data.remove(e).insert(e,!0))}delete(e){return this.has(e)?this.copy(this.data.remove(e)):this}isEmpty(){return this.data.isEmpty()}unionWith(e){let t=this;return t.size<e.size&&(t=e,e=this),e.forEach(e=>{t=t.add(e)}),t}isEqual(e){if(!(e instanceof R))return!1;if(this.size!==e.size)return!1;for(var r=this.data.getIterator(),n=e.data.getIterator();r.hasNext();){let e=r.getNext().key,t=n.getNext().key;if(0!==this.comparator(e,t))return!1}return!0}toArray(){let t=[];return this.forEach(e=>{t.push(e)}),t}toString(){let t=[];return this.forEach(e=>t.push(e)),"SortedSet("+t.toString()+")"}copy(e){var t=new R(this.comparator);return t.data=e,t}}class jn{constructor(e){this.iter=e}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}function zn(e){return e.hasNext()?e.getNext():void 0}class Hn{constructor(e){(this.fields=e).sort(h.comparator)}static empty(){return new Hn([])}unionWith(e){let t=new R(h.comparator);for(let e of this.fields)t=t.add(e);for(var r of e)t=t.add(r);return new Hn(t.toArray())}covers(e){for(var t of this.fields)if(t.isPrefixOf(e))return!0;return!1}isEqual(e){return Ct(this.fields,e.fields,(e,t)=>e.isEqual(t))}}function Kn(e){let t=0;for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t++;return t}function $n(e,t){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t(r,e[r])}function Qn(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}class Yn extends Error{constructor(){super(...arguments),this.name="Base64DecodeError"}}class k{constructor(e){this.binaryString=e}static fromBase64String(e){var t=(e=>{try{return atob(e)}catch(e){throw"undefined"!=typeof DOMException&&e instanceof DOMException?new Yn("Invalid base64 string: "+e):e}})(e);return new k(t)}static fromUint8Array(e){var t=(e=>{let t="";for(let r=0;r<e.length;++r)t+=String.fromCharCode(e[r]);return t})(e);return new k(t)}[Symbol.iterator](){let e=0;return{next:()=>e<this.binaryString.length?{value:this.binaryString.charCodeAt(e++),done:!1}:{value:void 0,done:!0}}}toBase64(){return e=this.binaryString,btoa(e);var e}toUint8Array(){var e=this.binaryString,t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}approximateByteSize(){return 2*this.binaryString.length}compareTo(e){return C(this.binaryString,e.binaryString)}isEqual(e){return this.binaryString===e.binaryString}}k.EMPTY_BYTE_STRING=new k("");let Wn=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Xn(t){if(v(!!t,39018),"string"!=typeof t)return{seconds:L(t.seconds),nanos:L(t.nanos)};{let e=0;var r=Wn.exec(t),r=(v(!!r,46558,{timestamp:t}),r[1]&&(r=((r=r[1])+"000000000").substr(0,9),e=Number(r)),new Date(t));return{seconds:Math.floor(r.getTime()/1e3),nanos:e}}}function L(e){return"number"==typeof e?e:"string"==typeof e?Number(e):0}function Jn(e){return"string"==typeof e?k.fromBase64String(e):k.fromUint8Array(e)}let Zn="server_timestamp",ei="__type__",ti="__previous_value__",ri="__local_write_time__";function ni(e){return(e?.mapValue?.fields||{})[ei]?.stringValue===Zn}function ii(e){var t=e.mapValue.fields[ti];return ni(t)?ii(t):t}function si(e){var t=Xn(e.mapValue.fields[ri].timestampValue);return new w(t.seconds,t.nanos)}class ai{constructor(e,t,r,n,i,s,a,o,u,l,h){this.databaseId=e,this.appId=t,this.persistenceKey=r,this.host=n,this.ssl=i,this.forceLongPolling=s,this.autoDetectLongPolling=a,this.longPollingOptions=o,this.useFetchStreams=u,this.isUsingEmulator=l,this.apiKey=h}}let oi="(default)";class ui{constructor(e,t){this.projectId=e,this.database=t||oi}static empty(){return new ui("","")}get isDefaultDatabase(){return this.database===oi}isEqual(e){return e instanceof ui&&e.projectId===this.projectId&&e.database===this.database}}let li="__type__",hi="__max__",ci={mapValue:{fields:{__type__:{stringValue:hi}}}},di="__vector__",pi="value",fi={nullValue:"NULL_VALUE"},gi={booleanValue:!0},mi={booleanValue:!1};function vi(e){return"nullValue"in e?0:"booleanValue"in e?1:"integerValue"in e||"doubleValue"in e?2:"timestampValue"in e?3:"stringValue"in e?5:"bytesValue"in e?6:"referenceValue"in e?7:"geoPointValue"in e?8:"arrayValue"in e?9:"mapValue"in e?ni(e)?4:Pi(e)?9007199254740991:Ri(e)?10:11:A(28295,{value:e})}function yi(r,n,i){if(r===n)return!0;var t,s,a,o,e=vi(r);if(e!==vi(n))return!1;switch(e){case 0:case 9007199254740991:return!0;case 1:return r.booleanValue===n.booleanValue;case 4:return si(r).isEqual(si(n));case 3:return s=n,"string"==typeof(t=r).timestampValue&&"string"==typeof s.timestampValue&&t.timestampValue.length===s.timestampValue.length?t.timestampValue===s.timestampValue:(a=Xn(t.timestampValue),o=Xn(s.timestampValue),a.seconds===o.seconds&&a.nanos===o.nanos);case 5:return r.stringValue===n.stringValue;case 6:return t=n,Jn(r.bytesValue).isEqual(Jn(t.bytesValue));case 7:return r.referenceValue===n.referenceValue;case 8:return s=n,L((u=r).geoPointValue.latitude)===L(s.geoPointValue.latitude)&&L(u.geoPointValue.longitude)===L(s.geoPointValue.longitude);case 2:{var u=r;var l=n;var h=i;if("integerValue"in u&&"integerValue"in l)return L(u.integerValue)===L(l.integerValue);let e,t;if("doubleValue"in u&&"doubleValue"in l)e=L(u.doubleValue),t=L(l.doubleValue);else{if(!h?.Ee)return!1;e=L(u.integerValue??u.doubleValue),t=L(l.integerValue??l.doubleValue)}return e===t?!!h?.he||Cr(e)===Cr(t):!(void 0!==h&&!h.Te)&&isNaN(e)&&isNaN(t);return}case 9:return Ct(r.arrayValue.values||[],n.arrayValue.values||[],(e,t)=>yi(e,t,i));case 10:case 11:var c=r,l=n,d=i,p=c.mapValue.fields||{},f=l.mapValue.fields||{};if(Kn(p)!==Kn(f))return!1;for(let e in p)if(p.hasOwnProperty(e)&&(void 0===f[e]||!yi(p[e],f[e],d)))return!1;return!0;default:return A(52216,{left:r})}}function wi(e,t){return void 0!==(e.values||[]).find(e=>yi(e,t))}function _i(e,n){if(e===n)return 0;var i,s,a,o,u,l,h,c,d=vi(e),t=vi(n);if(d!==t)return C(d,t);switch(d){case 0:case 9007199254740991:return 0;case 1:return C(e.booleanValue,n.booleanValue);case 2:return l=n,h=L((u=e).integerValue||u.doubleValue),c=L(l.integerValue||l.doubleValue),h<c?-1:c<h?1:h===c?0:isNaN(h)?isNaN(c)?0:-1:1;case 3:return Ei(e.timestampValue,n.timestampValue);case 4:return Ei(si(e),si(n));case 5:return bt(e.stringValue,n.stringValue);case 6:return u=e.bytesValue,l=n.bytesValue,h=Jn(u),c=Jn(l),h.compareTo(c);case 7:var p=e.referenceValue,f=n.referenceValue,g=p.split("/"),m=f.split("/");for(let t=0;t<g.length&&t<m.length;t++){let e=C(g[t],m[t]);if(0!==e)return e}return C(g.length,m.length);case 8:return p=e.geoPointValue,f=n.geoPointValue,0!==(o=C(L(p.latitude),L(f.latitude)))?o:C(L(p.longitude),L(f.longitude));case 9:return Ti(e.arrayValue,n.arrayValue);case 10:return v=e.mapValue,i=n.mapValue,o=v.fields||{},s=i.fields||{},o=o[pi]?.arrayValue,s=s[pi]?.arrayValue,0!==(a=C(o?.values?.length||0,s?.values?.length||0))?a:Ti(o,s);case 11:var v=e.mapValue,y=n.mapValue;if(v===ci.mapValue&&y===ci.mapValue)return 0;if(v===ci.mapValue)return 1;if(y===ci.mapValue)return-1;var w=v.fields||{},_=Object.keys(w),E=y.fields||{},T=Object.keys(E);_.sort(),T.sort();for(let r=0;r<_.length&&r<T.length;++r){let e=bt(_[r],T[r]);if(0!==e)return e;var b=_i(w[_[r]],E[T[r]]);if(0!==b)return b}return C(_.length,T.length);default:throw A(23264,{Pe:d})}}function Ei(e,t){var r,n,i;return"string"==typeof e&&"string"==typeof t&&e.length===t.length?C(e,t):(r=Xn(e),n=Xn(t),0!==(i=C(r.seconds,n.seconds))?i:C(r.nanos,n.nanos))}function Ti(e,t){var r=e.values||[],n=t.values||[];for(let i=0;i<r.length&&i<n.length;++i){let e=_i(r[i],n[i]);if(void 0!==e&&0!==e)return e}return C(r.length,n.length)}function bi(e){return function s(e){return"nullValue"in e?"null":"booleanValue"in e?""+e.booleanValue:"integerValue"in e?""+e.integerValue:"doubleValue"in e?""+e.doubleValue:"timestampValue"in e?(e=>{let t=Xn(e);return`time(${t.seconds},${t.nanos})`})(e.timestampValue):"stringValue"in e?e.stringValue:"bytesValue"in e?(e=>Jn(e).toBase64())(e.bytesValue):"referenceValue"in e?(e=>x.fromName(e).toString())(e.referenceValue):"geoPointValue"in e?(e=>`geo(${e.latitude},${e.longitude})`)(e.geoPointValue):"arrayValue"in e?(e=>{let t="[",r=!0;for(var n of e.values||[])r?r=!1:t+=",",t+=s(n);return t+"]"})(e.arrayValue):"mapValue"in e?(e=>{let t=Object.keys(e.fields||{}).sort(),r="{",n=!0;for(var i of t)n?n=!1:r+=",",r+=i+":"+s(e.fields[i]);return r+"}"})(e.mapValue):A(61005,{value:e})}(e)}function Si(e,t){return{referenceValue:`projects/${e.projectId}/databases/${e.database}/documents/`+t.path.canonicalString()}}function Ii(e){return!!e&&"integerValue"in e}function Ai(e){return!!e&&"doubleValue"in e}function Ci(e){return Ii(e)||Ai(e)}function xi(e){return!!e&&"arrayValue"in e}function Ni(e){return e&&"nullValue"in e}function Di(e){return e&&"doubleValue"in e&&isNaN(Number(e.doubleValue))}function Oi(e){return e&&"mapValue"in e}function Ri(e){return(e?.mapValue?.fields||{})[li]?.stringValue===di}function ki(e){return(e?.mapValue?.fields||{})[pi]?.arrayValue}function Li(t){if(t.geoPointValue)return{geoPointValue:{...t.geoPointValue}};if(t.timestampValue&&"object"==typeof t.timestampValue)return{timestampValue:{...t.timestampValue}};if(t.mapValue){let r={mapValue:{fields:{}}};return $n(t.mapValue.fields,(e,t)=>r.mapValue.fields[e]=Li(t)),r}if(t.arrayValue){var r={arrayValue:{values:[]}};for(let e=0;e<(t.arrayValue.values||[]).length;++e)r.arrayValue.values[e]=Li(t.arrayValue.values[e]);return r}return{...t}}function Pi(e){return(((e.mapValue||{}).fields||{}).__type__||{}).stringValue===hi}let Mi={mapValue:{fields:{[li]:{stringValue:di},[pi]:{arrayValue:{}}}}};function Vi(e,t){var r=_i(e.value,t.value);return 0!==r?r:e.inclusive&&!t.inclusive?-1:!e.inclusive&&t.inclusive?1:0}function Fi(e,t){var r=_i(e.value,t.value);return 0!==r?r:e.inclusive&&!t.inclusive?1:!e.inclusive&&t.inclusive?-1:0}class Ui{constructor(e){this.value=e}static empty(){return new Ui({mapValue:{}})}field(r){if(r.isEmpty())return this.value;{let e=this.value;for(let t=0;t<r.length-1;++t)if(!Oi(e=(e.mapValue.fields||{})[r.get(t)]))return null;return(e=(e.mapValue.fields||{})[r.lastSegment()])||null}}set(e,t){this.getFieldsMap(e.popLast())[e.lastSegment()]=Li(t)}setAll(e){let r=h.emptyPath(),n={},i=[];e.forEach((e,t)=>{if(!r.isImmediateParentOf(t)){let e=this.getFieldsMap(r);this.applyChanges(e,n,i),n={},i=[],r=t.popLast()}e?n[t.lastSegment()]=Li(e):i.push(t.lastSegment())});var t=this.getFieldsMap(r);this.applyChanges(t,n,i)}delete(e){var t=this.field(e.popLast());Oi(t)&&t.mapValue.fields&&delete t.mapValue.fields[e.lastSegment()]}isEqual(e){return yi(this.value,e.value)}getFieldsMap(t){let r=this.value;r.mapValue.fields||(r.mapValue={fields:{}});for(let n=0;n<t.length;++n){let e=r.mapValue.fields[t.get(n)];Oi(e)&&e.mapValue.fields||(e={mapValue:{fields:{}}},r.mapValue.fields[t.get(n)]=e),r=e}return r.mapValue.fields}applyChanges(r,e,t){$n(e,(e,t)=>r[e]=t);for(let e of t)delete r[e]}clone(){return new Ui(Li(this.value))}}function Bi(e,t){if(e.useProto3Json){if(isNaN(t))return{doubleValue:"NaN"};if(t===1/0)return{doubleValue:"Infinity"};if(t===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:Cr(t)?"-0":t}}function qi(e){return{integerValue:""+e}}function Gi(e,t,r){return Number.isInteger(t)&&r?.preferIntegers||xr(t)?qi(t):Bi(e,t)}class ji{constructor(){this._=void 0}}function zi(e,t){return e instanceof Xi?Ci(t)?t:{integerValue:0}:null}class Hi extends ji{}class Ki extends ji{constructor(e){super(),this.elements=e}}function $i(e,t){var r=rs(t);for(let t of e.elements)r.some(e=>yi(e,t))||r.push(t);return{arrayValue:{values:r}}}class Qi extends ji{constructor(e){super(),this.elements=e}}function Yi(e,t){let r=rs(t);for(let t of e.elements)r=r.filter(e=>!yi(e,t));return{arrayValue:{values:r}}}class Wi extends ji{constructor(e,t){super(),this.serializer=e,this.Re=t}}class Xi extends Wi{}class Ji extends Wi{}class Zi extends Wi{}function es(e,t,r){var n;return Ci(t)?(n=r(ts(t),ts(e.Re)),Ii(t)&&Ii(e.Re)?qi(n):Bi(e.serializer,n)):e.Re}function ts(e){return L(e.integerValue||e.doubleValue)}function rs(e){return xi(e)&&e.arrayValue.values?e.arrayValue.values.slice():[]}class ns{constructor(e,t){this.field=e,this.transform=t}}class is{constructor(e,t){this.version=e,this.transformResults=t}}class ss{constructor(e,t){this.updateTime=e,this.exists=t}static none(){return new ss}static exists(e){return new ss(void 0,e)}static updateTime(e){return new ss(e)}get isNone(){return void 0===this.updateTime&&void 0===this.exists}isEqual(e){return this.exists===e.exists&&(this.updateTime?!!e.updateTime&&this.updateTime.isEqual(e.updateTime):!e.updateTime)}}function as(e,t){return void 0!==e.updateTime?t.isFoundDocument()&&t.version.isEqual(e.updateTime):void 0===e.exists||e.exists===t.isFoundDocument()}class os{}function us(e,r){if(!e.hasLocalMutations||r&&0===r.fields.length)return null;if(null===r)return e.isNoDocument()?new ms(e.key,ss.none()):new cs(e.key,e.data,ss.none());{var n,i=e.data,s=Ui.empty();let t=new R(h.comparator);for(n of r.fields)if(!t.has(n)){let e=i.field(n);null===e&&1<n.length&&(n=n.popLast(),e=i.field(n)),null===e?s.delete(n):s.set(n,e),t=t.add(n)}return new ds(e.key,s,new Hn(t.toArray()),ss.none())}}function ls(e,t,r,n){return e instanceof cs?(s=t,a=r,o=n,as((i=e).precondition,s)?(u=i.value.clone(),l=gs(i.fieldTransforms,o,s),u.setAll(l),s.convertToFoundDocument(s.version,u).setHasLocalMutations(),null):a):e instanceof ds?(i=t,o=r,s=n,as((a=e).precondition,i)?(l=gs(a.fieldTransforms,s,i),(u=i.data).setAll(ps(a)),u.setAll(l),i.convertToFoundDocument(i.version,u).setHasLocalMutations(),null===o?null:o.unionWith(a.fieldMask.fields).unionWith(a.fieldTransforms.map(e=>e.field))):o):(n=t,t=r,as(e.precondition,n)?(n.convertToNoDocument(n.version).setHasLocalMutations(),null):t);var i,s,a,o,u,l}function hs(e,t){return e.type===t.type&&!!e.key.isEqual(t.key)&&!!e.precondition.isEqual(t.precondition)&&(r=e.fieldTransforms,n=t.fieldTransforms,!!(void 0===r&&void 0===n||r&&n&&Ct(r,n,(e,t)=>(t=t,(e=e).field.isEqual(t.field)&&(e=e.transform,t=t.transform,e instanceof Ki&&t instanceof Ki||e instanceof Qi&&t instanceof Qi?Ct(e.elements,t.elements,yi):e instanceof Xi&&t instanceof Xi||e instanceof Ji&&t instanceof Ji||e instanceof Zi&&t instanceof Zi?yi(e.Re,t.Re):e instanceof Hi&&t instanceof Hi)))))&&(0===e.type?e.value.isEqual(t.value):1!==e.type||e.data.isEqual(t.data)&&e.fieldMask.isEqual(t.fieldMask));var r,n}class cs extends os{constructor(e,t,r,n=[]){super(),this.key=e,this.value=t,this.precondition=r,this.fieldTransforms=n,this.type=0}getFieldMask(){return null}}class ds extends os{constructor(e,t,r,n,i=[]){super(),this.key=e,this.data=t,this.fieldMask=r,this.precondition=n,this.fieldTransforms=i,this.type=1}getFieldMask(){return this.fieldMask}}function ps(r){let n=new Map;return r.fieldMask.fields.forEach(e=>{var t;e.isEmpty()||(t=r.data.field(e),n.set(e,t))}),n}function fs(e,t,r){var n,i,s,a=new Map;v(e.length===r.length,32656,{Ie:r.length,Ae:e.length});for(let h=0;h<r.length;h++){var o=e[h],u=o.transform,l=t.data.field(o.field);a.set(o.field,(n=u,i=l,s=r[h],n instanceof Ki?$i(n,i):n instanceof Qi?Yi(n,i):s))}return a}function gs(e,r,n){var i,s,a,o,u,l,h,c=new Map;for(i of e){let e=i.transform,t=n.data.field(i.field);c.set(i.field,(s=e,a=t,o=r,h=l=u=void 0,s instanceof Hi?(o=o,l=a,h={fields:{[ei]:{stringValue:Zn},[ri]:{timestampValue:{seconds:o.seconds,nanos:o.nanoseconds}}}},(l=l&&ni(l)?ii(l):l)&&(h.fields[ti]=l),{mapValue:h}):s instanceof Ki?$i(s,a):s instanceof Qi?Yi(s,a):s instanceof Xi?(h=zi(o=s,a),u=ts(h)+ts(o.Re),Ii(h)&&Ii(o.Re)?qi(u):Bi(o.serializer,u)):s instanceof Ji?es(s,a,Math.min):s instanceof Zi?es(s,a,Math.max):void 0))}return c}class ms extends os{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class vs extends os{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}class ys{constructor(e,t){this.position=e,this.inclusive=t}}function ws(e,t,r){let n=0;for(let a=0;a<e.position.length;a++){var i=t[a],s=e.position[a];if(n=i.field.isKeyField()?x.comparator(x.fromName(s.referenceValue),r.key):_i(s,r.data.field(i.field)),"desc"===i.dir&&(n*=-1),0!==n)break}return n}function _s(e,t){if(null===e)return null===t;if(null===t)return!1;if(e.inclusive!==t.inclusive||e.position.length!==t.position.length)return!1;for(let r=0;r<e.position.length;r++)if(!yi(e.position[r],t.position[r]))return!1;return!0}class Es{}class P extends Es{constructor(e,t,r){super(),this.field=e,this.op=t,this.value=r}static create(e,t,r){return e.isKeyField()?"in"===t||"not-in"===t?this.createKeyFieldInFilter(e,t,r):new xs(e,t,r):"array-contains"===t?new Rs(e,r):"in"===t?new ks(e,r):"not-in"===t?new Ls(e,r):"array-contains-any"===t?new Ps(e,r):new P(e,t,r)}static createKeyFieldInFilter(e,t,r){return new("in"===t?Ns:Ds)(e,r)}matches(e){var t=e.data.field(this.field);return"!="===this.op?null!==t&&void 0===t.nullValue&&this.matchesComparison(_i(t,this.value)):null!==t&&vi(this.value)===vi(t)&&this.matchesComparison(_i(t,this.value))}matchesComparison(e){switch(this.op){case"<":return e<0;case"<=":return e<=0;case"==":return 0===e;case"!=":return 0!==e;case">":return 0<e;case">=":return 0<=e;default:return A(47266,{operator:this.op})}}isInequality(){return 0<=["<","<=",">",">=","!=","not-in"].indexOf(this.op)}getFlattenedFilters(){return[this]}getFilters(){return[this]}}class M extends Es{constructor(e,t){super(),this.filters=e,this.op=t,this.Ve=null}static create(e,t){return new M(e,t)}matches(t){return Ts(this)?void 0===this.filters.find(e=>!e.matches(t)):void 0!==this.filters.find(e=>e.matches(t))}getFlattenedFilters(){return null===this.Ve&&(this.Ve=this.filters.reduce((e,t)=>e.concat(t.getFlattenedFilters()),[])),this.Ve}getFilters(){return Object.assign([],this.filters)}}function Ts(e){return"and"===e.op}function bs(e){return"or"===e.op}function Ss(e){return Is(e)&&Ts(e)}function Is(e){for(var t of e.filters)if(t instanceof M)return!1;return!0}function As(e,t){var r=e.filters.concat(t);return M.create(r,e.op)}function Cs(e){return e instanceof P?`${(t=e).field.canonicalString()} ${t.op} `+bi(t.value):e instanceof M?(t=e).op.toString()+" {"+t.getFilters().map(Cs).join(" ,")+"}":"Filter";var t}class xs extends P{constructor(e,t,r){super(e,t,r),this.key=x.fromName(r.referenceValue)}matches(e){var t=x.comparator(e.key,this.key);return this.matchesComparison(t)}}class Ns extends P{constructor(e,t){super(e,"in",t),this.keys=Os(0,t)}matches(t){return this.keys.some(e=>e.isEqual(t.key))}}class Ds extends P{constructor(e,t){super(e,"not-in",t),this.keys=Os(0,t)}matches(t){return!this.keys.some(e=>e.isEqual(t.key))}}function Os(e,t){return(t.arrayValue?.values||[]).map(e=>x.fromName(e.referenceValue))}class Rs extends P{constructor(e,t){super(e,"array-contains",t)}matches(e){var t=e.data.field(this.field);return xi(t)&&wi(t.arrayValue,this.value)}}class ks extends P{constructor(e,t){super(e,"in",t)}matches(e){var t=e.data.field(this.field);return null!==t&&wi(this.value.arrayValue,t)}}class Ls extends P{constructor(e,t){super(e,"not-in",t)}matches(e){var t;return!wi(this.value.arrayValue,{nullValue:"NULL_VALUE"})&&null!==(t=e.data.field(this.field))&&void 0===t.nullValue&&!wi(this.value.arrayValue,t)}}class Ps extends P{constructor(e,t){super(e,"array-contains-any",t)}matches(e){var t=e.data.field(this.field);return!(!xi(t)||!t.arrayValue.values)&&t.arrayValue.values.some(e=>wi(this.value.arrayValue,e))}}class Ms{constructor(e,t="asc"){this.field=e,this.dir=t}}class Vs{constructor(e,t,r,n,i,s,a){this.key=e,this.documentType=t,this.version=r,this.readTime=n,this.createTime=i,this.data=s,this.documentState=a}static newInvalidDocument(e){return new Vs(e,0,N.min(),N.min(),N.min(),Ui.empty(),0)}static newFoundDocument(e,t,r,n){return new Vs(e,1,t,N.min(),r,n,0)}static newNoDocument(e,t){return new Vs(e,2,t,N.min(),N.min(),Ui.empty(),0)}static newUnknownDocument(e,t){return new Vs(e,3,t,N.min(),N.min(),Ui.empty(),2)}convertToFoundDocument(e,t){return!this.createTime.isEqual(N.min())||2!==this.documentType&&0!==this.documentType||(this.createTime=e),this.version=e,this.documentType=1,this.data=t,this.documentState=0,this}convertToNoDocument(e){return this.version=e,this.documentType=2,this.data=Ui.empty(),this.documentState=0,this}convertToUnknownDocument(e){return this.version=e,this.documentType=3,this.data=Ui.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=N.min(),this}setReadTime(e){return this.readTime=e,this}get hasLocalMutations(){return 1===this.documentState}get hasCommittedMutations(){return 2===this.documentState}get hasPendingWrites(){return this.hasLocalMutations||this.hasCommittedMutations}isValidDocument(){return 0!==this.documentType}isFoundDocument(){return 1===this.documentType}isNoDocument(){return 2===this.documentType}isUnknownDocument(){return 3===this.documentType}isEqual(e){return e instanceof Vs&&this.key.isEqual(e.key)&&this.version.isEqual(e.version)&&this.documentType===e.documentType&&this.documentState===e.documentState&&this.data.isEqual(e.data)}mutableCopy(){return new Vs(this.key,this.documentType,this.version,this.readTime,this.createTime,this.data.clone(),this.documentState)}toString(){return`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, {createTime: ${this.createTime}}), {documentType: ${this.documentType}}), {documentState: ${this.documentState}})`}}class Fs{constructor(e,t=null,r=[],n=[],i=null,s=null,a=null){this.path=e,this.collectionGroup=t,this.orderBy=r,this.filters=n,this.limit=i,this.startAt=s,this.endAt=a,this.de=null}}function Us(e,t=null,r=[],n=[],i=null,s=null,a=null){return new Fs(e,t,r,n,i,s,a)}function Bs(e){var t=e;if(null===t.de){let e=t.path.canonicalString();null!==t.collectionGroup&&(e+="|cg:"+t.collectionGroup),e=(e=(e+="|f:")+t.filters.map(e=>function t(e){var r;return e instanceof P?e.field.canonicalString()+e.op.toString()+bi(e.value):Ss(e)?e.filters.map(e=>t(e)).join(","):(r=e.filters.map(e=>t(e)).join(","),e.op+`(${r})`)}(e)).join(",")+"|ob:")+t.orderBy.map(e=>(e=e).field.canonicalString()+e.dir).join(","),Ar(t.limit)||(e=(e+="|l:")+t.limit),t.startAt&&(e=(e=(e+="|lb:")+(t.startAt.inclusive?"b:":"a:"))+t.startAt.position.map(e=>bi(e)).join(",")),t.endAt&&(e=(e=(e+="|ub:")+(t.endAt.inclusive?"a:":"b:"))+t.endAt.position.map(e=>bi(e)).join(",")),t.de=e}return t.de}function qs(e,t){if(e.limit!==t.limit)return!1;if(e.orderBy.length!==t.orderBy.length)return!1;for(let i=0;i<e.orderBy.length;i++)if(r=e.orderBy[i],n=t.orderBy[i],r.dir!==n.dir||!r.field.isEqual(n.field))return!1;var r,n;if(e.filters.length!==t.filters.length)return!1;for(let s=0;s<e.filters.length;s++)if(!function n(e,t){return e instanceof P?(r=e,(s=t)instanceof P&&r.op===s.op&&r.field.isEqual(s.field)&&yi(r.value,s.value)):e instanceof M?(r=e,(i=t)instanceof M&&r.op===i.op&&r.filters.length===i.filters.length&&r.filters.reduce((e,t,r)=>e&&n(t,i.filters[r]),!0)):void A(19439);var i,r,s}(e.filters[s],t.filters[s]))return!1;return e.collectionGroup===t.collectionGroup&&!!e.path.isEqual(t.path)&&!!_s(e.startAt,t.startAt)&&_s(e.endAt,t.endAt)}function Gs(e){return e.isCorePipeline}function js(e){return!!e.path&&x.isDocumentKey(e.path)&&null===e.collectionGroup&&0===e.filters.length}function zs(e,t){return e.filters.filter(e=>e instanceof P&&e.field.isEqual(t))}function Hs(e,r,n){let i=fi,s=!0;for(let n of zs(e,r)){let e=fi,t=!0;switch(n.op){case"<":case"<=":e="nullValue"in(a=n.value)?fi:"booleanValue"in a?{booleanValue:!1}:"integerValue"in a||"doubleValue"in a?{doubleValue:NaN}:"timestampValue"in a?{timestampValue:{seconds:Number.MIN_SAFE_INTEGER}}:"stringValue"in a?{stringValue:""}:"bytesValue"in a?{bytesValue:""}:"referenceValue"in a?Si(ui.empty(),x.empty()):"geoPointValue"in a?{geoPointValue:{latitude:-90,longitude:-180}}:"arrayValue"in a?{arrayValue:{}}:"mapValue"in a?Ri(a)?Mi:{mapValue:{}}:A(35942,{value:a});break;case"==":case"in":case">=":e=n.value;break;case">":e=n.value,t=!1;break;case"!=":case"not-in":e=fi}Vi({value:i,inclusive:s},{value:e,inclusive:t})<0&&(i=e,s=t)}var a;if(null!==n)for(let t=0;t<e.orderBy.length;++t)if(e.orderBy[t].field.isEqual(r)){let e=n.position[t];Vi({value:i,inclusive:s},{value:e,inclusive:n.inclusive})<0&&(i=e,s=n.inclusive);break}return{value:i,inclusive:s}}function Ks(e,r,n){let i=ci,s=!0;for(let n of zs(e,r)){let e=ci,t=!0;switch(n.op){case">=":case">":e="nullValue"in(a=n.value)?{booleanValue:!1}:"booleanValue"in a?{doubleValue:NaN}:"integerValue"in a||"doubleValue"in a?{timestampValue:{seconds:Number.MIN_SAFE_INTEGER}}:"timestampValue"in a?{stringValue:""}:"stringValue"in a?{bytesValue:""}:"bytesValue"in a?Si(ui.empty(),x.empty()):"referenceValue"in a?{geoPointValue:{latitude:-90,longitude:-180}}:"geoPointValue"in a?{arrayValue:{}}:"arrayValue"in a?Mi:"mapValue"in a?Ri(a)?{mapValue:{}}:ci:A(61959,{value:a}),t=!1;break;case"==":case"in":case"<=":e=n.value;break;case"<":e=n.value,t=!1;break;case"!=":case"not-in":e=ci}0<Fi({value:i,inclusive:s},{value:e,inclusive:t})&&(i=e,s=t)}var a;if(null!==n)for(let t=0;t<e.orderBy.length;++t)if(e.orderBy[t].field.isEqual(r)){let e=n.position[t];0<Fi({value:i,inclusive:s},{value:e,inclusive:n.inclusive})&&(i=e,s=n.inclusive);break}return{value:i,inclusive:s}}class $s{constructor(e,t=null,r=[],n=[],i=null,s="F",a=null,o=null){this.path=e,this.collectionGroup=t,this.explicitOrderBy=r,this.filters=n,this.limit=i,this.limitType=s,this.startAt=a,this.endAt=o,this.fe=null,this.me=null,this.pe=null,this.startAt,this.endAt}}function Qs(e,t,r,n,i,s,a,o){return new $s(e,t,r,n,i,s,a,o)}function Ys(e){return new $s(e)}function Ws(e){return 0===e.filters.length&&null===e.limit&&null==e.startAt&&null==e.endAt&&(0===e.explicitOrderBy.length||1===e.explicitOrderBy.length&&e.explicitOrderBy[0].field.isKeyField())}function Xs(e){return null!==e.collectionGroup}function Js(e){let n=e;if(null===n.fe){n.fe=[];let t=new Set;for(var i of n.explicitOrderBy)n.fe.push(i),t.add(i.field.canonicalString());let r=0<n.explicitOrderBy.length?n.explicitOrderBy[n.explicitOrderBy.length-1].dir:"asc",e=(e=>{let t=new R(h.comparator);return e.filters.forEach(e=>{e.getFlattenedFilters().forEach(e=>{e.isInequality()&&(t=t.add(e.field))})}),t})(n);e.forEach(e=>{t.has(e.canonicalString())||e.isKeyField()||n.fe.push(new Ms(e,r))}),t.has(h.keyField().canonicalString())||n.fe.push(new Ms(h.keyField(),r))}return n.fe}function Zs(e){var t=e;return t.me||(t.me=((e,t)=>{if("F"===e.limitType)return Us(e.path,e.collectionGroup,t,e.filters,e.limit,e.startAt,e.endAt);t=t.map(e=>{var t="desc"===e.dir?"asc":"desc";return new Ms(e.field,t)});var r=e.endAt?new ys(e.endAt.position,e.endAt.inclusive):null,n=e.startAt?new ys(e.startAt.position,e.startAt.inclusive):null;return Us(e.path,e.collectionGroup,t,e.filters,e.limit,r,n)})(t,Js(e))),t.me}function ea(e,t){var r=e.filters.concat([t]);return new $s(e.path,e.collectionGroup,e.explicitOrderBy.slice(),r,e.limit,e.limitType,e.startAt,e.endAt)}function ta(e,t,r){return new $s(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),t,r,e.startAt,e.endAt)}function ra(e,t){return qs(Zs(e),Zs(t))&&e.limitType===t.limitType}function na(e){return`Query(target=${(e=>{let t=e.path.canonicalString();return null!==e.collectionGroup&&(t+=" collectionGroup="+e.collectionGroup),0<e.filters.length&&(t+=`, filters: [${e.filters.map(e=>Cs(e)).join(", ")}]`),Ar(e.limit)||(t+=", limit: "+e.limit),0<e.orderBy.length&&(t+=`, orderBy: [${e.orderBy.map(e=>`${(e=e).field.canonicalString()} (${e.dir})`).join(", ")}]`),e.startAt&&(t=(t=(t+=", startAt: ")+(e.startAt.inclusive?"b:":"a:"))+e.startAt.position.map(e=>bi(e)).join(",")),`Target(${t=e.endAt?(t=(t+=", endAt: ")+(e.endAt.inclusive?"a:":"b:"))+e.endAt.position.map(e=>bi(e)).join(","):t})`})(Zs(e))}; limitType=${e.limitType})`}function ia(e,t){return t.isFoundDocument()&&(s=e,o=(a=t).key.path,null!==s.collectionGroup?a.key.hasCollectionId(s.collectionGroup)&&s.path.isPrefixOf(o):x.isDocumentKey(s.path)?s.path.isEqual(o):s.path.isImmediateParentOf(o))&&((e,t)=>{for(var r of Js(e))if(!r.field.isKeyField()&&null===t.data.field(r.field))return!1;return!0})(e,t)&&((e,t)=>{for(var r of e.filters)if(!r.matches(t))return!1;return!0})(e,t)&&(a=t,!(s=e).startAt||(n=s.startAt,r=Js(s),i=ws(n,r,a),n.inclusive?i<=0:i<0))&&(!s.endAt||(r=s.endAt,n=Js(s),i=ws(r,n,a),r.inclusive?0<=i:0<i));var r,n,i,s,a,o}function sa(e){return(t,r)=>{let n=!1;for(var i of Js(e)){let e=((e,t,r)=>{var n=e.field.isKeyField()?x.comparator(t.key,r.key):((e,t,r)=>{var n=t.data.field(e),i=r.data.field(e);return null!==n&&null!==i?_i(n,i):A(42886)})(e.field,t,r);switch(e.dir){case"asc":return n;case"desc":return-1*n;default:return A(19790,{direction:e.dir})}})(i,t,r);if(0!==e)return e;n=n||i.field.isKeyField()}return 0}}class aa{constructor(e,t){this.count=e,this.unchangedNames=t}}function oa(e){switch(e){case _.OK:return A(64938);case _.CANCELLED:case _.UNKNOWN:case _.DEADLINE_EXCEEDED:case _.RESOURCE_EXHAUSTED:case _.INTERNAL:case _.UNAVAILABLE:case _.UNAUTHENTICATED:return!1;case _.INVALID_ARGUMENT:case _.NOT_FOUND:case _.ALREADY_EXISTS:case _.PERMISSION_DENIED:case _.FAILED_PRECONDITION:case _.ABORTED:case _.OUT_OF_RANGE:case _.UNIMPLEMENTED:case _.DATA_LOSS:return!0;default:return A(15467,{code:e})}}function ua(e){if(void 0===e)return lt("GRPC error has no .code"),_.UNKNOWN;switch(e){case Me.OK:return _.OK;case Me.CANCELLED:return _.CANCELLED;case Me.UNKNOWN:return _.UNKNOWN;case Me.DEADLINE_EXCEEDED:return _.DEADLINE_EXCEEDED;case Me.RESOURCE_EXHAUSTED:return _.RESOURCE_EXHAUSTED;case Me.INTERNAL:return _.INTERNAL;case Me.UNAVAILABLE:return _.UNAVAILABLE;case Me.UNAUTHENTICATED:return _.UNAUTHENTICATED;case Me.INVALID_ARGUMENT:return _.INVALID_ARGUMENT;case Me.NOT_FOUND:return _.NOT_FOUND;case Me.ALREADY_EXISTS:return _.ALREADY_EXISTS;case Me.PERMISSION_DENIED:return _.PERMISSION_DENIED;case Me.FAILED_PRECONDITION:return _.FAILED_PRECONDITION;case Me.ABORTED:return _.ABORTED;case Me.OUT_OF_RANGE:return _.OUT_OF_RANGE;case Me.UNIMPLEMENTED:return _.UNIMPLEMENTED;case Me.DATA_LOSS:return _.DATA_LOSS;default:return A(39323,{code:e})}}(e=Me=Me||{})[e.OK=0]="OK",e[e.CANCELLED=1]="CANCELLED",e[e.UNKNOWN=2]="UNKNOWN",e[e.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",e[e.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",e[e.NOT_FOUND=5]="NOT_FOUND",e[e.ALREADY_EXISTS=6]="ALREADY_EXISTS",e[e.PERMISSION_DENIED=7]="PERMISSION_DENIED",e[e.UNAUTHENTICATED=16]="UNAUTHENTICATED",e[e.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",e[e.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",e[e.ABORTED=10]="ABORTED",e[e.OUT_OF_RANGE=11]="OUT_OF_RANGE",e[e.UNIMPLEMENTED=12]="UNIMPLEMENTED",e[e.INTERNAL=13]="INTERNAL",e[e.UNAVAILABLE=14]="UNAVAILABLE",e[e.DATA_LOSS=15]="DATA_LOSS";class la{constructor(e,t){this.mapKeyFn=e,this.equalsFn=t,this.inner={},this.innerSize=0}get(r){let e=this.mapKeyFn(r),n=this.inner[e];if(void 0!==n)for(let[e,t]of n)if(this.equalsFn(e,r))return t}has(e){return void 0!==this.get(e)}set(t,r){var e=this.mapKeyFn(t),n=this.inner[e];if(void 0===n)this.inner[e]=[[t,r]];else{for(let e=0;e<n.length;e++)if(this.equalsFn(n[e][0],t))return void(n[e]=[t,r]);n.push([t,r])}this.innerSize++}delete(t){var r=this.mapKeyFn(t),n=this.inner[r];if(void 0!==n)for(let e=0;e<n.length;e++)if(this.equalsFn(n[e][0],t))return 1===n.length?delete this.inner[r]:n.splice(e,1),this.innerSize--,!0;return!1}forEach(n){$n(this.inner,(e,t)=>{for(let[e,r]of t)n(e,r)})}isEmpty(){return Qn(this.inner)}size(){return this.innerSize}}let ha=new O(x.comparator);let ca=new O(x.comparator);function da(...e){let t=ca;for(var r of e)t=t.insert(r.key,r);return t}function pa(e){let r=ca;return e.forEach((e,t)=>r=r.insert(e,t.overlayedDocument)),r}function fa(){return new la(e=>e.toString(),(e,t)=>e.isEqual(t))}let ga=new O(x.comparator),ma=new R(x.comparator);function V(...e){let t=ma;for(var r of e)t=t.add(r);return t}let va=new R(C);function ya(){return new TextEncoder}let wa=new ue([4294967295,4294967295],0);function _a(e){var t=ya().encode(e),r=new le;return r.update(t),new Uint8Array(r.digest())}function Ea(e){var t=new DataView(e.buffer),r=t.getUint32(0,!0),n=t.getUint32(4,!0),i=t.getUint32(8,!0),t=t.getUint32(12,!0);return[new ue([r,n],0),new ue([i,t],0)]}class Ta{constructor(e,t,r){if(this.bitmap=e,this.padding=t,this.hashCount=r,t<0||8<=t)throw new ba("Invalid padding: "+t);if(r<0)throw new ba("Invalid hash count: "+r);if(0<e.length&&0===this.hashCount)throw new ba("Invalid hash count: "+r);if(0===e.length&&0!==t)throw new ba("Invalid padding when bitmap length is 0: "+t);this.ge=8*e.length-t,this.ye=ue.fromNumber(this.ge)}we(e,t,r){let n=e.add(t.multiply(ue.fromNumber(r)));return(n=1===n.compare(wa)?new ue([n.getBits(0),n.getBits(1)],0):n).modulo(this.ye).toNumber()}be(e){return!!(this.bitmap[Math.floor(e/8)]&1<<e%8)}mightContain(e){if(0===this.ge)return!1;let t=_a(e),[r,n]=Ea(t);for(let i=0;i<this.hashCount;i++){let e=this.we(r,n,i);if(!this.be(e))return!1}return!0}static create(e,t,r){let n=e%8==0?0:8-e%8,i=new Uint8Array(Math.ceil(e/8)),s=new Ta(i,n,t);return r.forEach(e=>s.insert(e)),s}insert(i){if(0!==this.ge){let e=_a(i),[t,r]=Ea(e);for(let n=0;n<this.hashCount;n++){let e=this.we(t,r,n);this.ve(e)}}}ve(e){var t=Math.floor(e/8);this.bitmap[t]|=1<<e%8}}class ba extends Error{constructor(){super(...arguments),this.name="BloomFilterError"}}class Sa{constructor(e,t,r,n,i,s){this.snapshotVersion=e,this.targetChanges=t,this.targetMismatches=r,this.documentUpdates=n,this.augmentedDocumentUpdates=i,this.resolvedLimboDocuments=s}static createSynthesizedRemoteEventForCurrentChange(e,t,r){var n=new Map;return n.set(e,Ia.createSynthesizedTargetChangeForCurrentChange(e,t,r)),new Sa(N.min(),n,new O(C),ha,ha,V())}}class Ia{constructor(e,t,r,n,i){this.resumeToken=e,this.current=t,this.addedDocuments=r,this.modifiedDocuments=n,this.removedDocuments=i}static createSynthesizedTargetChangeForCurrentChange(e,t,r){return new Ia(r,t,V(),V(),V())}}class Aa{constructor(e,t,r,n){this.Se=e,this.removedTargetIds=t,this.key=r,this.De=n}}class Ca{constructor(e,t){this.targetId=e,this.xe=t}}class xa{constructor(e,t,r=k.EMPTY_BYTE_STRING,n=null){this.state=e,this.targetIds=t,this.resumeToken=r,this.cause=n}}class Na{constructor(e){this.targetId=e,this.Ce=0,this.Fe=ka(),this.Oe=k.EMPTY_BYTE_STRING,this.Me=!1,this.Ne=!0}get current(){return this.Me}get resumeToken(){return this.Oe}get Le(){return 0!==this.Ce}get Be(){return this.Ne}Ue(e){0<e.approximateByteSize()&&(this.Ne=!0,this.Oe=e)}ke(){let r=V(),n=V(),i=V();return this.Fe.forEach((e,t)=>{switch(t){case 0:r=r.add(e);break;case 2:n=n.add(e);break;case 1:i=i.add(e);break;default:A(38017,{changeType:t})}}),new Ia(this.Oe,this.Me,r,n,i)}qe(){this.Ne=!1,this.Fe=ka()}$e(e,t){this.Ne=!0,this.Fe=this.Fe.insert(e,t)}Ke(e){this.Ne=!0,this.Fe=this.Fe.remove(e)}We(){this.Ce+=1}Qe(){--this.Ce,v(0<=this.Ce,3241,{Ce:this.Ce,targetId:this.targetId})}Ge(){this.Ne=!0,this.Me=!0}}let Da="WatchChangeAggregator";class Oa{constructor(e){this.ze=e,this.je=new Map,this.He=ha,this.Je=Ra(),this.Ye=ha,this.Ze=Ra(),this.Xe=new O(C)}et(e){for(var t of e.Se)e.De&&e.De.isFoundDocument()?this.tt(t,e.De):this.nt(t,e.key,e.De);for(var r of e.removedTargetIds)this.nt(r,e.key,e.De)}rt(r){this.forEachTarget(r,e=>{var t=this.je.get(e);if(t)switch(r.state){case 0:this.it(e)&&t.Ue(r.resumeToken);break;case 1:t.Qe(),t.Le||t.qe(),t.Ue(r.resumeToken);break;case 2:t.Qe(),t.Le||this.removeTarget(e);break;case 3:this.it(e)&&(t.Ge(),t.Ue(r.resumeToken));break;case 4:this.it(e)&&(this.st(e),t.Ue(r.resumeToken));break;default:A(56790,{state:r.state})}else m(Da,`handleTargetChange received targetChange for untracked target ID (${e}) with state (${r.state})`)})}forEachTarget(e,r){0<e.targetIds.length?e.targetIds.forEach(r):this.je.forEach((e,t)=>{this.it(t)&&r(t)})}_t(e){return Gs(e)?"documents"===e.getPipelineSourceType()&&1===e.getPipelineDocuments()?.length:js(e)}ot(n){let i=n.targetId,e=n.xe.count,t=this.ut(i);if(t){var r=t.target;if(this._t(r))if(0===e){let e=new x(Gs(r)?T.fromString(r.getPipelineDocuments()[0]):r.path);this.nt(i,e,Vs.newNoDocument(e,N.min()))}else v(1===e,20013,"Single document existence filter with count: "+e);else{let r=this.ct(i);if(r!==e){let e=this.lt(n),t=e?this.Et(e,n,r):1;if(0!==t){this.st(i);let e=2===t?"TargetPurposeExistenceFilterMismatchBloom":"TargetPurposeExistenceFilterMismatch";this.Xe=this.Xe.insert(i,e)}}}}}lt(e){var t=e.xe.unchangedNames;if(!t||!t.bits)return null;var{bits:{bitmap:t="",padding:r=0},hashCount:n=0}=t;let i,s;try{i=Jn(t).toUint8Array()}catch(e){if(e instanceof Yn)return ht("Decoding the base64 bloom filter in existence filter failed ("+e.message+"); ignoring the bloom filter and falling back to full re-query."),null;throw e}try{s=new Ta(i,r,n)}catch(e){return ht(e instanceof ba?"BloomFilter error: ":"Applying bloom filter failed: ",e),null}return 0===s.ge?null:s}Et(e,t,r){return t.xe.count===r-this.Pt(e,t.targetId)?0:2}Pt(r,n){var e=this.ze.getRemoteKeysForTarget(n);let i=0;return e.forEach(e=>{var t=this.ze.Tt(),t=`projects/${t.projectId}/databases/${t.database}/documents/`+e.path.canonicalString();r.mightContain(t)||(this.nt(n,e,null),i++)}),i}Rt(i){let t=new Map,n=(this.je.forEach((e,r)=>{var n=this.ut(r);if(n){if(e.current&&this._t(n.target)){let e=Gs(n.target)?T.fromString(n.target.getPipelineDocuments()[0]):n.target.path,t=new x(e);this.It(t).has(r)||this.At(r,t)||this.nt(r,t,Vs.newNoDocument(t,i))}e.Be&&(t.set(r,e.ke()),e.qe())}}),V());this.Ze.forEach((e,t)=>{let r=!0;t.forEachWhile(e=>{var t=this.ut(e);return!t||"TargetPurposeLimboResolution"===t.purpose||(r=!1)}),r&&(n=n.add(e))}),this.He.forEach((e,t)=>t.setReadTime(i)),this.Ye.forEach((e,t)=>t.setReadTime(i));var e=new Sa(i,t,this.Xe,this.He,this.Ye,n);return this.He=ha,this.Je=Ra(),this.Ye=ha,this.Ze=Ra(),this.Xe=new O(C),e}tt(e,t){var r,n=this.je.get(e);n&&this.it(e)?(r=this.At(e,t.key)?2:0,n.$e(t.key,r),Gs(this.ut(e).target)&&"exact"!==this.ut(e).target.getPipelineFlavor()?this.Ye=this.Ye.insert(t.key,t):this.He=this.He.insert(t.key,t),this.Je=this.Je.insert(t.key,this.It(t.key).add(e)),this.Ze=this.Ze.insert(t.key,this.Vt(t.key).add(e))):m(Da,`addDocumentToTarget received document for unknown inactive target (${e})`)}nt(e,t,r){var n=this.je.get(e);n&&this.it(e)?(this.At(e,t)?n.$e(t,1):n.Ke(t),this.Ze=this.Ze.insert(t,this.Vt(t).delete(e)),this.Ze=this.Ze.insert(t,this.Vt(t).add(e)),r&&(Gs(this.ut(e).target)&&"exact"!==this.ut(e).target.getPipelineFlavor()?this.Ye=this.Ye.insert(t,r):this.He=this.He.insert(t,r))):m(Da,`removeDocumentFromTarget received document for unknown or inactive target (${e})`)}removeTarget(e){this.je.delete(e)}ct(e){var t=this.je.get(e);return t?(t=t.ke(),this.ze.getRemoteKeysForTarget(e).size+t.addedDocuments.size-t.removedDocuments.size):0}We(e){let t=this.je.get(e);t||(m(Da,"recordPendingTargetRequest set up tracking for target ID "+e),t=new Na(e),this.je.set(e,t)),t.We()}Vt(e){let t=this.Ze.get(e);return t||(t=new R(C),this.Ze=this.Ze.insert(e,t)),t}It(e){let t=this.Je.get(e);return t||(t=new R(C),this.Je=this.Je.insert(e,t)),t}it(e){var t=null!==this.ut(e);return t||m(Da,"Detected inactive target",e),t}ut(e){var t=this.je.get(e);return void 0===t||t.Le?null:this.ze.dt(e)}st(t){this.je.set(t,new Na(t)),this.ze.getRemoteKeysForTarget(t).forEach(e=>{this.nt(t,e,null)})}At(e,t){return this.ze.getRemoteKeysForTarget(e).has(t)}}function Ra(){return new O(x.comparator)}function ka(){return new O(x.comparator)}let La={asc:"ASCENDING",desc:"DESCENDING"},Pa={"<":"LESS_THAN","<=":"LESS_THAN_OR_EQUAL",">":"GREATER_THAN",">=":"GREATER_THAN_OR_EQUAL","==":"EQUAL","!=":"NOT_EQUAL","array-contains":"ARRAY_CONTAINS",in:"IN","not-in":"NOT_IN","array-contains-any":"ARRAY_CONTAINS_ANY"},Ma={and:"AND",or:"OR"};class Va{constructor(e,t){this.databaseId=e,this.useProto3Json=t}}function Fa(e,t){return e.useProto3Json||Ar(t)?t:{value:t}}function Ua(e,t){return e.useProto3Json?`${new Date(1e3*t.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+t.nanoseconds).slice(-9)}Z`:{seconds:""+t.seconds,nanos:t.nanoseconds}}function Ba(e){var t=Xn(e);return new w(t.seconds,t.nanos)}function qa(e,t){return e.useProto3Json?t.toBase64():t.toUint8Array()}function Ga(e,t){return Ua(e,t.toTimestamp())}function ja(e){return v(!!e,49232),N.fromTimestamp(Ba(e))}function za(e,t){return Ha(e,t).canonicalString()}function Ha(e,t){e=e;var r=new T(["projects",e.projectId,"databases",e.database]).child("documents");return void 0===t?r:r.child(t)}function Ka(e){var t=T.fromString(e);return v(p1(t),10190,{key:t.toString()}),t}function $a(e,t){return za(e.databaseId,t.path)}function Qa(e,t){var r=Ka(t);if(r.get(1)!==e.databaseId.projectId)throw new E(_.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+r.get(1)+" vs "+e.databaseId.projectId);if(r.get(3)!==e.databaseId.database)throw new E(_.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+r.get(3)+" vs "+e.databaseId.database);return new x(Ja(r))}function Ya(e,t){return za(e.databaseId,t)}function Wa(e){var t=Ka(e);return 4===t.length?T.emptyPath():Ja(t)}function Xa(e){return new T(["projects",e.databaseId.projectId,"databases",e.databaseId.database]).canonicalString()}function Ja(e){return v(4<e.length&&"documents"===e.get(4),29091,{key:e.toString()}),e.popFirst(5)}function Za(e,t,r){return{name:$a(e,t),fields:r.value.mapValue.fields}}function e1(e,t,r){var n=Qa(e,t.name),i=ja(t.updateTime),s=t.createTime?ja(t.createTime):N.min(),a=new Ui({mapValue:{fields:t.fields}}),n=Vs.newFoundDocument(n,i,s,a);return r&&n.setHasCommittedMutations(),r?n.setHasCommittedMutations():n}function t1(e,t){let r;if(t instanceof cs)r={update:Za(e,t.key,t.value)};else if(t instanceof ms)r={delete:$a(e,t.key)};else if(t instanceof ds)r={update:Za(e,t.key,t.data),updateMask:(e=>{let t=[];return e.fields.forEach(e=>t.push(e.canonicalString())),{fieldPaths:t}})(t.fieldMask)};else{if(!(t instanceof vs))return A(16599,{gt:t.type});r={verify:$a(e,t.key)}}return 0<t.fieldTransforms.length&&(r.updateTransforms=t.fieldTransforms.map(e=>{var t=e.transform;if(t instanceof Hi)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(t instanceof Ki)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:t.elements}};if(t instanceof Qi)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:t.elements}};if(t instanceof Xi)return{fieldPath:e.field.canonicalString(),increment:t.Re};if(t instanceof Ji)return{fieldPath:e.field.canonicalString(),minimum:t.Re};if(t instanceof Zi)return{fieldPath:e.field.canonicalString(),maximum:t.Re};throw A(20930,{transform:e.transform})})),t.precondition.isNone||(r.currentDocument=(e=e,void 0!==(t=t.precondition).updateTime?{updateTime:Ga(e,t.updateTime)}:void 0!==t.exists?{exists:t.exists}:A(27497))),r}function r1(i,t){let r=t.currentDocument?void 0!==(s=t.currentDocument).updateTime?ss.updateTime(ja(s.updateTime)):void 0!==s.exists?ss.exists(s.exists):ss.none():ss.none(),n=t.updateTransforms?t.updateTransforms.map(r=>{{var e=i;let t=null;if("setToServerValue"in r)v("REQUEST_TIME"===r.setToServerValue,16630,{proto:r}),t=new Hi;else if("appendMissingElements"in r){let e=r.appendMissingElements.values||[];t=new Ki(e)}else if("removeAllFromArray"in r){let e=r.removeAllFromArray.values||[];t=new Qi(e)}else"increment"in r?t=new Xi(e,r.increment):"minimum"in r?t=new Ji(e,r.minimum):"maximum"in r?t=new Zi(e,r.maximum):A(16584,{proto:r});var n=h.fromServerFormat(r.fieldPath);return new ns(n,t)}}):[];var s,a;if(t.update){t.update.name;var o=Qa(i,t.update.name),u=new Ui({mapValue:{fields:t.update.fields}});if(t.updateMask){s=t.updateMask,a=s.fieldPaths||[];let e=new Hn(a.map(e=>h.fromServerFormat(e)));return new ds(o,u,e,r,n)}return new cs(o,u,r,n)}if(t.delete){let e=Qa(i,t.delete);return new ms(e,r)}if(t.verify){let e=Qa(i,t.verify);return new vs(e,r)}return A(1463,{proto:t})}function n1(e,n){return e&&0<e.length?(v(void 0!==n,14353),e.map(t=>{{var r=n;let e=t.updateTime?ja(t.updateTime):ja(r);return e.isEqual(N.min())&&(e=ja(r)),new is(e,t.transformResults||[])}})):[]}function i1(e,t){return{documents:[Ya(e,t.path)]}}function s1(e,t){var r={structuredQuery:{}},n=t.path;let i;null!==t.collectionGroup?(i=n,r.structuredQuery.from=[{collectionId:t.collectionGroup,allDescendants:!0}]):(i=n.popLast(),r.structuredQuery.from=[{collectionId:n.lastSegment()}]),r.parent=Ya(e,i);n=(e=>{if(0!==e.length)return function r(e){return e instanceof P?(e=>{if("=="===e.op){if(Di(e.value))return{unaryFilter:{field:c1(e.field),op:"IS_NAN"}};if(Ni(e.value))return{unaryFilter:{field:c1(e.field),op:"IS_NULL"}}}else if("!="===e.op){if(Di(e.value))return{unaryFilter:{field:c1(e.field),op:"IS_NOT_NAN"}};if(Ni(e.value))return{unaryFilter:{field:c1(e.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:c1(e.field),op:l1(e.op),value:e.value}}})(e):e instanceof M?(e=>{let t=e.getFilters().map(e=>r(e));return 1===t.length?t[0]:{compositeFilter:{op:h1(e.op),filters:t}}})(e):A(54877,{filter:e})}(M.create(e,"and"))})(t.filters),n&&(r.structuredQuery.where=n),n=(e=>{if(0!==e.length)return e.map(e=>({field:c1((e=e).field),direction:(e=e.dir,La[e])}))})(t.orderBy),n&&(r.structuredQuery.orderBy=n),n=Fa(e,t.limit);return null!==n&&(r.structuredQuery.limit=n),t.startAt&&(r.structuredQuery.startAt={before:(e=t.startAt).inclusive,values:e.position}),t.endAt&&(r.structuredQuery.endAt={before:!(e=t.endAt).inclusive,values:e.position}),{yt:r,parent:i}}function a1(e){let t=Wa(e.parent);var r,n=e.structuredQuery,i=n.from?n.from.length:0;let s=null;if(0<i){v(1===i,65062);let e=n.from[0];e.allDescendants?s=e.collectionId:t=t.child(e.collectionId)}let a=[],o=(n.where&&(a=(e=n.where,(i=function t(e){return void 0!==e.unaryFilter?(i=>{switch(i.unaryFilter.op){case"IS_NAN":let e=d1(i.unaryFilter.field);return P.create(e,"==",{doubleValue:NaN});case"IS_NULL":let t=d1(i.unaryFilter.field);return P.create(t,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":let r=d1(i.unaryFilter.field);return P.create(r,"!=",{doubleValue:NaN});case"IS_NOT_NULL":let n=d1(i.unaryFilter.field);return P.create(n,"!=",{nullValue:"NULL_VALUE"});case"OPERATOR_UNSPECIFIED":return A(61313);default:return A(60726)}})(e):void 0!==e.fieldFilter?(e=>P.create(d1(e.fieldFilter.field),(e=>{switch(e){case"EQUAL":return"==";case"NOT_EQUAL":return"!=";case"GREATER_THAN":return">";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";case"OPERATOR_UNSPECIFIED":return A(58110);default:return A(50506)}})(e.fieldFilter.op),e.fieldFilter.value))(e):void 0!==e.compositeFilter?(e=>M.create(e.compositeFilter.filters.map(e=>t(e)),(e=>{switch(e){case"AND":return"and";case"OR":return"or";default:return A(1026)}})(e.compositeFilter.op)))(e):A(30097,{filter:e})}(e))instanceof M&&Ss(i)?i.getFilters():[i])),[]),u=(n.orderBy&&(o=n.orderBy.map(e=>(e=e,new Ms(d1(e.field),(e=>{switch(e){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}})(e.direction))))),null),l=(n.limit&&(u=(e=n.limit,Ar(i="object"==typeof e?e.value:e)?null:i)),null),h=(n.startAt&&(l=(e=n.startAt,i=!!e.before,r=e.values||[],new ys(r,i))),null);return n.endAt&&(h=(e=n.endAt,r=!e.before,i=e.values||[],new ys(i,r))),Qs(t,s,o,a,u,"F",l,h)}function o1(e,t){var r=(e=>{switch(e){case"TargetPurposeListen":return null;case"TargetPurposeExistenceFilterMismatch":return"existence-filter-mismatch";case"TargetPurposeExistenceFilterMismatchBloom":return"existence-filter-mismatch-bloom";case"TargetPurposeLimboResolution":return"limbo-document";default:return A(28987,{purpose:e})}})(t.purpose);return null==r?null:{"goog-listen-tags":r}}function u1(t,e){return{structuredPipeline:{pipeline:{stages:e.stages.map(e=>e._toProto(t))}}}}function l1(e){return Pa[e]}function h1(e){return Ma[e]}function c1(e){return{fieldPath:e.canonicalString()}}function d1(e){return h.fromServerFormat(e.fieldPath)}function p1(e){return 4<=e.length&&"projects"===e.get(0)&&"databases"===e.get(2)}function f1(e){return e&&"function"==typeof e._toProto&&"ProtoValue"===e._protoValueType}function g1(r,e){let n={fields:{}};return e.forEach((e,t)=>{if("string"!=typeof t)throw new Error("Cannot encode map with non-string key: "+t);n.fields[t]=e._toProto(r)}),{mapValue:n}}function m1(e){return{stringValue:e}}function v1(e){return new Va(e,!0)}class y1{constructor(e){this._byteString=e}static fromBase64String(e){try{return new y1(k.fromBase64String(e))}catch(e){throw new E(_.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+e)}}static fromUint8Array(e){return new y1(k.fromUint8Array(e))}toBase64(){return this._byteString.toBase64()}toUint8Array(){return this._byteString.toUint8Array()}toString(){return"Bytes(base64: "+this.toBase64()+")"}isEqual(e){return this._byteString.isEqual(e._byteString)}toJSON(){return{type:y1._jsonSchemaVersion,bytes:this.toBase64()}}static fromJSON(e){if(Bt(e,y1._jsonSchema))return y1.fromBase64String(e.bytes)}}y1._jsonSchemaVersion="firestore/bytes/1.0",y1._jsonSchema={type:Ut("string",y1._jsonSchemaVersion),bytes:Ut("string")};class w1{constructor(...e){for(let t=0;t<e.length;++t)if(0===e[t].length)throw new E(_.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new h(e)}isEqual(e){return this._internalPath.isEqual(e._internalPath)}}class _1{constructor(e){this._methodName=e}}class E1{constructor(e,t){if(!isFinite(e)||e<-90||90<e)throw new E(_.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+e);if(!isFinite(t)||t<-180||180<t)throw new E(_.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+t);this._lat=e,this._long=t}get latitude(){return this._lat}get longitude(){return this._long}isEqual(e){return this._lat===e._lat&&this._long===e._long}_compareTo(e){return C(this._lat,e._lat)||C(this._long,e._long)}toJSON(){return{latitude:this._lat,longitude:this._long,type:E1._jsonSchemaVersion}}static fromJSON(e){if(Bt(e,E1._jsonSchema))return new E1(e.latitude,e.longitude)}}function T1(e){var t={};return void 0!==e.timeoutSeconds&&(t.timeoutSeconds=e.timeoutSeconds),t}E1._jsonSchemaVersion="firestore/geoPoint/1.0",E1._jsonSchema={type:Ut("string",E1._jsonSchemaVersion),latitude:Ut("number"),longitude:Ut("number")};class b1{bt(e){}shutdown(){}}let S1="ConnectivityMonitor";class I1{constructor(){this.vt=()=>this.St(),this.Dt=()=>this.xt(),this.Ct=[],this.Ft()}bt(e){this.Ct.push(e)}shutdown(){window.removeEventListener("online",this.vt),window.removeEventListener("offline",this.Dt)}Ft(){window.addEventListener("online",this.vt),window.addEventListener("offline",this.Dt)}St(){m(S1,"Network connectivity changed: AVAILABLE");for(var e of this.Ct)e(0)}xt(){m(S1,"Network connectivity changed: UNAVAILABLE");for(var e of this.Ct)e(1)}static C(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}}let A1=null;function C1(){return null===A1?A1=268435456+Math.round(2147483648*Math.random()):A1++,"0x"+A1.toString(16)}let x1="RestConnection",N1={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery",ExecutePipeline:"executePipeline"};class D1{constructor(e){this.Kt=e.Kt,this.Wt=e.Wt}Qt(e){this.Gt=e}zt(e){this.jt=e}Ht(e){this.Jt=e}onMessage(e){this.Yt=e}close(){this.Wt()}send(e){this.Kt(e)}Zt(){this.Gt()}Xt(){this.jt()}en(e){this.Jt(e)}tn(e){this.Yt(e)}}let O1="WebChannelConnection",R1=(e,t,r)=>{e.listen(t,e=>{try{r(e)}catch(e){setTimeout(()=>{throw e},0)}})};class k1 extends class{get Ot(){return!1}constructor(e){this.databaseInfo=e,this.databaseId=e.databaseId;var t=e.ssl?"https":"http",r=encodeURIComponent(this.databaseId.projectId),n=encodeURIComponent(this.databaseId.database);this.Mt=t+"://"+e.host,this.Nt=`projects/${r}/databases/`+n,this.Lt=this.databaseId.database===oi?"project_id="+r:`project_id=${r}&database_id=`+n}Bt(t,e,r,n,i){let s=C1(),a=this.Ut(t,e.toUriEncodedString());m(x1,`Sending RPC '${t}' ${s}:`,a,r);var o={"google-cloud-resource-prefix":this.Nt,"x-goog-request-params":this.Lt},u=(this.kt(o,n,i),new URL(a)).host,u=ae(u);return this.qt(t,a,o,r,u).then(e=>(m(x1,`Received RPC '${t}' ${s}: `,e),e),e=>{throw ht(x1,`RPC '${t}' ${s} failed with error: `,e,"url: ",a,"request:",r),e})}$t(e,t,r,n,i,s){return this.Bt(e,t,r,n,i)}kt(r,e,t){r["X-Goog-Api-Client"]="gl-js/ fire/"+at,r["Content-Type"]="text/plain",this.databaseInfo.appId&&(r["X-Firebase-GMPID"]=this.databaseInfo.appId),e&&e.headers.forEach((e,t)=>r[t]=e),t&&t.headers.forEach((e,t)=>r[t]=e)}Ut(e,t){var r=N1[e];let n=this.Mt+`/v1/${t}:`+r;return n=this.databaseInfo.apiKey?n+"?key="+encodeURIComponent(this.databaseInfo.apiKey):n}terminate(){}}{constructor(e){super(e),this.nn=[],this.forceLongPolling=e.forceLongPolling,this.autoDetectLongPolling=e.autoDetectLongPolling,this.useFetchStreams=e.useFetchStreams,this.longPollingOptions=e.longPollingOptions}static rn(){var e;k1.sn||(e=dr(),R1(e,cr.STAT_EVENT,e=>{e.stat===hr.PROXY?m(O1,"STAT_EVENT: detected buffering proxy"):e.stat===hr.NOPROXY&&m(O1,"STAT_EVENT: detected no buffering proxy")}),k1.sn=!0)}qt(u,t,r,n,e){let l=C1();return new Promise((s,a)=>{let o=new ar;o.setWithCredentials(!0),o.listenOnce(ur.COMPLETE,()=>{try{switch(o.getLastErrorCode()){case lr.NO_ERROR:var e=o.getResponseJson();m(O1,`XHR for RPC '${u}' ${l} received:`,JSON.stringify(e)),s(e);break;case lr.TIMEOUT:m(O1,`RPC '${u}' ${l} timed out`),a(new E(_.DEADLINE_EXCEEDED,"Request time out"));break;case lr.HTTP_ERROR:var t=o.getStatus();if(m(O1,`RPC '${u}' ${l} failed with status:`,t,"response text:",o.getResponseText()),0<t){let e=o.getResponseJson();var r=(e=Array.isArray(e)?e[0]:e)?.error;if(r&&r.status&&r.message){n=r.status,i=n.toLowerCase().replace(/_/g,"-");let e=0<=Object.values(_).indexOf(i)?i:_.UNKNOWN;a(new E(e,r.message))}else a(new E(_.UNKNOWN,"Server responded with status "+o.getStatus()))}else a(new E(_.UNAVAILABLE,"Connection failed."));break;default:A(9055,{_n:u,streamId:l,an:o.getLastErrorCode(),un:o.getLastError()})}}finally{m(O1,`RPC '${u}' ${l} completed.`)}var n,i});var e=JSON.stringify(n);m(O1,`RPC '${u}' ${l} sending request:`,n),o.send(t,"POST",e,r,15)})}cn(i,e,t){let s=C1(),r=[this.Mt,"/","google.firestore.v1.Firestore","/",i,"/channel"],n=this.createWebChannelTransport(),a={httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:`projects/${this.databaseId.projectId}/databases/`+this.databaseId.database},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling,detectBufferingProxy:this.autoDetectLongPolling},o=this.longPollingOptions.timeoutSeconds;void 0!==o&&(a.longPollingTimeout=Math.round(1e3*o)),this.useFetchStreams&&(a.useFetchStreams=!0),this.kt(a.initMessageHeaders,e,t),a.encodeInitMessageHeaders=!0;var u=r.join("");m(O1,`Creating RPC '${i}' stream ${s}: `+u,a);let l=n.createWebChannel(u,a),h=(this.En(l),!1),c=!1,d=new D1({Kt:e=>{c?m(O1,`Not sending because RPC '${i}' stream ${s} is closed:`,e):(h||(m(O1,`Opening RPC '${i}' stream ${s} transport.`),l.open(),h=!0),m(O1,`RPC '${i}' stream ${s} sending:`,e),l.send(e))},Wt:()=>l.close()});return R1(l,or.EventType.OPEN,()=>{c||(m(O1,`RPC '${i}' stream ${s} transport opened.`),d.Zt())}),R1(l,or.EventType.CLOSE,()=>{c||(c=!0,m(O1,`RPC '${i}' stream ${s} transport closed`),d.en(),this.hn(l))}),R1(l,or.EventType.ERROR,e=>{c||(c=!0,ht(O1,`RPC '${i}' stream ${s} transport errored. Name:`,e.name,"Message:",e.message),d.en(new E(_.UNAVAILABLE,"The operation could not be completed")))}),R1(l,or.EventType.MESSAGE,e=>{if(!c){var t=e.data[0],n=(v(!!t,16349),t),n=n?.error||n[0]?.error;if(n){m(O1,`RPC '${i}' stream ${s} received error:`,n);let e=n.status,t=(e=>{var t=Me[e];if(void 0!==t)return ua(t)})(e),r=n.message;"NOT_FOUND"===e&&r.includes("database")&&r.includes("does not exist")&&r.includes(this.databaseId.database)&&ht(`Database '${this.databaseId.database}' not found. Please check your project configuration.`),void 0===t&&(t=_.INTERNAL,r="Unknown error status: "+e+" with message "+n.message),c=!0,d.en(new E(t,r)),l.close()}else m(O1,`RPC '${i}' stream ${s} received:`,t),d.tn(t)}}),k1.rn(),setTimeout(()=>{d.Xt()},0),d}terminate(){this.nn.forEach(e=>e.close()),this.nn=[]}En(e){this.nn.push(e)}hn(t){this.nn=this.nn.filter(e=>e===t)}kt(e,t,r){super.kt(e,t,r),this.databaseInfo.apiKey&&(e["x-goog-api-key"]=this.databaseInfo.apiKey)}createWebChannelTransport(){return pr()}}k1.sn=!1;class L1{constructor(e,t,r=1e3,n=1.5,i=6e4){this.Tn=e,this.timerId=t,this.Pn=r,this.Rn=n,this.In=i,this.An=0,this.Vn=null,this.dn=Date.now(),this.reset()}reset(){this.An=0}fn(){this.An=this.In}mn(e){this.cancel();var t=Math.floor(this.An+this.pn()),r=Math.max(0,Date.now()-this.dn),n=Math.max(0,t-r);0<n&&m("ExponentialBackoff",`Backing off for ${n} ms (base delay: ${this.An} ms, delay with jitter: ${t} ms, last attempt: ${r} ms ago)`),this.Vn=this.Tn.enqueueAfterDelay(this.timerId,n,()=>(this.dn=Date.now(),e())),this.An*=this.Rn,this.An<this.Pn&&(this.An=this.Pn),this.An>this.In&&(this.An=this.In)}gn(){null!==this.Vn&&(this.Vn.skipDelay(),this.Vn=null)}cancel(){null!==this.Vn&&(this.Vn.cancel(),this.Vn=null)}pn(){return(Math.random()-.5)*this.An}}let P1="PersistentStream";class M1{constructor(e,t,r,n,i,s,a,o){this.Tn=e,this.yn=r,this.wn=n,this.connection=i,this.authCredentialsProvider=s,this.appCheckCredentialsProvider=a,this.listener=o,this.state=0,this.bn=0,this.vn=null,this.Sn=null,this.stream=null,this.Dn=0,this.xn=new L1(e,t)}Cn(){return 1===this.state||5===this.state||this.Fn()}Fn(){return 2===this.state||3===this.state}start(){this.Dn=0,4!==this.state?this.auth():this.On()}async stop(){this.Cn()&&await this.close(0)}Mn(){this.state=0,this.xn.reset()}Nn(){this.Fn()&&null===this.vn&&(this.vn=this.Tn.enqueueAfterDelay(this.yn,6e4,()=>this.Ln()))}Bn(e){this.Un(),this.stream.send(e)}async Ln(){if(this.Fn())return this.close(0)}Un(){this.vn&&(this.vn.cancel(),this.vn=null)}kn(){this.Sn&&(this.Sn.cancel(),this.Sn=null)}async close(e,t){this.Un(),this.kn(),this.xn.cancel(),this.bn++,4!==e?this.xn.reset():t&&t.code===_.RESOURCE_EXHAUSTED?(lt(t.toString()),lt("Using maximum backoff delay to prevent overloading the backend."),this.xn.fn()):t&&t.code===_.UNAUTHENTICATED&&3!==this.state&&(this.authCredentialsProvider.invalidateToken(),this.appCheckCredentialsProvider.invalidateToken()),null!==this.stream&&(this.qn(),this.stream.close(),this.stream=null),this.state=e,await this.listener.Ht(t)}qn(){}auth(){this.state=1;let e=this.$n(this.bn),r=this.bn;Promise.all([this.authCredentialsProvider.getToken(),this.appCheckCredentialsProvider.getToken()]).then(([e,t])=>{this.bn===r&&this.Kn(e,t)},t=>{e(()=>{var e=new E(_.UNKNOWN,"Fetching auth token failed: "+t.message);return this.Wn(e)})})}Kn(e,t){let r=this.$n(this.bn);this.stream=this.Qn(e,t),this.stream.Qt(()=>{r(()=>this.listener.Qt())}),this.stream.zt(()=>{r(()=>(this.state=2,this.Sn=this.Tn.enqueueAfterDelay(this.wn,1e4,()=>(this.Fn()&&(this.state=3),Promise.resolve())),this.listener.zt()))}),this.stream.Ht(e=>{r(()=>this.Wn(e))}),this.stream.onMessage(e=>{r(()=>1==++this.Dn?this.Gn(e):this.onNext(e))})}On(){this.state=5,this.xn.mn(async()=>{this.state=0,this.start()})}Wn(e){return m(P1,"close with error: "+e),this.stream=null,this.close(4,e)}$n(t){return e=>{this.Tn.enqueueAndForget(()=>this.bn===t?e():(m(P1,"stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve()))}}}class V1 extends M1{constructor(e,t,r,n,i,s){super(e,"listen_stream_connection_backoff","listen_stream_idle","health_check_timeout",t,r,n,s),this.serializer=i}Qn(e,t){return this.connection.cn("Listen",e,t)}Gn(e){return this.onNext(e)}onNext(e){this.xn.reset();var t=((e,t)=>{let r;if("targetChange"in t){t.targetChange;var n="NO_CHANGE"===(u=t.targetChange.targetChangeType||"NO_CHANGE")?0:"ADD"===u?1:"REMOVE"===u?2:"CURRENT"===u?3:"RESET"===u?4:A(39313,{state:u}),i=t.targetChange.targetIds||[],s=(u=t.targetChange.resumeToken,e.useProto3Json?(v(void 0===u||"string"==typeof u,58123),k.fromBase64String(u||"")):(v(void 0===u||u instanceof Buffer||u instanceof Uint8Array,16193),k.fromUint8Array(u||new Uint8Array))),a=t.targetChange.cause,a=a&&(a=void 0===(u=a).code?_.UNKNOWN:ua(u.code),new E(a,u.message||""));r=new xa(n,i,s,a||null)}else if("documentChange"in t){t.documentChange;var n=t.documentChange,i=(n.document,n.document.name,n.document.updateTime,Qa(e,n.document.name)),s=ja(n.document.updateTime),a=n.document.createTime?ja(n.document.createTime):N.min(),o=new Ui({mapValue:{fields:n.document.fields}}),i=Vs.newFoundDocument(i,s,a,o),s=n.targetIds||[],o=n.removedTargetIds||[];r=new Aa(s,o,i.key,i)}else if("documentDelete"in t){t.documentDelete;n=t.documentDelete,s=(n.document,Qa(e,n.document)),o=n.readTime?ja(n.readTime):N.min(),i=Vs.newNoDocument(s,o),s=n.removedTargetIds||[];r=new Aa([],s,i.key,i)}else if("documentRemove"in t){t.documentRemove;o=t.documentRemove,n=(o.document,Qa(e,o.document)),s=o.removedTargetIds||[];r=new Aa([],s,n,null)}else{if(!("filter"in t))return A(11601,{ft:t});{t.filter;let e=t.filter;e.targetId;var{count:i=0,unchangedNames:o}=e,s=new aa(i,o),n=e.targetId;r=new Ca(n,s)}}var u;return r})(this.serializer,e),r="targetChange"in(e=e)&&(!(r=e.targetChange).targetIds||!r.targetIds.length)&&r.readTime?ja(r.readTime):N.min();return this.listener.zn(t,r)}jn(e){var t={},r=(t.database=Xa(this.serializer),t.addTarget=((t,r)=>{var n;let e=r.target;if((n=Gs(e)?{pipelineQuery:u1(t,e)}:js(e)?{documents:i1(t,e)}:{query:s1(t,e).yt}).targetId=r.targetId,0<r.resumeToken.approximateByteSize()){n.resumeToken=qa(t,r.resumeToken);let e=Fa(t,r.expectedCount);null!==e&&(n.expectedCount=e)}else if(0<r.snapshotVersion.compareTo(N.min())){n.readTime=Ua(t,r.snapshotVersion.toTimestamp());let e=Fa(t,r.expectedCount);null!==e&&(n.expectedCount=e)}return n})(this.serializer,e),o1(this.serializer,e));r&&(t.labels=r),this.Bn(t)}Hn(e){var t={};t.database=Xa(this.serializer),t.removeTarget=e,this.Bn(t)}}class F1 extends M1{constructor(e,t,r,n,i,s){super(e,"write_stream_connection_backoff","write_stream_idle","health_check_timeout",t,r,n,s),this.serializer=i}get Jn(){return 0<this.Dn}start(){this.lastStreamToken=void 0,super.start()}qn(){this.Jn&&this.Yn([])}Qn(e,t){return this.connection.cn("Write",e,t)}Gn(e){return v(!!e.streamToken,31322),this.lastStreamToken=e.streamToken,v(!e.writeResults||0===e.writeResults.length,55816),this.listener.Zn()}onNext(e){v(!!e.streamToken,12678),this.lastStreamToken=e.streamToken,this.xn.reset();var t=n1(e.writeResults,e.commitTime),r=ja(e.commitTime);return this.listener.Xn(r,t)}er(){var e={};e.database=Xa(this.serializer),this.Bn(e)}Yn(e){var t={streamToken:this.lastStreamToken,writes:e.map(e=>t1(this.serializer,e))};this.Bn(t)}}class U1 extends class{}{constructor(e,t,r,n){super(),this.authCredentials=e,this.appCheckCredentials=t,this.connection=r,this.serializer=n,this.tr=!1}nr(){if(this.tr)throw new E(_.FAILED_PRECONDITION,"The client has already been terminated.")}Bt(r,n,i,s){return this.nr(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([e,t])=>this.connection.Bt(r,Ha(n,i),s,e,t)).catch(e=>{throw"FirebaseError"===e.name?(e.code===_.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new E(_.UNKNOWN,e.toString())})}$t(r,n,i,s,a){return this.nr(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([e,t])=>this.connection.$t(r,Ha(n,i),s,e,t,a)).catch(e=>{throw"FirebaseError"===e.name?(e.code===_.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new E(_.UNKNOWN,e.toString())})}terminate(){this.tr=!0,this.connection.terminate()}}let B1=new Map;let q1={didRun:!1,sequenceNumbersCollected:0,targetsRemoved:0,documentsRemoved:0};class G1{static withCacheSize(e){return new G1(e,G1.DEFAULT_COLLECTION_PERCENTILE,G1.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}constructor(e,t,r){this.cacheSizeCollectionThreshold=e,this.percentileToCollect=t,this.maximumSequenceNumbersToCollect=r}}G1.DEFAULT_COLLECTION_PERCENTILE=10,G1.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,G1.DEFAULT=new G1(41943040,G1.DEFAULT_COLLECTION_PERCENTILE,G1.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),G1.DISABLED=new G1(-1,0,0);let j1="LruGarbageCollector";function z1([e,t],[r,n]){var i=C(e,r);return 0===i?C(t,n):i}class H1{constructor(e){this.rr=e,this.buffer=new R(z1),this.ir=0}sr(){return++this.ir}_r(e){var t=[e,this.sr()];if(this.buffer.size<this.rr)this.buffer=this.buffer.add(t);else{let e=this.buffer.last();z1(t,e)<0&&(this.buffer=this.buffer.delete(e).add(t))}}get maxValue(){return this.buffer.last()[0]}}class K1{constructor(e,t,r){this.garbageCollector=e,this.asyncQueue=t,this.localStore=r,this.ar=null}start(){-1!==this.garbageCollector.params.cacheSizeCollectionThreshold&&this.ur(6e4)}stop(){this.ar&&(this.ar.cancel(),this.ar=null)}get started(){return null!==this.ar}ur(e){m(j1,`Garbage collection scheduled in ${e}ms`),this.ar=this.asyncQueue.enqueueAfterDelay("lru_garbage_collection",e,async()=>{this.ar=null;try{await this.localStore.collectGarbage(this.garbageCollector)}catch(e){mr(e)?m(j1,"Ignoring IndexedDB error during garbage collection: ",e):await er(e)}await this.ur(3e5)})}}class $1{constructor(e,t){this.cr=e,this.params=t}calculateTargetCount(e,t){return this.cr.lr(e).next(e=>Math.floor(t/100*e))}nthSequenceNumber(e,t){if(0===t)return D.resolve(Sr.ce);let r=new H1(t);return this.cr.forEachTarget(e,e=>r._r(e.sequenceNumber)).next(()=>this.cr.Er(e,e=>r._r(e))).next(()=>r.maxValue)}removeTargets(e,t,r){return this.cr.removeTargets(e,t,r)}removeOrphanedDocuments(e,t){return this.cr.removeOrphanedDocuments(e,t)}collect(t,r){return-1===this.params.cacheSizeCollectionThreshold?(m("LruGarbageCollector","Garbage collection skipped; disabled"),D.resolve(q1)):this.getCacheSize(t).next(e=>e<this.params.cacheSizeCollectionThreshold?(m("LruGarbageCollector",`Garbage collection skipped; Cache size ${e} is lower than threshold `+this.params.cacheSizeCollectionThreshold),q1):this.hr(t,r))}getCacheSize(e){return this.cr.getCacheSize(e)}hr(t,r){let n,i,s,a,o,u,l,h=Date.now();return this.calculateTargetCount(t,this.params.percentileToCollect).next(e=>(i=e>this.params.maximumSequenceNumbersToCollect?(m("LruGarbageCollector",`Capping sequence numbers to collect down to the maximum of ${this.params.maximumSequenceNumbersToCollect} from `+e),this.params.maximumSequenceNumbersToCollect):e,a=Date.now(),this.nthSequenceNumber(t,i))).next(e=>(n=e,o=Date.now(),this.removeTargets(t,n,r))).next(e=>(s=e,u=Date.now(),this.removeOrphanedDocuments(t,n))).next(e=>(l=Date.now(),ut()<=c.DEBUG&&m("LruGarbageCollector",`LRU Garbage Collection
	Counted targets in ${a-h}ms
	Determined least recently used ${i} in `+(o-a)+"ms\n"+`	Removed ${s} targets in `+(u-o)+"ms\n"+`	Removed ${e} documents in `+(l-u)+"ms\n"+`Total Duration: ${l-h}ms`),D.resolve({didRun:!0,sequenceNumbersCollected:i,targetsRemoved:s,documentsRemoved:e})))}}function Q1(e,t){return new $1(e,t)}let Y1="firestore.googleapis.com";class W1{constructor(e){if(void 0===e.host){if(void 0!==e.ssl)throw new E(_.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host=Y1,this.ssl=!0}else this.host=e.host,this.ssl=e.ssl??!0;if(this.isUsingEmulator=void 0!==e.emulatorOptions,this.credentials=e.credentials,this.ignoreUndefinedProperties=!!e.ignoreUndefinedProperties,this.localCache=e.localCache,void 0===e.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==e.cacheSizeBytes&&e.cacheSizeBytes<1048576)throw new E(_.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=e.cacheSizeBytes}kt("experimentalForceLongPolling",e.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",e.experimentalAutoDetectLongPolling),this.experimentalForceLongPolling=!!e.experimentalForceLongPolling,this.experimentalForceLongPolling?this.experimentalAutoDetectLongPolling=!1:void 0===e.experimentalAutoDetectLongPolling?this.experimentalAutoDetectLongPolling=!0:this.experimentalAutoDetectLongPolling=!!e.experimentalAutoDetectLongPolling,this.experimentalLongPollingOptions=T1(e.experimentalLongPollingOptions??{});var t=this.experimentalLongPollingOptions;if(void 0!==t.timeoutSeconds){if(isNaN(t.timeoutSeconds))throw new E(_.INVALID_ARGUMENT,`invalid long polling timeout: ${t.timeoutSeconds} (must not be NaN)`);if(t.timeoutSeconds<5)throw new E(_.INVALID_ARGUMENT,`invalid long polling timeout: ${t.timeoutSeconds} (minimum allowed value is 5)`);if(30<t.timeoutSeconds)throw new E(_.INVALID_ARGUMENT,`invalid long polling timeout: ${t.timeoutSeconds} (maximum allowed value is 30)`)}this.useFetchStreams=!!e.useFetchStreams}isEqual(e){return this.host===e.host&&this.ssl===e.ssl&&this.credentials===e.credentials&&this.cacheSizeBytes===e.cacheSizeBytes&&this.experimentalForceLongPolling===e.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===e.experimentalAutoDetectLongPolling&&(t=this.experimentalLongPollingOptions,r=e.experimentalLongPollingOptions,t.timeoutSeconds===r.timeoutSeconds)&&this.ignoreUndefinedProperties===e.ignoreUndefinedProperties&&this.useFetchStreams===e.useFetchStreams;var t,r}}class X1{constructor(e,t,r,n){this._authCredentials=e,this._appCheckCredentials=t,this._databaseId=r,this._app=n,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new W1({}),this._settingsFrozen=!1,this._emulatorOptions={},this._terminateTask="notTerminated"}get app(){if(this._app)return this._app;throw new E(_.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available")}get _initialized(){return this._settingsFrozen}get _terminated(){return"notTerminated"!==this._terminateTask}_setSettings(e){if(this._settingsFrozen)throw new E(_.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.");this._settings=new W1(e),this._emulatorOptions=e.emulatorOptions||{},void 0!==e.credentials&&(this._authCredentials=(e=>{if(!e)return new gt;switch(e.type){case"firstParty":return new wt(e.sessionIndex||"0",e.iamToken||null,e.authTokenFactory||null);case"provider":return e.client;default:throw new E(_.INVALID_ARGUMENT,"makeAuthCredentialsProvider failed due to invalid credential type")}})(e.credentials))}_getSettings(){return this._settings}_getEmulatorOptions(){return this._emulatorOptions}_freezeSettings(){return this._settingsFrozen=!0,this._settings}_delete(){return"notTerminated"===this._terminateTask&&(this._terminateTask=this._terminate()),this._terminateTask}async _restart(){"notTerminated"===this._terminateTask?await this._terminate():this._terminateTask="notTerminated"}toJSON(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}}_terminate(){return e=this,(t=B1.get(e))&&(m("ComponentProvider","Removing Datastore"),B1.delete(e),t.terminate()),Promise.resolve();var e,t}}function J1(n,e,t,i={}){n=y(n,X1);let r=ae(e),s=n._getSettings(),a={...s,emulatorOptions:n._getEmulatorOptions()},o=e+":"+t;r&&(async e=>(await fetch(e,{credentials:"include"})).ok)("https://"+o),s.host!==Y1&&s.host!==o&&ht("Host has been set in both settings() and connectFirestoreEmulator(), emulator host will be used.");var u={...s,host:o,ssl:r,emulatorOptions:i};if(!ne(u,a)&&(n._setSettings(u),i.mockUserToken)){let t,r;if("string"==typeof i.mockUserToken)t=i.mockUserToken,r=st.MOCK_USER;else{t=((e,t)=>{if(e.uid)throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');var r=t||"demo-project",n=e.iat||0,i=e.sub||e.user_id;if(i)return r={iss:"https://securetoken.google.com/"+r,aud:r,iat:n,exp:n+3600,auth_time:n,sub:i,user_id:i,firebase:{sign_in_provider:"custom",identities:{}},...e},[j(JSON.stringify({alg:"none",type:"JWT"})),j(JSON.stringify(r)),""].join(".");throw new Error("mockUserToken must contain 'sub' or 'user_id' field!")})(i.mockUserToken,n._app?.options.projectId);let e=i.mockUserToken.sub||i.mockUserToken.user_id;if(!e)throw new E(_.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");r=new st(e)}n._authCredentials=new mt(new ft(t,r))}}class Z1{constructor(e,t,r){this.converter=t,this._query=r,this.type="query",this.firestore=e}withConverter(e){return new Z1(this.firestore,e,this._query)}}class F{constructor(e,t,r){this.converter=t,this._key=r,this.type="document",this.firestore=e}get _path(){return this._key.path}get id(){return this._key.path.lastSegment()}get path(){return this._key.path.canonicalString()}get parent(){return new eo(this.firestore,this.converter,this._key.path.popLast())}withConverter(e){return new F(this.firestore,e,this._key)}toJSON(){return{type:F._jsonSchemaVersion,referencePath:this._key.toString()}}static fromJSON(e,t,r){if(Bt(t,F._jsonSchema))return new F(e,r||null,new x(T.fromString(t.referencePath)))}}F._jsonSchemaVersion="firestore/documentReference/1.0",F._jsonSchema={type:Ut("string",F._jsonSchemaVersion),referencePath:Ut("string")};class eo extends Z1{constructor(e,t,r){super(e,t,Ys(r)),this._path=r,this.type="collection"}get id(){return this._query.path.lastSegment()}get path(){return this._query.path.canonicalString()}get parent(){var e=this._path.popLast();return e.isEmpty()?null:new F(this.firestore,null,new x(e))}withConverter(e){return new eo(this.firestore,e,this._path)}}function to(e,t,...r){var n;if(e=se(e),Rt("collection","path",t),e instanceof X1)return Pt(n=T.fromString(t,...r)),new eo(e,null,n);if(e instanceof F||e instanceof eo)return Pt(n=e._path.child(T.fromString(t,...r))),new eo(e.firestore,null,n);throw new E(_.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore")}function ro(e,t,...r){var n;if(e=se(e),Rt("doc","path",t=1===arguments.length?Tt.newId():t),e instanceof X1)return Lt(n=T.fromString(t,...r)),new F(e,null,new x(n));if(e instanceof F||e instanceof eo)return Lt(n=e._path.child(T.fromString(t,...r))),new F(e.firestore,e instanceof eo?e.converter:null,new x(n));throw new E(_.INVALID_ARGUMENT,"Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore")}function no(e,t){return e=se(e),t=se(t),(e instanceof F||e instanceof eo)&&(t instanceof F||t instanceof eo)&&e.firestore===t.firestore&&e.path===t.path&&e.converter===t.converter}function io(e,t){return e=se(e),t=se(t),e instanceof Z1&&t instanceof Z1&&e.firestore===t.firestore&&ra(e._query,t._query)&&e.converter===t.converter}class so{constructor(e){this._values=(e||[]).map(e=>e)}toArray(){return this._values.map(e=>e)}isEqual(e){var t=this._values,r=e._values;if(t.length!==r.length)return!1;for(let n=0;n<t.length;++n)if(t[n]!==r[n])return!1;return!0}toJSON(){return{type:so._jsonSchemaVersion,vectorValues:this._values}}static fromJSON(e){if(Bt(e,so._jsonSchema)){if(Array.isArray(e.vectorValues)&&e.vectorValues.every(e=>"number"==typeof e))return new so(e.vectorValues);throw new E(_.INVALID_ARGUMENT,"Expected 'vectorValues' field to be a number array")}}}so._jsonSchemaVersion="firestore/vectorValue/1.0",so._jsonSchema={type:Ut("string",so._jsonSchemaVersion),vectorValues:Ut("object")};let ao=/^__.*__$/;class oo{constructor(e,t,r){this.data=e,this.fieldMask=t,this.fieldTransforms=r}toMutation(e,t){return null!==this.fieldMask?new ds(e,this.data,this.fieldMask,t,this.fieldTransforms):new cs(e,this.data,t,this.fieldTransforms)}}class uo{constructor(e,t,r){this.data=e,this.fieldMask=t,this.fieldTransforms=r}toMutation(e,t){return new ds(e,this.data,this.fieldMask,t,this.fieldTransforms)}}function lo(e){switch(e){case 0:case 2:case 1:return 1;case 3:case 4:return;default:throw A(40011,{dataSource:e})}}class ho{constructor(e,t,r,n,i,s){this.settings=e,this.databaseId=t,this.serializer=r,this.ignoreUndefinedProperties=n,void 0===i&&this.validatePath(),this.fieldTransforms=i||[],this.fieldMask=s||[]}get path(){return this.settings.path}get dataSource(){return this.settings.dataSource}contextWith(e){return new ho({...this.settings,...e},this.databaseId,this.serializer,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}childContextForField(e){var t=this.path?.child(e),t=this.contextWith({path:t,arrayElement:!1});return t.validatePathSegment(e),t}childContextForFieldPath(e){var t=this.path?.child(e),t=this.contextWith({path:t,arrayElement:!1});return t.validatePath(),t}childContextForArray(e){return this.contextWith({path:void 0,arrayElement:!0})}createError(e){return Oo(e,this.settings.methodName,this.settings.hasConverter||!1,this.path,this.settings.targetDoc)}contains(t){return void 0!==this.fieldMask.find(e=>t.isPrefixOf(e))||void 0!==this.fieldTransforms.find(e=>t.isPrefixOf(e.field))}validatePath(){if(this.path)for(let e=0;e<this.path.length;e++)this.validatePathSegment(this.path.get(e))}validatePathSegment(e){if(0===e.length)throw this.createError("Document fields must not be empty");if(lo(this.dataSource)&&ao.test(e))throw this.createError('Document fields cannot begin and end with "__"')}}class co{constructor(e,t,r){this.databaseId=e,this.ignoreUndefinedProperties=t,this.serializer=r||v1(e)}createContext(e,t,r,n=!1){return new ho({dataSource:e,methodName:t,targetDoc:r,path:h.emptyPath(),arrayElement:!1,hasConverter:n},this.databaseId,this.serializer,this.ignoreUndefinedProperties)}}function po(e){var t=e._freezeSettings(),r=v1(e._databaseId);return new co(e._databaseId,!!t.ignoreUndefinedProperties,r)}function fo(e,n,i,t,r,s={}){var a=e.createContext(s.merge||s.mergeFields?2:0,n,i,r),o=(Co("Data must be an object, but it was:",a,t),Io(t,a));let u,l;if(s.merge)u=new Hn(a.fieldMask),l=a.fieldTransforms;else if(s.mergeFields){let t=[];for(let r of s.mergeFields){let e=xo(n,r,i);if(!a.contains(e))throw new E(_.INVALID_ARGUMENT,`Field '${e}' is specified in your field mask but missing from your input data.`);Ro(t,e)||t.push(e)}u=new Hn(t),l=a.fieldTransforms.filter(e=>u.covers(e.field))}else u=null,l=a.fieldTransforms;return new oo(new Ui(o),u,l)}class go extends _1{_toFieldTransform(e){if(2!==e.dataSource)throw 1===e.dataSource?e.createError(this._methodName+"() can only appear at the top level of your update data"):e.createError(this._methodName+"() cannot be used with set() unless you pass {merge:true}");return e.fieldMask.push(e.path),null}isEqual(e){return e instanceof go}}function mo(e,t,r){return new ho({dataSource:3,targetDoc:t.settings.targetDoc,methodName:e._methodName,arrayElement:r},t.databaseId,t.serializer,t.ignoreUndefinedProperties)}class vo extends _1{_toFieldTransform(e){return new ns(e.path,new Hi)}isEqual(e){return e instanceof vo}}class yo extends _1{constructor(e,t){super(e),this.Tr=t}_toFieldTransform(e){let t=mo(this,e,!0),r=this.Tr.map(e=>So(e,t)),n=new Ki(r);return new ns(e.path,n)}isEqual(e){return e instanceof yo&&ne(this.Tr,e.Tr)}}class wo extends _1{constructor(e,t){super(e),this.Tr=t}_toFieldTransform(e){let t=mo(this,e,!0),r=this.Tr.map(e=>So(e,t)),n=new Qi(r);return new ns(e.path,n)}isEqual(e){return e instanceof wo&&ne(this.Tr,e.Tr)}}class _o extends _1{constructor(e,t){super(e),this.Pr=t}_toFieldTransform(e){var t=new Xi(e.serializer,Gi(e.serializer,this.Pr));return new ns(e.path,t)}isEqual(e){return e instanceof _o&&(this.Pr===e.Pr||Number.isNaN(this.Pr)&&Number.isNaN(e.Pr))}}function Eo(e,i,s,t){let a=e.createContext(1,i,s),o=(Co("Data must be an object, but it was:",a,t),[]),u=Ui.empty();$n(t,(e,t)=>{var r=Do(i,e,s),n=(t=se(t),a.childContextForFieldPath(r));if(t instanceof go)o.push(r);else{let e=So(t,n);null!=e&&(o.push(r),u.set(r,e))}});var r=new Hn(o);return new uo(u,r,a.fieldTransforms)}function To(e,t,r,n,i,s){var a=e.createContext(1,t,r),o=[xo(t,n,r)],u=[i];if(s.length%2!=0)throw new E(_.INVALID_ARGUMENT,`Function ${t}() needs to be called with an even number of arguments that alternate between field names and values.`);for(let p=0;p<s.length;p+=2)o.push(xo(t,s[p])),u.push(s[p+1]);var l=[],h=Ui.empty();for(let f=o.length-1;0<=f;--f)if(!Ro(l,o[f])){let t=o[f];var c=se(u[f]);let r=a.childContextForFieldPath(t);if(c instanceof go)l.push(t);else{let e=So(c,r);null!=e&&(l.push(t),h.set(t,e))}}var d=new Hn(l);return new uo(h,d,a.fieldTransforms)}function bo(e,t,r,n=!1){return So(r,e.createContext(n?4:3,t))}function So(e,r,t){if(Ao(e=se(e)))return Co("Unsupported field value:",r,e),Io(e,r);if(e instanceof _1){{var n=e;var i=r;if(!lo(i.dataSource))throw i.createError(n._methodName+"() can only be used with update() and set()");if(!i.path)throw i.createError(n._methodName+"() is not currently supported inside arrays");var s=n._toFieldTransform(i);s&&i.fieldTransforms.push(s)}return null}if(void 0===e&&r.ignoreUndefinedProperties)return null;if(r.path&&r.fieldMask.push(r.path),e instanceof Array){if(r.settings.arrayElement&&4!==r.dataSource)throw r.createError("Nested arrays are not supported");{var a,o=r,u=[];let t=0;for(a of e){let e=So(a,o.childContextForArray(t));null==e&&(e={nullValue:"NULL_VALUE"}),u.push(e),t++}return{arrayValue:{values:u}}}}var l,n=e,i=r,h=t;if(null===(n=se(n)))return{nullValue:"NULL_VALUE"};if("number"==typeof n)return Gi(i.serializer,n,h);if("boolean"==typeof n)return{booleanValue:n};if("string"==typeof n)return{stringValue:n};if(n instanceof Date){let e=w.fromDate(n);return{timestampValue:Ua(i.serializer,e)}}if(n instanceof w){let e=new w(n.seconds,1e3*Math.floor(n.nanoseconds/1e3));return{timestampValue:Ua(i.serializer,e)}}if(n instanceof E1)return{geoPointValue:{latitude:n.latitude,longitude:n.longitude}};if(n instanceof y1)return{bytesValue:qa(i.serializer,n._byteString)};if(n instanceof F){let e=i.databaseId,t=n.firestore._databaseId;if(t.isEqual(e))return{referenceValue:za(n.firestore._databaseId||i.databaseId,n._key.path)};throw i.createError(`Document reference is for database ${t.projectId}/${t.database} but should be for database ${e.projectId}/`+e.database)}if(n instanceof so)return l=i,s=(h=n)instanceof so?h.toArray():h,{mapValue:{fields:{[li]:{stringValue:di},[pi]:{arrayValue:{values:s.map(e=>{if("number"!=typeof e)throw l.createError("VectorValues must only contain numeric values.");return Bi(l.serializer,e)})}}}}};if(f1(n))return n._toProto(i.serializer);throw i.createError("Unsupported field value: "+Vt(n))}function Io(e,n){let i={};return Qn(e)?n.path&&0<n.path.length&&n.fieldMask.push(n.path):$n(e,(e,t)=>{var r=So(t,n.childContextForField(e));null!=r&&(i[e]=r)}),{mapValue:{fields:i}}}function Ao(e){return!("object"!=typeof e||null===e||e instanceof Array||e instanceof Date||e instanceof w||e instanceof E1||e instanceof y1||e instanceof F||e instanceof _1||e instanceof so||f1(e))}function Co(e,t,r){var n;if(!Ao(r)||!Mt(r))throw"an object"===(n=Vt(r))?t.createError(e+" a custom object"):t.createError(e+" "+n)}function xo(e,t,r){if((t=se(t))instanceof w1)return t._internalPath;if("string"==typeof t)return Do(e,t);throw Oo("Field path arguments must be of type string or ",e,!1,void 0,r)}let No=new RegExp("[~\\*/\\[\\]]");function Do(t,r,n){if(0<=r.search(No))throw Oo(`Invalid field path (${r}). Paths must not contain '~', '*', '/', '[', or ']'`,t,!1,void 0,n);try{return new w1(...r.split("."))._internalPath}catch(e){throw Oo(`Invalid field path (${r}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,t,!1,void 0,n)}}function Oo(e,t,r,n,i){var s=n&&!n.isEmpty(),a=void 0!==i;let o=`Function ${t}() called with invalid data`,u=(r&&(o+=" (via `toFirestore()`)"),o+=". ","");return(s||a)&&(u+=" (found",s&&(u+=" in field "+n),a&&(u+=" in document "+i),u+=")"),new E(_.INVALID_ARGUMENT,o+e+u)}function Ro(e,t){return e.some(e=>e.isEqual(t))}function ko(e){return"function"==typeof e._readUserData}class Lo{constructor(e){this.optionDefinitions=e}_getKnownOptions(t,r){var n,i=Ui.empty();for(n in this.optionDefinitions)if(this.optionDefinitions.hasOwnProperty(n)){var s=this.optionDefinitions[n];if(n in t){var a=t[n];let e;s.nestedOptions&&Mt(a)?e={mapValue:{fields:new Lo(s.nestedOptions).getOptionsProto(r,a)}}:a&&(e=So(a,r)??void 0),e&&i.set(h.fromServerFormat(s.serverName),e)}}return i}getOptionsProto(r,e,t){var n=this._getKnownOptions(e,r);if(t){let e=new Map(((e,t)=>{var r,n=[];for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.push(t(e[r],r,e));return n})(t,(e,t)=>[h.fromServerFormat(t),void 0!==e?So(e,r):null]));n.setAll(e)}return n.value.mapValue.fields??{}}}function i(e){return e instanceof Vo?e:Mt(e)?(e=>{var t,r=[];for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t=e[n],r.push(Ho(n)),r.push(i(t)));return new s("map",r,"map")})(e):e instanceof Array?((e,t)=>new s("array",e.map(e=>i(e)),t))(e,"array"):Ko(e,void 0)}function Po(e){if(e instanceof Vo)return e;if(e instanceof so)return Ho(e);if(Array.isArray(e))return Ho((t=e,new so(t)));var t;throw new Error("Unsupported value: "+typeof e)}function Mo(e){return("string"==typeof e?jo:i)(e)}class Vo{constructor(){this._protoValueType="ProtoValue"}add(e){return new s("add",[this,i(e)],"add")}asBoolean(){if(this instanceof $o)return this;if(this instanceof zo)return new Yo(this);if(this instanceof Go)return new Wo(this);if(this instanceof s)return new Qo(this);throw new E("invalid-argument",`Conversion of type ${typeof this} to BooleanExpression not supported.`)}subtract(e){return new s("subtract",[this,i(e)],"subtract")}multiply(e){return new s("multiply",[this,i(e)],"multiply")}divide(e){return new s("divide",[this,i(e)],"divide")}mod(e){return new s("mod",[this,i(e)],"mod")}equal(e){return new s("equal",[this,i(e)],"equal").asBoolean()}notEqual(e){return new s("not_equal",[this,i(e)],"notEqual").asBoolean()}lessThan(e){return new s("less_than",[this,i(e)],"lessThan").asBoolean()}lessThanOrEqual(e){return new s("less_than_or_equal",[this,i(e)],"lessThanOrEqual").asBoolean()}greaterThan(e){return new s("greater_than",[this,i(e)],"greaterThan").asBoolean()}greaterThanOrEqual(e){return new s("greater_than_or_equal",[this,i(e)],"greaterThanOrEqual").asBoolean()}arrayConcat(e,...t){var r=[e,...t].map(e=>i(e));return new s("array_concat",[this,...r],"arrayConcat")}arrayContains(e){return new s("array_contains",[this,i(e)],"arrayContains").asBoolean()}arrayContainsAll(e){var t=Array.isArray(e)?new qo(e.map(i),"arrayContainsAll"):e;return new s("array_contains_all",[this,t],"arrayContainsAll").asBoolean()}arrayContainsAny(e){var t=Array.isArray(e)?new qo(e.map(i),"arrayContainsAny"):e;return new s("array_contains_any",[this,t],"arrayContainsAny").asBoolean()}arrayReverse(){return new s("array_reverse",[this])}arrayLength(){return new s("array_length",[this],"arrayLength")}equalAny(e){var t=Array.isArray(e)?new qo(e.map(i),"equalAny"):e;return new s("equal_any",[this,t],"equalAny").asBoolean()}notEqualAny(e){var t=Array.isArray(e)?new qo(e.map(i),"notEqualAny"):e;return new s("not_equal_any",[this,t],"notEqualAny").asBoolean()}exists(){return new s("exists",[this],"exists").asBoolean()}charLength(){return new s("char_length",[this],"charLength")}like(e){return new s("like",[this,i(e)],"like").asBoolean()}regexContains(e){return new s("regex_contains",[this,i(e)],"regexContains").asBoolean()}regexFind(e){return new s("regex_find",[this,i(e)],"regexFind")}regexFindAll(e){return new s("regex_find_all",[this,i(e)],"regexFindAll")}regexMatch(e){return new s("regex_match",[this,i(e)],"regexMatch").asBoolean()}stringContains(e){return new s("string_contains",[this,i(e)],"stringContains").asBoolean()}startsWith(e){return new s("starts_with",[this,i(e)],"startsWith").asBoolean()}endsWith(e){return new s("ends_with",[this,i(e)],"endsWith").asBoolean()}toLower(){return new s("to_lower",[this],"toLower")}toUpper(){return new s("to_upper",[this],"toUpper")}trim(e){var t=[this];return e&&t.push(i(e)),new s("trim",t,"trim")}ltrim(e){var t=[this];return e&&t.push(i(e)),new s("ltrim",t,"ltrim")}rtrim(e){var t=[this];return e&&t.push(i(e)),new s("rtrim",t,"rtrim")}type(){return new s("type",[this])}isType(e){return new s("is_type",[this,Ho(e)],"isType").asBoolean()}stringConcat(e,...t){var r=[e,...t].map(i);return new s("string_concat",[this,...r],"stringConcat")}stringIndexOf(e){return new s("string_index_of",[this,i(e)],"stringIndexOf")}stringRepeat(e){return new s("string_repeat",[this,i(e)],"stringRepeat")}stringReplaceAll(e,t){return new s("string_replace_all",[this,i(e),i(t)],"stringReplaceAll")}stringReplaceOne(e,t){return new s("string_replace_one",[this,i(e),i(t)],"stringReplaceOne")}concat(e,...t){var r=[e,...t].map(i);return new s("concat",[this,...r],"concat")}reverse(){return new s("reverse",[this],"reverse")}arrayFilter(e,t){return new s("array_filter",[this,i(e),t],"arrayFilter")}arrayTransform(e,t){return new s("array_transform",[this,i(e),t],"arrayTransform")}arrayTransformWithIndex(e,t,r){return new s("array_transform",[this,i(e),i(t),r],"arrayTransformWithIndex")}arraySlice(e,t){var r=[this,i(e)];return void 0!==t&&r.push(i(t)),new s("array_slice",r,"arraySlice")}arrayFirst(){return new s("array_first",[this],"arrayFirst")}arrayFirstN(e){return new s("array_first_n",[this,i(e)],"arrayFirstN")}arrayLast(){return new s("array_last",[this],"arrayLast")}arrayLastN(e){return new s("array_last_n",[this,i(e)],"arrayLastN")}arrayMaximum(){return new s("maximum",[this],"arrayMaximum")}arrayMaximumN(e){return new s("maximum_n",[this,i(e)],"arrayMaximumN")}arrayMinimum(){return new s("minimum",[this],"arrayMinimum")}arrayMinimumN(e){return new s("minimum_n",[this,i(e)],"arrayMinimumN")}arrayIndexOf(e){return new s("array_index_of",[this,i(e),i("first")],"arrayIndexOf")}arrayLastIndexOf(e){return new s("array_index_of",[this,i(e),i("last")],"arrayLastIndexOf")}arrayIndexOfAll(e){return new s("array_index_of_all",[this,i(e)],"arrayIndexOfAll")}byteLength(){return new s("byte_length",[this],"byteLength")}ceil(){return new s("ceil",[this])}floor(){return new s("floor",[this])}abs(){return new s("abs",[this])}exp(){return new s("exp",[this])}mapGet(e){return new s("map_get",[this,Ho(e)],"mapGet")}mapSet(e,t,...r){var n=[this,i(e),i(t),...r.map(i)];return new s("map_set",n,"mapSet")}mapKeys(){return new s("map_keys",[this],"mapKeys")}mapValues(){return new s("map_values",[this],"mapValues")}mapEntries(){return new s("map_entries",[this],"mapEntries")}getField(e){return new s("get_field",[this,i(e)],"get_field")}count(){return Fo._create("count",[this],"count")}sum(){return Fo._create("sum",[this],"sum")}average(){return Fo._create("average",[this],"average")}minimum(){return Fo._create("minimum",[this],"minimum")}maximum(){return Fo._create("maximum",[this],"maximum")}first(){return Fo._create("first",[this],"first")}last(){return Fo._create("last",[this],"last")}arrayAgg(){return Fo._create("array_agg",[this],"arrayAgg")}arrayAggDistinct(){return Fo._create("array_agg_distinct",[this],"arrayAggDistinct")}countDistinct(){return Fo._create("count_distinct",[this],"countDistinct")}logicalMaximum(e,...t){var r=[e,...t];return new s("maximum",[this,...r.map(i)],"logicalMaximum")}logicalMinimum(e,...t){var r=[e,...t];return new s("minimum",[this,...r.map(i)],"minimum")}vectorLength(){return new s("vector_length",[this],"vectorLength")}cosineDistance(e){return new s("cosine_distance",[this,Po(e)],"cosineDistance")}dotProduct(e){return new s("dot_product",[this,Po(e)],"dotProduct")}euclideanDistance(e){return new s("euclidean_distance",[this,Po(e)],"euclideanDistance")}unixMicrosToTimestamp(){return new s("unix_micros_to_timestamp",[this],"unixMicrosToTimestamp")}timestampToUnixMicros(){return new s("timestamp_to_unix_micros",[this],"timestampToUnixMicros")}unixMillisToTimestamp(){return new s("unix_millis_to_timestamp",[this],"unixMillisToTimestamp")}timestampToUnixMillis(){return new s("timestamp_to_unix_millis",[this],"timestampToUnixMillis")}unixSecondsToTimestamp(){return new s("unix_seconds_to_timestamp",[this],"unixSecondsToTimestamp")}timestampToUnixSeconds(){return new s("timestamp_to_unix_seconds",[this],"timestampToUnixSeconds")}timestampAdd(e,t){return new s("timestamp_add",[this,i(e),i(t)],"timestampAdd")}timestampSubtract(e,t){return new s("timestamp_subtract",[this,i(e),i(t)],"timestampSubtract")}timestampDiff(e,t){return new s("timestamp_diff",[this,Mo(e),i(t)],"timestampDiff")}timestampExtract(e,t){var r=[this,i(e)];return t&&r.push(i(t)),new s("timestamp_extract",r,"timestampExtract")}documentId(){return new s("document_id",[this],"documentId")}parent(){return new s("parent",[this],"parent")}substring(e,t){var r=i(e);return new s("substring",void 0===t?[this,r]:[this,r,i(t)],"substring")}arrayGet(e){return new s("array_get",[this,i(e)],"arrayGet")}isError(){return new s("is_error",[this],"isError").asBoolean()}ifError(e){var t=new s("if_error",[this,i(e)],"ifError");return e instanceof $o?t.asBoolean():t}isAbsent(){return new s("is_absent",[this],"isAbsent").asBoolean()}mapRemove(e){return new s("map_remove",[this,i(e)],"mapRemove")}mapMerge(e,...t){var r=i(e),n=t.map(i);return new s("map_merge",[this,r,...n],"mapMerge")}pow(e){return new s("pow",[this,i(e)])}trunc(e){return void 0===e?new s("trunc",[this]):new s("trunc",[this,i(e)],"trunc")}round(e){return void 0===e?new s("round",[this]):new s("round",[this,i(e)],"round")}collectionId(){return new s("collection_id",[this])}length(){return new s("length",[this])}ln(){return new s("ln",[this])}sqrt(){return new s("sqrt",[this])}stringReverse(){return new s("string_reverse",[this])}ifAbsent(e){return new s("if_absent",[this,i(e)],"ifAbsent")}ifNull(e){return new s("if_null",[this,i(e)],"ifNull")}coalesce(e,...t){return new s("coalesce",[this,i(e),...t.map(i)],"coalesce")}join(e){return new s("join",[this,i(e)],"join")}log10(){return new s("log10",[this])}arraySum(){return new s("sum",[this])}split(e){return new s("split",[this,i(e)])}timestampTruncate(e,t){var r=[this,i(e)];return t&&r.push(i(t)),new s("timestamp_trunc",r)}ascending(){return new Xo(Mo(this),"ascending","ascending")}descending(){return new Xo(Mo(this),"descending","descending")}as(e){return new Bo(this,e,"as")}}class Fo{constructor(e,t){this.name=e,this.params=t,this.exprType="AggregateFunction",this._protoValueType="ProtoValue"}static _create(e,t,r){var n=new Fo(e,t);return n._methodName=r,n}as(e){return new Uo(this,e,"as")}_toProto(t){return{functionValue:{name:this.name,args:this.params.map(e=>e._toProto(t))}}}_readUserData(t){t=this._methodName?t.contextWith({methodName:this._methodName}):t,this.params.forEach(e=>e._readUserData(t))}}class Uo{constructor(e,t,r){this.aggregate=e,this.alias=t,this._methodName=r}_readUserData(e){this.aggregate._readUserData(e)}}class Bo{constructor(e,t,r){this.expr=e,this.alias=t,this._methodName=r,this.exprType="AliasedExpression",this.selectable=!0}_readUserData(e){this.expr._readUserData(e)}}class qo extends Vo{constructor(e,t){super(),this.Rr=e,this._methodName=t,this.expressionType="ListOfExpressions"}_toProto(t){return{arrayValue:{values:this.Rr.map(e=>e._toProto(t))}}}_readUserData(t){this.Rr.forEach(e=>e._readUserData(t))}}class Go extends Vo{constructor(e,t){super(),this.fieldPath=e,this._methodName=t,this.expressionType="Field",this.selectable=!0}get _fieldPath(){return this.fieldPath}get fieldName(){return this.fieldPath.canonicalString()}get alias(){return this.fieldName}get expr(){return this}geoDistance(e){return new s("geo_distance",[this,i(e)],"geoDistance")}_toProto(e){return{fieldReferenceValue:this.fieldPath.canonicalString()}}_readUserData(e){}}function jo(e){return e=e,t="field",new Go("string"==typeof e?Nt===e?new w1(Nt)._internalPath:xo("field",e):e._internalPath,t);var t}class zo extends Vo{constructor(e,t){super(),this.value=e,this._methodName=t,this.expressionType="Constant"}static _fromProto(e){var t=new zo(e,void 0);return t._protoValue=e,t}_toProto(e){return v(void 0!==this._protoValue,237),this._protoValue}_getValue(){return this._protoValue}_readUserData(e){var t,r,n,i;e=this._methodName?e.contextWith({methodName:this._methodName}):e,"object"==typeof(t=this._protoValue)&&null!==t&&("nullValue"in t&&(null===t.nullValue||"NULL_VALUE"===t.nullValue)||"booleanValue"in t&&(null===t.booleanValue||"boolean"==typeof t.booleanValue)||"integerValue"in t&&(null===t.integerValue||"number"==typeof t.integerValue||"string"==typeof t.integerValue)||"doubleValue"in t&&(null===t.doubleValue||"number"==typeof t.doubleValue)||"timestampValue"in t&&(null===t.timestampValue||"object"==typeof(i=t.timestampValue)&&null!==i&&"seconds"in i&&(null===i.seconds||"number"==typeof i.seconds||"string"==typeof i.seconds)&&"nanos"in i&&(null===i.nanos||"number"==typeof i.nanos))||"stringValue"in t&&(null===t.stringValue||"string"==typeof t.stringValue)||"bytesValue"in t&&(null===t.bytesValue||t.bytesValue instanceof Uint8Array)||"referenceValue"in t&&(null===t.referenceValue||"string"==typeof t.referenceValue)||"geoPointValue"in t&&(null===t.geoPointValue||"object"==typeof(i=t.geoPointValue)&&null!==i&&"latitude"in i&&(null===i.latitude||"number"==typeof i.latitude)&&"longitude"in i&&(null===i.longitude||"number"==typeof i.longitude))||"arrayValue"in t&&(null===t.arrayValue||"object"==typeof(n=t.arrayValue)&&null!==n&&"values"in n&&(null===n.values||Array.isArray(n.values)))||"mapValue"in t&&(null===t.mapValue||"object"==typeof(n=t.mapValue)&&null!==n&&"fields"in n&&(null===n.fields||Mt(n.fields)))||"fieldReferenceValue"in t&&(null===t.fieldReferenceValue||"string"==typeof t.fieldReferenceValue)||"functionValue"in t&&(null===t.functionValue||"object"==typeof(r=t.functionValue)&&null!==r&&"name"in r&&(null===r.name||"string"==typeof r.name)&&"args"in r&&(null===r.args||Array.isArray(r.args)))||"pipelineValue"in t&&(null===t.pipelineValue||"object"==typeof(r=t.pipelineValue)&&null!==r&&"stages"in r&&(null===r.stages||Array.isArray(r.stages))))||(this._protoValue=So(this.value,e))}}function Ho(e){return Ko(e,"constant")}function Ko(e,t){var r=new zo(e,t);return"boolean"==typeof e?new Yo(r):r}class s extends Vo{constructor(e,t,r,n){super(),this.name=e,this.params=t,this.expressionType="Function",(this._optionsProto=void 0)!==r&&(this._methodName=r),void 0!==n&&(this._options=n)}get _optionsUtil(){return new Lo({})}_toProto(t){var e={functionValue:{name:this.name,args:this.params.map(e=>e._toProto(t))}};return this._optionsProto&&(e.functionValue.options=this._optionsProto),e}_readUserData(t){t=this._methodName?t.contextWith({methodName:this._methodName}):t,this.params.forEach(e=>e._readUserData(t)),this._options&&(this._optionsProto=this._optionsUtil.getOptionsProto(t,this._options))}}class $o extends Vo{get _methodName(){return this._expr._methodName}countIf(){return Fo._create("count_if",[this],"countIf")}not(){return new s("not",[this],"not").asBoolean()}conditional(e,t){return new s("conditional",[this,e,t],"conditional")}ifError(e){var t=i(e),r=new s("if_error",[this,t],"ifError");return t instanceof $o?r.asBoolean():r}_toProto(e){return this._expr._toProto(e)}_readUserData(e){this._expr._readUserData(e)}}class Qo extends $o{constructor(e){super(),this._expr=e,this.expressionType="Function"}}class Yo extends $o{constructor(e){super(),this._expr=e,this.expressionType="Constant"}_getValue(){return this._expr._getValue()}}class Wo extends $o{constructor(e){super(),this._expr=e,this.expressionType="Field"}}class Xo{constructor(e,t,r){this.expr=e,this.direction=t,this._methodName=r,this._protoValueType="ProtoValue"}_toProto(e){return{mapValue:{fields:{direction:m1(this.direction),expression:this.expr._toProto(e)}}}}_readUserData(e){this.expr._readUserData(e)}}class Jo{constructor(e){this.optionsProto=void 0,{rawOptions:this.rawOptions,...this.knownOptions}=e}_readUserData(e){this.optionsProto=this._optionsUtil.getOptionsProto(e,this.knownOptions,this.rawOptions)}_toProto(e){return{name:this._name,options:this.optionsProto}}}class Zo extends Jo{get _name(){return"add_fields"}get _optionsUtil(){return new Lo({})}constructor(e,t){super(t),this.fields=e}_toProto(e){return{...super._toProto(e),args:[g1(e,this.fields)]}}_readUserData(e){super._readUserData(e),cu(this.fields,e)}}class eu extends Jo{get _name(){return"aggregate"}get _optionsUtil(){return new Lo({})}constructor(e,t,r){super(r),this.groups=e,this.accumulators=t}_toProto(e){return{...super._toProto(e),args:[g1(e,this.accumulators),g1(e,this.groups)]}}_readUserData(e){super._readUserData(e),cu(this.groups,e),cu(this.accumulators,e)}}class tu extends Jo{get _name(){return"distinct"}get _optionsUtil(){return new Lo({})}constructor(e,t){super(t),this.groups=e}_toProto(e){return{...super._toProto(e),args:[g1(e,this.groups)]}}_readUserData(e){super._readUserData(e),cu(this.groups,e)}}class ru extends Jo{get _name(){return"collection"}get _optionsUtil(){return new Lo({forceIndex:{serverName:"force_index"}})}constructor(e,t){super(t),this.Vr=e.startsWith("/")?e:"/"+e}_toProto(e){return{...super._toProto(e),args:[{referenceValue:this.Vr}]}}_readUserData(e){super._readUserData(e)}}class nu extends Jo{get _name(){return"collection_group"}get _optionsUtil(){return new Lo({forceIndex:{serverName:"force_index"}})}constructor(e,t){super(t),this.collectionId=e}_toProto(e){return{...super._toProto(e),args:[{referenceValue:""},{stringValue:this.collectionId}]}}_readUserData(e){super._readUserData(e)}}class iu extends Jo{get _name(){return"database"}get _optionsUtil(){return new Lo({})}_toProto(e){return{...super._toProto(e)}}_readUserData(e){super._readUserData(e)}}class su extends Jo{get _name(){return"documents"}get _optionsUtil(){return new Lo({})}constructor(e,t){if(super(t),!e||0===e.length)throw new E(_.INVALID_ARGUMENT,"Empty document paths are not allowed in DocumentsSource");var r=e.map(e=>e.startsWith("/")?e:"/"+e),n=new Set(r);if(n.size!==r.length)throw new E(_.INVALID_ARGUMENT,"Duplicate document paths are not allowed in DocumentsSource");this.dr=r,this.mr=n}_toProto(e){return{...super._toProto(e),args:this.dr.map(e=>({referenceValue:e}))}}_readUserData(e){super._readUserData(e)}}class au extends Jo{get _name(){return"where"}get _optionsUtil(){return new Lo({})}constructor(e,t){super(t),this.condition=e}_toProto(e){return{...super._toProto(e),args:[this.condition._toProto(e)]}}_readUserData(e){super._readUserData(e),cu(this.condition,e)}}class ou extends Jo{get _name(){return"limit"}get _optionsUtil(){return new Lo({})}constructor(e,t){v(!isNaN(e)&&e!==1/0&&e!==-1/0,34860),super(t),this.limit=e}_toProto(e){return{...super._toProto(e),args:[Gi(e,this.limit)]}}}class uu extends Jo{get _name(){return"select"}get _optionsUtil(){return new Lo({})}constructor(e,t){super(t),this.selections=e}_toProto(e){return{...super._toProto(e),args:[g1(e,this.selections)]}}_readUserData(e){super._readUserData(e),cu(this.selections,e)}}class lu extends Jo{get _name(){return"sort"}get _optionsUtil(){return new Lo({})}constructor(e,t){super(t),this.orderings=e}_toProto(t){return{...super._toProto(t),args:this.orderings.map(e=>e._toProto(t))}}_readUserData(e){super._readUserData(e),cu(this.orderings,e)}}class hu extends Jo{get _name(){return"replace_with"}get _optionsUtil(){return new Lo({})}constructor(e,t){super(t),this.map=e}_toProto(e){return{...super._toProto(e),args:[this.map._toProto(e),m1(hu.pr)]}}_readUserData(e){super._readUserData(e),cu(this.map,e)}}function cu(e,t){ko(e)?e._readUserData(t):Array.isArray(e)?e.forEach(e=>e._readUserData(t)):e instanceof Map?e.forEach(e=>e._readUserData(t)):Object.values(e).forEach(e=>e._readUserData(t))}hu.pr="full_replace";class du{constructor(e,t,r){this.serializer=e,this.stages=t,this.listenOptions=r,this.isCorePipeline=!0}getPipelineCollection(){return fu(this)}getPipelineCollectionGroup(){return gu(this)}getPipelineCollectionId(){return mu(this)}getPipelineDocuments(){return vu(this)}getPipelineFlavor(){{var n=this;let r="exact";return n.stages.forEach((e,t)=>{e._name!==tu.name&&e._name!==eu.name||(r="keyless"),e._name===uu.name&&"exact"===r&&(r="augmented"),e._name===Zo.name&&t<n.stages.length-1&&"exact"===r&&(r="augmented")}),r}}getPipelineSourceType(){return pu(this)}}function pu(e){var t=e.stages[0];return t instanceof ru||t instanceof nu||t instanceof iu||t instanceof su?t._name:"unknown"}function fu(e){if("collection"===pu(e))return e.stages[0].Vr}function gu(e){if("collection_group"===pu(e))return e.stages[0].collectionId}function mu(e){switch(pu(e)){case"collection":return T.fromString(fu(e)).lastSegment();case"collection_group":return gu(e);default:return}}function vu(e){if("documents"===pu(e))return e.stages[0].dr}class l{constructor(e,t){this.type=e,this.value=t}static vr(){return new l("ERROR",void 0)}static Sr(){return new l("UNSET",void 0)}static Dr(){return new l("NULL",fi)}static newValue(e){return Ni(e)?new l("NULL",fi):(t=e)&&"booleanValue"in t?new l("BOOLEAN",e):Ii(e)?new l("INT",e):Ai(e)?new l("DOUBLE",e):(t=e)&&"timestampValue"in t&&t.timestampValue?new l("TIMESTAMP",e):(t=e)&&"stringValue"in t?new l("STRING",e):(t=e)&&"bytesValue"in t?new l("BYTES",e):e.referenceValue?new l("REFERENCE",e):e.geoPointValue?new l("GEO_POINT",e):xi(e)?new l("ARRAY",e):Ri(e)?new l("VECTOR",e):Oi(e)?new l("MAP",e):new l("ERROR",void 0);var t}Cr(){return"ERROR"===this.type||"UNSET"===this.type}Fr(){return"NULL"===this.type}}function yu(e){if(!e.Cr())return e.value}function wu(e){return e instanceof $o?e._expr:e}function U(e){if((e=wu(e))instanceof Go)return new _u(e);if(e instanceof zo)return new Eu(e);if(e instanceof qo)return new Tu(e);if(e instanceof s){if("add"===e.name)return new Nu(e);if("subtract"===e.name)return new Du(e);if("multiply"===e.name)return new Ou(e);if("divide"===e.name)return new Ru(e);if("mod"===e.name)return new ku(e);if("and"===e.name)return new Lu(e);if("equal"===e.name)return new Wu(e);if("not_equal"===e.name)return new Xu(e);if("less_than"===e.name)return new Ju(e);if("less_than_or_equal"===e.name)return new Zu(e);if("greater_than"===e.name)return new el(e);if("greater_than_or_equal"===e.name)return new tl(e);if("array_concat"===e.name)return new rl(e);if("array_reverse"===e.name)return new nl(e);if("array_contains"===e.name)return new il(e);if("array_contains_all"===e.name)return new sl(e);if("array_contains_any"===e.name)return new al(e);if("array_length"===e.name)return new ol(e);if("array_element"===e.name)return new ul(e);if("equal_any"===e.name)return new Fu(e);if("not_equal_any"===e.name)return new Uu(e);if("is_nan"===e.name)return new Bu(e);if("is_not_nan"===e.name)return new qu(e);if("is_null"===e.name)return new Gu(e);if("is_not_null"===e.name)return new ju(e);if("is_error"===e.name)return new zu(e);if("exists"===e.name)return new Hu(e);if("not"===e.name)return new Pu(e);if("or"===e.name)return new Mu(e);if("xor"===e.name)return new Vu(e);if("conditional"===e.name)return new Ku(e);if("maximum"===e.name)return new $u(e);if("minimum"===e.name)return new Qu(e);if("reverse"===e.name)return new ll(e);if("replace_first"===e.name)return new hl(e);if("replace_all"===e.name)return new cl(e);if("char_length"===e.name)return new dl(e);if("byte_length"===e.name)return new pl(e);if("like"===e.name)return new gl(e);if("regex_contains"===e.name)return new ml(e);if("regex_match"===e.name)return new vl(e);if("string_contains"===e.name)return new yl(e);if("starts_with"===e.name)return new wl(e);if("ends_with"===e.name)return new _l(e);if("to_lower"===e.name)return new El(e);if("to_upper"===e.name)return new Tl(e);if("trim"===e.name)return new bl(e);if("string_concat"===e.name)return new Sl(e);if("map_get"===e.name)return new Il(e);if("cosine_distance"===e.name)return new Cl(e);if("dot_product"===e.name)return new xl(e);if("euclidean_distance"===e.name)return new Nl(e);if("vector_length"===e.name)return new Dl(e);if("unix_micros_to_timestamp"===e.name)return new Hl(e);if("timestamp_to_unix_micros"===e.name)return new Yl(e);if("unix_millis_to_timestamp"===e.name)return new Kl(e);if("timestamp_to_unix_millis"===e.name)return new Wl(e);if("unix_seconds_to_timestamp"===e.name)return new $l(e);if("timestamp_to_unix_seconds"===e.name)return new Xl(e);if("timestamp_add"===e.name)return new Zl(e);if("timestamp_subtract"===e.name)return new eh(e)}throw new Error("Unknown Expr : "+e)}class _u{constructor(e){this.expr=e}evaluate(e,t){var r;return this.expr.fieldName===Nt?l.newValue({referenceValue:$a(e.serializer,t.key)}):"__update_time__"===this.expr.fieldName?l.newValue({timestampValue:Ga(e.serializer,t.version)}):"__create_time__"===this.expr.fieldName?l.newValue({timestampValue:Ga(e.serializer,t.createTime)}):(r=t.data.field(this.expr._fieldPath))?ni(r)?l.newValue(((e,t)=>{if("estimate"===e.serverTimestampBehavior)return{timestampValue:Ga(e.serializer,N.fromTimestamp(si(t)))};if("previous"===e.serverTimestampBehavior){let e=ii(t);if(e)return e}return{nullValue:"NULL_VALUE"}})(e,r)):l.newValue(r):l.Sr()}}class Eu{constructor(e){this.expr=e}evaluate(e,t){return l.newValue(this.expr._getValue())}}class Tu{constructor(e){this.expr=e}evaluate(t,r){var e=this.expr.Rr.map(e=>U(e).evaluate(t,r));return e.some(e=>e.Cr())?l.vr():l.newValue({arrayValue:{values:e.map(e=>e.value)}})}}function bu(e){return Ai(e)?Number(e.doubleValue):Number(e.integerValue)}function Su(e){return BigInt(e.integerValue)}let Iu=BigInt("0x7fffffffffffffff"),Au=-BigInt("0x8000000000000000");class Cu{constructor(e){this.expr=e}evaluate(t,r){v(2<=this.expr.params.length,24778);let n=U(this.expr.params[0]).evaluate(t,r),e=U(this.expr.params[1]).evaluate(t,r),i=this.Or(n,e);for(let n of this.expr.params.slice(2)){let e=U(n).evaluate(t,r);i=this.Or(i,e)}return i}Or(e,t){if(!e.Cr()&&!t.Cr()){if(e.Fr()||t.Fr())return l.Dr();var r=e.value,n=t.value;if((Ai(r)||Ii(r))&&(Ai(n)||Ii(n))){if(Ai(r)||Ai(n)){let e=this.Mr(r,n);return e?l.newValue(e):l.vr()}if(Ii(r)&&Ii(n)){let e=this.Nr(r,n);return void 0===e?l.vr():"number"==typeof e?l.newValue({doubleValue:e}):e<Au||e>Iu?l.vr():l.newValue({integerValue:""+e})}}}return l.vr()}}function xu(r,n){{if(vi(r)!==vi(n))return"TYPE_MISMATCH";if(Di(r)||Di(n))return"NOT_EQ";if(Ni(r)&&Ni(n))return"EQ";if(Ni(r)||Ni(n))return"NULL";if(xi(r)&&xi(n)){var i=r.arrayValue,s=n.arrayValue;if(i.values?.length!==s.values?.length)return"NOT_EQ";let e=!1;for(let t=0;t<(i.values?.length??0);t++){var a=i.values[t],o=s.values[t];switch(xu(a,o)){case"EQ":break;case"NOT_EQ":case"TYPE_MISMATCH":return"NOT_EQ";case"NULL":e=!0;break;default:A(44609,{Lr:a,Br:o})}}return e?"NULL":"EQ"}if(Ri(r)&&Ri(n)||Oi(r)&&Oi(n)){var u=r.mapValue,l=n.mapValue,h=u.fields||{},c=l.fields||{};if(Kn(h)!==Kn(c))return"NOT_EQ";let e=!1;for(let t in h)if(h.hasOwnProperty(t)){if(void 0===c[t])return"NOT_EQ";switch(xu(h[t],c[t])){case"NOT_EQ":case"TYPE_MISMATCH":return"NOT_EQ";case"NULL":e=!0}}return e?"NULL":"EQ"}return yi(r,n,{Te:!1,Ee:!0,he:!0})?"EQ":"NOT_EQ"}}class Nu extends Cu{Nr(e,t){return Su(e)+Su(t)}Mr(e,t){return{doubleValue:bu(e)+bu(t)}}}class Du extends Cu{constructor(e){super(e),this.expr=e}Nr(e,t){return Su(e)-Su(t)}Mr(e,t){return{doubleValue:bu(e)-bu(t)}}}class Ou extends Cu{constructor(e){super(e),this.expr=e}Nr(e,t){return Su(e)*Su(t)}Mr(e,t){return{doubleValue:bu(e)*bu(t)}}}class Ru extends Cu{constructor(e){super(e),this.expr=e}Nr(e,t){var r=Su(t);if(r!==BigInt(0))return Su(e)/r}Mr(e,t){var r=bu(t);return 0===r?{doubleValue:Cr(r)?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}:{doubleValue:bu(e)/r}}}class ku extends Cu{constructor(e){super(e),this.expr=e}Nr(e,t){var r=Su(t);if(r!==BigInt(0))return Su(e)%r}Mr(e,t){var r=bu(t);if(0!==r)return{doubleValue:bu(e)%r}}}class Lu{constructor(e){this.expr=e}evaluate(e,t){let r=!1,n=!1;for(var i of this.expr.params){var s=U(i).evaluate(e,t);switch(s.type){case"BOOLEAN":if(s.value?.booleanValue)break;return l.newValue(mi);case"NULL":n=!0;break;default:r=!0}}return r?l.vr():n?l.Dr():l.newValue(gi)}}class Pu{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,9634);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"BOOLEAN":return l.newValue({booleanValue:!r.value?.booleanValue});case"NULL":return l.Dr();default:return l.vr()}}}class Mu{constructor(e){this.expr=e}evaluate(e,t){let r=!1,n=!1;for(var i of this.expr.params){var s=U(i).evaluate(e,t);switch(s.type){case"BOOLEAN":if(s.value?.booleanValue)return l.newValue(gi);break;case"NULL":n=!0;break;default:r=!0}}return r?l.vr():n?l.Dr():l.newValue(mi)}}class Vu{constructor(e){this.expr=e}evaluate(e,t){let r=!1,n=!1;for(var i of this.expr.params){var s=U(i).evaluate(e,t);switch(s.type){case"BOOLEAN":r=Vu.xor(r,!!s.value?.booleanValue);break;case"NULL":n=!0;break;default:return l.vr()}}return n?l.Dr():l.newValue({booleanValue:r})}static xor(e,t){return(e||t)&&!(e&&t)}}class Fu{constructor(e){this.expr=e}evaluate(e,t){v(2===this.expr.params.length,55094);let r=!1;var n=U(this.expr.params[0]).evaluate(e,t);switch(n.type){case"NULL":r=!0;break;case"ERROR":case"UNSET":return l.vr()}var i=U(this.expr.params[1]).evaluate(e,t);switch(i.type){case"ARRAY":break;case"NULL":r=!0;break;default:return l.vr()}if(r)return l.Dr();for(let e of i.value?.arrayValue?.values??[])switch(Ni(n.value)&&Ni(e)?"EQ":xu(n.value,e)){case"EQ":return l.newValue(gi);case"NOT_EQ":case"TYPE_MISMATCH":break;case"NULL":r=!0;break;default:A(44608,{value:n.value,candidate:e})}return r?l.Dr():l.newValue(mi)}}class Uu{constructor(e){this.expr=e}evaluate(e,t){return new Pu(new s("not",[new s("equal_any",this.expr.params)])).evaluate(e,t)}}class Bu{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,23322);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"INT":return l.newValue(mi);case"DOUBLE":return l.newValue({booleanValue:isNaN(bu(r.value))});case"NULL":return l.Dr();default:return l.vr()}}}class qu{constructor(e){this.expr=e}evaluate(e,t){return v(1===this.expr.params.length,50406),new Pu(new s("not",[new s("is_nan",this.expr.params)])).evaluate(e,t)}}class Gu{constructor(e){this.expr=e}evaluate(e,t){switch(v(1===this.expr.params.length,23123),U(this.expr.params[0]).evaluate(e,t).type){case"NULL":return l.newValue(gi);case"UNSET":case"ERROR":return l.vr();default:return l.newValue(mi)}}}class ju{constructor(e){this.expr=e}evaluate(e,t){return v(1===this.expr.params.length,23167),new Pu(new s("not",[new s("is_null",this.expr.params)])).evaluate(e,t)}}class zu{constructor(e){this.expr=e}evaluate(e,t){return v(1===this.expr.params.length,5228),"ERROR"===U(this.expr.params[0]).evaluate(e,t).type?l.newValue(gi):l.newValue(mi)}}class Hu{constructor(e){this.expr=e}evaluate(e,t){switch(v(1===this.expr.params.length,6877),U(this.expr.params[0]).evaluate(e,t).type){case"ERROR":return l.vr();case"UNSET":return l.newValue(mi);default:return l.newValue(gi)}}}class Ku{constructor(e){this.expr=e}evaluate(e,t){v(3===this.expr.params.length,11706);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"BOOLEAN":return(r.value?.booleanValue?U(this.expr.params[1]):U(this.expr.params[2])).evaluate(e,t);case"NULL":return U(this.expr.params[2]).evaluate(e,t);default:return l.vr()}}}class $u{constructor(e){this.expr=e}evaluate(t,r){var e=this.expr.params.map(e=>U(e).evaluate(t,r));let n;for(let t of e)switch(t.type){case"ERROR":case"UNSET":case"NULL":continue;default:n=void 0===n||0<_i(t.value,n.value)?t:n}return void 0===n?l.Dr():n}}class Qu{constructor(e){this.expr=e}evaluate(t,r){var e=this.expr.params.map(e=>U(e).evaluate(t,r));let n;for(let t of e)switch(t.type){case"ERROR":case"UNSET":case"NULL":continue;default:n=void 0===n||_i(t.value,n.value)<0?t:n}return void 0===n?l.Dr():n}}class Yu{constructor(e){this.expr=e}evaluate(e,t){v(2===this.expr.params.length,31033,this.expr.name+"() function should have exactly 2 params");var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"ERROR":case"UNSET":return l.vr()}var n=U(this.expr.params[1]).evaluate(e,t);switch(n.type){case"ERROR":case"UNSET":return l.vr()}return this.Ur(r,n)}}class Wu extends Yu{constructor(e){super(e),this.expr=e}Ur(e,t){if(e.Fr()&&t.Fr())return l.newValue(gi);if(e.Fr()||t.Fr())return l.newValue(mi);if(Di(e.value)||Di(t.value))return l.newValue(mi);if(vi(e.value)!==vi(t.value))return l.newValue(mi);switch(xu(e.value,t.value)){case"EQ":return l.newValue(gi);case"NOT_EQ":return l.newValue(mi);case"NULL":return l.Dr();default:A(44615,{left:e,right:t})}}}class Xu extends Yu{constructor(e){super(e),this.expr=e}Ur(e,t){switch(xu(e.value,t.value)){case"EQ":return l.newValue(mi);case"NOT_EQ":case"TYPE_MISMATCH":return l.newValue(gi);case"NULL":return l.Dr();default:A(44614,{left:e,right:t})}}}class Ju extends Yu{constructor(e){super(e),this.expr=e}Ur(e,t){return vi(e.value)!==vi(t.value)||Di(e.value)||Di(t.value)?l.newValue(mi):l.newValue({booleanValue:_i(e.value,t.value)<0})}}class Zu extends Yu{constructor(e){super(e),this.expr=e}Ur(e,t){return vi(e.value)!==vi(t.value)||Di(e.value)||Di(t.value)?l.newValue(mi):"EQ"===xu(e.value,t.value)?l.newValue(gi):l.newValue({booleanValue:_i(e.value,t.value)<0})}}class el extends Yu{constructor(e){super(e),this.expr=e}Ur(e,t){return vi(e.value)!==vi(t.value)||Di(e.value)||Di(t.value)?l.newValue(mi):l.newValue({booleanValue:0<_i(e.value,t.value)})}}class tl extends Yu{constructor(e){super(e),this.expr=e}Ur(e,t){return vi(e.value)!==vi(t.value)||Di(e.value)||Di(t.value)?l.newValue(mi):"EQ"===xu(e.value,t.value)?l.newValue(gi):l.newValue({booleanValue:0<_i(e.value,t.value)})}}class rl{constructor(e){this.expr=e}evaluate(e,t){throw new Error("Unimplemented")}}class nl{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,216);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"NULL":return l.Dr();case"ARRAY":{let e=r.value.arrayValue?.values??[];return l.newValue({arrayValue:{values:[...e].reverse()}})}default:return l.vr()}}}class il{constructor(e){this.expr=e}evaluate(e,t){return v(2===this.expr.params.length,52884),new Fu(new s("eq_any",[this.expr.params[1],this.expr.params[0]])).evaluate(e,t)}}class sl{constructor(e){this.expr=e}evaluate(r,e){v(2===this.expr.params.length,1392);let n=!1,t=U(this.expr.params[0]).evaluate(r,e);switch(t.type){case"ARRAY":break;case"NULL":n=!0;break;default:return l.vr()}var i=U(this.expr.params[1]).evaluate(r,e);switch(i.type){case"ARRAY":break;case"NULL":n=!0;break;default:return l.vr()}if(n)return l.Dr();var i=i.value?.arrayValue?.values??[],s=t.value?.arrayValue?.values??[];for(let r of i){let e=!1;n=!1;for(let t of s){switch(Ni(r)&&Ni(t)?"EQ":xu(r,t)){case"EQ":e=!0;break;case"NOT_EQ":case"TYPE_MISMATCH":break;case"NULL":n=!0;break;default:A(44613,{value:t,search:r})}if(e)break}if(!e)return l.newValue(mi)}return l.newValue(gi)}}class al{constructor(e){this.expr=e}evaluate(t,e){v(2===this.expr.params.length,2680);let r=!1;var n=U(this.expr.params[0]).evaluate(t,e);switch(n.type){case"ARRAY":break;case"NULL":r=!0;break;default:return l.vr()}var i=U(this.expr.params[1]).evaluate(t,e);switch(i.type){case"ARRAY":break;case"NULL":r=!0;break;default:return l.vr()}if(r)return l.Dr();var s=i.value?.arrayValue?.values??[];for(let t of n.value?.arrayValue?.values??[])for(let e of s)switch(Ni(t)&&Ni(e)?"EQ":xu(t,e)){case"EQ":return l.newValue(gi);case"NOT_EQ":case"TYPE_MISMATCH":break;case"NULL":r=!0;break;default:A(44608,{value:t,search:e})}return r?l.Dr():l.newValue(mi)}}class ol{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,38605);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"NULL":return l.Dr();case"ARRAY":return l.newValue({integerValue:""+(r.value?.arrayValue?.values?.length??0)});default:return l.vr()}}}class ul{constructor(e){this.expr=e}evaluate(e,t){throw new Error("Unimplemented")}}class ll{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,1508);var n=U(this.expr.params[0]).evaluate(e,t);switch(n.type){case"NULL":return l.Dr();case"BYTES":{let t=n.value?.bytesValue;if("string"!=typeof t)return l.newValue({bytesValue:new Uint8Array(t).reverse()});{let e=k.fromBase64String(t).toUint8Array();return e.reverse(),l.newValue({bytesValue:k.fromUint8Array(e).toBase64()})}}case"STRING":{let e=n.value?.stringValue,t=new Intl.__PRIVATE_Segmenter(void 0,{granularity:"grapheme"}).segment(e),r=Array.from(t,e=>e.segment).reverse();return l.newValue({stringValue:r.join("")})}default:return l.vr()}}}class hl{constructor(e){this.expr=e}evaluate(e,t){throw new Error("Unimplemented")}}class cl{constructor(e){this.expr=e}evaluate(e,t){throw new Error("Unimplemented")}}class dl{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,19400);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"NULL":return l.Dr();case"STRING":{let e=(e=>{let t=0;for(let i=0;i<e.length;i++){var r,n=e.codePointAt(i);if(void 0===n)return;if(n<=65535)55296<=n&&n<=57343&&n<=56319&&void 0!==(r=e.codePointAt(i+1))&&56320<=r&&r<=57343?(t+=1,i++):t+=1;else{if(!(n<=1114111))return;t+=1,i++}}return t})(r.value.stringValue);return void 0===e?l.vr():l.newValue({integerValue:e})}default:return l.vr()}}}class pl{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,8486);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"BYTES":{let e=r.value?.bytesValue;return"string"==typeof e?l.newValue({integerValue:k.fromBase64String(e).toUint8Array().length}):l.newValue({integerValue:new Uint8Array(e).length})}case"STRING":{let e=(e=>{let t=0;for(let i=0;i<e.length;i++){var r=e.codePointAt(i);if(void 0===r)return;if(55296<=r&&r<=57343){if(!(r<=56319))return;var n=e.codePointAt(i+1);if(void 0===n||!(56320<=n&&n<=57343))return;t+=4,i++}else if(r<=127)t+=1;else if(r<=2047)t+=2;else if(r<=65535)t+=3;else{if(!(r<=1114111))return;t+=4,i++}}return t})(r.value?.stringValue);return void 0===e?l.vr():l.newValue({integerValue:e})}case"NULL":return l.Dr();default:return l.vr()}}}class fl{constructor(e){this.expr=e}evaluate(e,t){v(2===this.expr.params.length,39773,this.expr.name+"() function should have exactly two parameters");let r=!1;var n=U(this.expr.params[0]).evaluate(e,t);switch(n.type){case"STRING":break;case"NULL":r=!0;break;default:return l.vr()}var i=U(this.expr.params[1]).evaluate(e,t);switch(i.type){case"STRING":break;case"NULL":r=!0;break;default:return l.vr()}return r?l.Dr():this.kr(n.value?.stringValue,i.value?.stringValue)}}class gl extends fl{kr(e,t){try{var r=(e=>{let t="";for(let n=0;n<e.length;n++){var r=e.charAt(n);switch(r){case"_":t+=".";break;case"%":t+=".*";break;case"\\":case".":case"*":case"?":case"+":case"^":case"$":case"|":case"(":case")":case"[":case"]":case"{":case"}":t+="\\"+r;break;default:t+=r}}return"^"+t+"$"})(t),n=it.compile(r);return l.newValue({booleanValue:n.matches(e)})}catch(e){return ht(`Invalid LIKE pattern converted to regex: ${t}, returning error. Error: `+e),l.vr()}}}class ml extends fl{kr(e,t){try{var r=it.compile(t);return l.newValue({booleanValue:r.matcher(e).find()})}catch(e){return ht(`Invalid regex pattern found in regex_contains: ${t}, returning error`),l.vr()}}}class vl extends fl{kr(e,t){try{return l.newValue({booleanValue:it.compile(t).matches(e)})}catch(e){return ht(`Invalid regex pattern found in regex_match: ${t}, returning error`),l.vr()}}}class yl extends fl{kr(e,t){return l.newValue({booleanValue:e.includes(t)})}}class wl extends fl{kr(e,t){return l.newValue({booleanValue:e.startsWith(t)})}}class _l extends fl{kr(e,t){return l.newValue({booleanValue:e.endsWith(t)})}}class El{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,29079);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"STRING":return l.newValue({stringValue:r.value?.stringValue?.toLowerCase()});case"NULL":return l.Dr();default:return l.vr()}}}class Tl{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,60487);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"STRING":return l.newValue({stringValue:r.value?.stringValue?.toUpperCase()});case"NULL":return l.Dr();default:return l.vr()}}}class bl{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,28544);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"STRING":return l.newValue({stringValue:r.value?.stringValue?.trim()});case"NULL":return l.Dr();default:return l.vr()}}}class Sl{constructor(e){this.expr=e}evaluate(t,r){var e=this.expr.params.map(e=>U(e).evaluate(t,r));let n="",i=!1;for(let t of e)switch(t.type){case"STRING":n+=t.value.stringValue;break;case"NULL":i=!0;break;default:return l.vr()}return i?l.Dr():l.newValue({stringValue:n})}}class Il{constructor(e){this.expr=e}evaluate(e,t){v(2===this.expr.params.length,4483);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"UNSET":return l.Sr();case"MAP":break;default:return l.vr()}var n=U(this.expr.params[1]).evaluate(e,t);return"STRING"!==n.type?l.vr():void 0===(r=r.value?.mapValue?.fields?.[n.value?.stringValue])?l.Sr():l.newValue(r)}}class Al{constructor(e){this.expr=e}evaluate(e,t){v(2===this.expr.params.length,25231,this.expr.name+"() function should have exactly 2 params");let r=!1;var n=U(this.expr.params[0]).evaluate(e,t);switch(n.type){case"VECTOR":break;case"NULL":r=!0;break;default:return l.vr()}var i=U(this.expr.params[1]).evaluate(e,t);switch(i.type){case"VECTOR":break;case"NULL":r=!0;break;default:return l.vr()}return r?l.Dr():(n=ki(n.value),i=ki(i.value),void 0===n||void 0===i||n.values?.length!==i.values?.length||void 0===(n=this.qr(n,i))||isNaN(n)?l.vr():l.newValue({doubleValue:n}))}}class Cl extends Al{qr(e,t){var a=e?.values??[],o=t?.values??[];if(0!==a.length){let r=0,n=0,i=0;for(let s=0;s<a.length;s++){if(!Ci(a[s])||!Ci(o[s]))return;let e=bu(a[s]),t=bu(o[s]);r+=e*t,n+=e*e,i+=t*t}let e=Math.sqrt(n)*Math.sqrt(i);if(0!==e)return 1-Math.max(-1,Math.min(1,r/e))}}}class xl extends Al{qr(e,t){var r=e?.values??[],n=t?.values??[];if(0===r.length)return 0;let i=0;for(let s=0;s<r.length;s++){if(!Ci(r[s])||!Ci(n[s]))return;i+=bu(r[s])*bu(n[s])}return i}}class Nl extends Al{qr(e,t){var r=e?.values??[],n=t?.values??[];if(0===r.length)return 0;let i=0;for(let s=0;s<r.length;s++){if(!Ci(r[s])||!Ci(n[s]))return;let e=bu(r[s]),t=bu(n[s]);i+=Math.pow(e-t,2)}return Math.sqrt(i)}}class Dl{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,39044);var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"VECTOR":{let e=ki(r.value);return l.newValue({integerValue:e?.values?.length??0})}case"NULL":return l.Dr();default:return l.vr()}}}let Ol=BigInt(-62135596800),Rl=BigInt(253402300799),kl=BigInt(1e3),Ll=BigInt(1e6),Pl=Ol*kl,Ml=Rl*kl+BigInt(999),Vl=Ol*Ll,Fl=Rl*Ll+BigInt(999999);function Ul(e){return e>=Vl&&e<=Fl}function Bl(e){return e>=Ol&&e<=Rl}function ql(e,t){var r=BigInt(e);return!(r<Ol||r>Rl||t<0||1e9<=t||r===Ol&&0!==t||r===Rl&&999999999<t)}function Gl(e,t){return t<0?{seconds:e-1,nanos:t+1e9}:{seconds:e,nanos:t}}function jl(e){return BigInt(e.seconds)*Ll+BigInt(Math.trunc(e.nanoseconds/1e3))}class zl{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,49262,this.expr.name+"() function should have exactly one parameter");var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"INT":return this.toTimestamp(BigInt(r.value.integerValue));case"NULL":return l.Dr();default:return l.vr()}}}class Hl extends zl{toTimestamp(e){var t,r;return Ul(e)&&ql(t=(r=Gl(Number(e/Ll),Number(e%Ll*BigInt(1e3)))).seconds,r=r.nanos)?l.newValue({timestampValue:{seconds:t,nanos:r}}):l.vr()}}class Kl extends zl{toTimestamp(e){var t,r,n;return(t=e)>=Pl&&t<=Ml&&ql(r=(n=Gl(Number(e/kl),Number(e%kl*BigInt(1e6)))).seconds,n=n.nanos)?l.newValue({timestampValue:{seconds:r,nanos:n}}):l.vr()}}class $l extends zl{toTimestamp(e){var t;return Bl(e)?(t=Number(e),l.newValue({timestampValue:{seconds:t,nanos:0}})):l.vr()}}class Ql{constructor(e){this.expr=e}evaluate(e,t){v(1===this.expr.params.length,1265,this.expr.name+"() function should have exactly one parameter");var r=U(this.expr.params[0]).evaluate(e,t);switch(r.type){case"TIMESTAMP":break;case"NULL":return l.Dr();default:return l.vr()}r=Ba(r.value.timestampValue);return ql(r.seconds,r.nanoseconds)?this.$r(r):l.vr()}}class Yl extends Ql{$r(e){var t=jl(e);return Ul(t)?l.newValue({integerValue:""+t.toString()}):l.vr()}}class Wl extends Ql{$r(e){var t=jl(e),r=t/BigInt(1e3),t=t%BigInt(1e3);return r>BigInt(0)||t===BigInt(0)?l.newValue({integerValue:r.toString()}):l.newValue({integerValue:(r-BigInt(1)).toString()})}}class Xl extends Ql{$r(e){var t=BigInt(e.seconds);return Bl(t)?l.newValue({integerValue:t.toString()}):l.vr()}}class Jl{constructor(e){this.expr=e}evaluate(e,t){v(3===this.expr.params.length,2775,this.expr.name+"() function should have exactly 3 parameters");let r=!1;var n=U(this.expr.params[0]).evaluate(e,t);switch(n.type){case"TIMESTAMP":break;case"NULL":r=!0;break;default:return l.vr()}var i=U(this.expr.params[1]).evaluate(e,t);let s;switch(i.type){case"STRING":if(void 0===(s=(e=>{switch(e){case"microsecond":return"microsecond";case"millisecond":return"millisecond";case"second":return"second";case"minute":return"minute";case"hour":return"hour";case"day":return"day";default:return}})(i.value.stringValue)))return l.vr();break;case"NULL":r=!0;break;default:return l.vr()}var a=U(this.expr.params[2]).evaluate(e,t);switch(a.type){case"INT":break;case"NULL":r=!0;break;default:return l.vr()}if(r)return l.Dr();var o=BigInt(a.value.integerValue);let u;try{switch(s){case"microsecond":u=o;break;case"millisecond":u=o*BigInt(1e3);break;case"second":u=o*BigInt(1e6);break;case"minute":u=o*BigInt(6e7);break;case"hour":u=o*BigInt(36e8);break;case"day":u=o*BigInt(864e8);break;default:return l.vr()}if("microsecond"!==s&&o!==BigInt(0)&&u/o!==BigInt(this.Kr(s)))return l.vr()}catch(e){return ht("Error during timestamp arithmetic: "+e),l.vr()}var a=Ba(n.value.timestampValue);return ql(a.seconds,a.nanoseconds)&&(n=jl(a),Ul(a=this.Wr(n,u)))&&(n=Number(a/Ll),ql(n=(a=a%Ll)<0?n-1:n,a=Number((a<0?a+Ll:a)*BigInt(1e3))))?l.newValue({timestampValue:{seconds:n,nanos:a}}):l.vr()}Kr(e){switch(e){case"millisecond":return 1e3;case"second":return 1e6;case"minute":return 6e7;case"hour":return 36e8;case"day":return 864e8;default:return 1}}}class Zl extends Jl{Wr(e,t){return e+t}}class eh extends Jl{Wr(e,t){return e-t}}function th(e){if((e=wu(e))instanceof Go)return`fld(${e.fieldName})`;if(e instanceof zo)return`cst(${t=e.value,null===t?"null":"number"==typeof t?t.toString():"string"==typeof t?`"${t}"`:t instanceof F?`ref(${t.path})`:t instanceof so?`vec(${JSON.stringify(t)})`:JSON.stringify(t)})`;var t;if(e instanceof s)return`fn(${e.name},[${e.params.map(th).join(",")}])`;if("ListOfExpressions"===e.expressionType)return`list([${e.Rr.map(th).join(",")}])`;throw new Error("Unrecognized expr "+JSON.stringify(e,null,2))}function rh(e){return""+Array.from(e.entries()).sort().map(([e,t])=>e+"="+th(t)).join(",")}function nh(e){return e.stages.map(t=>{var e;if(t instanceof Zo)return`${t._name}(${rh(t.fields)})`;if(t instanceof eu){let e=`${t._name}(${rh(t.accumulators)})`;return 0<t.groups.size&&(e+=`grouping(${rh(t.groups)})`),e}if(t instanceof tu)return`${t._name}(${rh(t.groups)})`;if(t instanceof ru)return t._name+`(${t.Vr})`;if(t instanceof nu)return t._name+`(${t.collectionId})`;if(t instanceof iu)return t._name+"()";if(t instanceof su)return`${t._name}(${t.dr.sort()})`;if(t instanceof au)return`${t._name}(${th(t.condition)})`;if(t instanceof ou)return t._name+`(${t.limit})`;if(t instanceof lu)return`${t._name}(${e=t.orderings,e.map(e=>""+th(e.expr)+e.direction).join(",")})`;throw new Error("Unrecognized stage "+t._name)}).join("|")}function ih(e,t){return nh(e)===nh(t)}function sh(e){return e instanceof du}function ah(e){return(sh(e)?nh:na)(e)}function oh(e){return sh(e)?nh(e):Bs(Zs(e=e))+"|lt:"+e.limitType}function uh(e,t){return e instanceof du&&t instanceof du?ih(e,t):!(e instanceof du&&!(t instanceof du)||!(e instanceof du)&&t instanceof du)&&ra(e,t)}function lh(e){return(Gs(e)?nh:Bs)(e)}function hh(e,t){return e instanceof du&&t instanceof du?ih(e,t):!(e instanceof du&&!(t instanceof du)||!(e instanceof du)&&t instanceof du)&&qs(e,t)}function ch(e,t){var r=(e=>{let t=!1;var r,n=[];for(r of e)if(r instanceof lu)if(t=!0,r.orderings.some(e=>e.expr instanceof Go&&e.expr.fieldName===Nt))n.push(r);else{let e=r.orderings.map(e=>e);e.push(jo(Nt).ascending()),n.push(new lu(e,{}))}else r instanceof ou&&(t||(n.push(new lu([jo(Nt).ascending()],{})),t=!0)),n.push(r);return t||n.push(new lu([jo(Nt).ascending()],{})),n})(e.stages);if(e.userDataReader){let t=e.userDataReader.createContext(3,"toCorePipeline");r.forEach(e=>e._readUserData(t))}return new du(e.userDataReader.serializer,r,t)}class dh{constructor(e,t,r,n){this.batchId=e,this.localWriteTime=t,this.baseMutations=r,this.mutations=n}applyToRemoteDocument(e,t){var r,n,i,s,a,o,u,l=t.mutationResults;for(let c=0;c<this.mutations.length;c++){var h=this.mutations[c];h.key.isEqual(e.key)&&(r=h,n=e,i=l[c],u=h=o=a=s=void 0,r instanceof cs?(a=n,o=i,h=(s=r).value.clone(),u=fs(s.fieldTransforms,a,o.transformResults),h.setAll(u),a.convertToFoundDocument(o.version,h).setHasCommittedMutations()):r instanceof ds?(s=n,a=i,as((o=r).precondition,s)?(u=fs(o.fieldTransforms,s,a.transformResults),(h=s.data).setAll(ps(o)),h.setAll(u),s.convertToFoundDocument(a.version,h).setHasCommittedMutations()):s.convertToUnknownDocument(a.version)):n.convertToNoDocument(i.version).setHasCommittedMutations())}}applyToLocalView(e,t){for(var r of this.baseMutations)r.key.isEqual(e.key)&&(t=ls(r,e,t,this.localWriteTime));for(var n of this.mutations)n.key.isEqual(e.key)&&(t=ls(n,e,t,this.localWriteTime));return t}applyToLocalDocumentSet(n,i){let s=fa();return this.mutations.forEach(e=>{var t=n.get(e.key),r=t.overlayedDocument,t=this.applyToLocalView(r,t.mutatedFields),t=us(r,i.has(e.key)?null:t);null!==t&&s.set(e.key,t),r.isValidDocument()||r.convertToNoDocument(N.min())}),s}keys(){return this.mutations.reduce((e,t)=>e.add(t.key),V())}isEqual(e){return this.batchId===e.batchId&&Ct(this.mutations,e.mutations,(e,t)=>hs(e,t))&&Ct(this.baseMutations,e.baseMutations,(e,t)=>hs(e,t))}}class ph{constructor(e,t,r,n){this.batch=e,this.commitVersion=t,this.mutationResults=r,this.docVersions=n}static from(e,t,r){v(e.mutations.length===r.length,58842,{Qr:e.mutations.length,Gr:r.length});let n=ga;var i=e.mutations;for(let s=0;s<i.length;s++)n=n.insert(i[s].key,r[s].version);return new ph(e,t,r,n)}}class fh{constructor(e,t){this.largestBatchId=e,this.mutation=t}getKey(){return this.mutation.key}isEqual(e){return null!==e&&this.mutation===e.mutation}toString(){return`Overlay{
      largestBatchId: ${this.largestBatchId},
      mutation: ${this.mutation.toString()}
    }`}}class gh{constructor(e,t,r,n,i=N.min(),s=N.min(),a=k.EMPTY_BYTE_STRING,o=null){this.target=e,this.targetId=t,this.purpose=r,this.sequenceNumber=n,this.snapshotVersion=i,this.lastLimboFreeSnapshotVersion=s,this.resumeToken=a,this.expectedCount=o}withSequenceNumber(e){return new gh(this.target,this.targetId,this.purpose,e,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,this.expectedCount)}withResumeToken(e,t){return new gh(this.target,this.targetId,this.purpose,this.sequenceNumber,t,this.lastLimboFreeSnapshotVersion,e,null)}withExpectedCount(e){return new gh(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,e)}withLastLimboFreeSnapshotVersion(e){return new gh(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,e,this.resumeToken,this.expectedCount)}}class mh{constructor(e){this.zr=e}}function vh(e,t){var r,n=t.key,i={prefixPath:n.getCollectionPath().popLast().toArray(),collectionGroup:n.collectionGroup,documentId:n.path.lastSegment(),readTime:yh(t.readTime),hasCommittedMutations:t.hasCommittedMutations};if(t.isFoundDocument())i.document={name:$a(e=e.zr,(r=t).key),fields:r.data.value.mapValue.fields,updateTime:Ua(e,r.version.toTimestamp()),createTime:Ua(e,r.createTime.toTimestamp())};else if(t.isNoDocument())i.noDocument={path:n.path.toArray(),readTime:wh(t.version)};else{if(!t.isUnknownDocument())return A(57904,{document:t});i.unknownDocument={path:n.path.toArray(),version:wh(t.version)}}return i}function yh(e){var t=e.toTimestamp();return[t.seconds,t.nanoseconds]}function wh(e){var t=e.toTimestamp();return{seconds:t.seconds,nanoseconds:t.nanoseconds}}function _h(e){var t=new w(e.seconds,e.nanoseconds);return N.fromTimestamp(t)}function Eh(t,r){let e=(r.baseMutations||[]).map(e=>r1(t.zr,e));for(let s=0;s<r.mutations.length-1;++s){let t=r.mutations[s];if(s+1<r.mutations.length&&void 0!==r.mutations[s+1].transform){let e=r.mutations[s+1];t.updateTransforms=e.transform.fieldTransforms,r.mutations.splice(s+1,1),++s}}let n=r.mutations.map(e=>r1(t.zr,e)),i=w.fromMillis(r.localWriteTimeMs);return new dh(r.batchId,i,e,n)}function Th(e,t){var r,n,i=_h(t.readTime),s=void 0!==t.lastLimboFreeSnapshotVersion?_h(t.lastLimboFreeSnapshotVersion):N.min(),a=void 0!==t.query.structuredPipeline?(r=t.query,e=e.zr,v(0<((n=r.structuredPipeline)?.pipeline?.stages??[]).length,1845),n=n?.pipeline?.stages.map(xh),new du(e,n)):void 0!==t.query.documents?(r=t.query,v(1===(n=r.documents.length),1966,{count:n}),Zs(Ys(Wa(r.documents[0])))):Zs(a1(t.query));return new gh(a,t.targetId,"TargetPurposeListen",t.lastListenSequenceNumber,i,s,k.fromBase64String(t.resumeToken))}function bh(e,t){var r=wh(t.snapshotVersion),n=wh(t.lastLimboFreeSnapshotVersion),i=Gs(t.target)?u1(e.zr,t.target):js(t.target)?i1(e.zr,t.target):s1(e.zr,t.target).yt,s=t.resumeToken.toBase64();return{targetId:t.targetId,canonicalId:lh(t.target),readTime:r,resumeToken:s,lastListenSequenceNumber:t.sequenceNumber,lastLimboFreeSnapshotVersion:n,query:i}}function Sh(e){var t=a1({parent:e.parent,structuredQuery:e.structuredQuery});return"LAST"===e.limitType?ta(t,t.limit,"L"):t}function Ih(e,t){return new fh(t.largestBatchId,r1(e.zr,t.overlayMutation))}function Ah(e,t){var r=t.path.lastSegment();return[e,Dr(t.path.popLast()),r]}function Ch(e,t,r,n){return{indexId:e,uid:t,sequenceNumber:r,readTime:wh(n.readTime),documentKey:Dr(n.documentKey.path),largestBatchId:n.largestBatchId}}function xh(e){switch(e.name){case"collection":return new ru(e.args[0].referenceValue,{});case"collection_group":return new nu(e.args[1].stringValue,{});case"database":return new iu({});case"documents":return new su(e.args.map(e=>e.referenceValue),{});case"where":return new au(Nh(e.args[0]),{});case"limit":var t=e.args[0].integerValue??e.args[0].doubleValue;return new ou("number"==typeof t?t:Number(t),{});case"sort":return new lu(e.args.map(e=>{return t=e.mapValue?.fields,new Xo(Nh(t.expression),t.direction?.stringValue,"orderingFromProto");var t}),{});default:throw new Error(`Stage type: ${e.name} not supported.`)}}function Nh(e){return e.fieldReferenceValue?new Go(xo("_exprFromProto",e.fieldReferenceValue),"_exprFromProto"):e.functionValue?(t=e,new s(t.functionValue.name,t.functionValue.args?.map(Nh)||[])):zo._fromProto(e);var t}class Dh{getBundleMetadata(e,t){return Oh(e).get(t).next(e=>{if(e)return{id:(e=e).bundleId,createTime:_h(e.createTime),version:e.version}})}saveBundleMetadata(e,t){return Oh(e).put({bundleId:(e=t).id,createTime:wh(ja(e.createTime)),version:e.version})}getNamedQuery(e,t){return Rh(e).get(t).next(e=>{if(e)return{name:(e=e).name,query:Sh(e.bundledQuery),readTime:_h(e.readTime)}})}saveNamedQuery(e,t){return Rh(e).put({name:(e=t).name,readTime:wh(ja(e.readTime)),bundledQuery:e.bundledQuery})}}function Oh(e){return Bn(e,dn)}function Rh(e){return Bn(e,pn)}class kh{constructor(e,t){this.serializer=e,this.userId=t}static jr(e,t){var r=t.uid||"";return new kh(e,r)}getOverlay(e,t){return Lh(e).get(Ah(this.userId,t)).next(e=>e?Ih(this.serializer,e):null)}getOverlays(e,t){let r=fa();return D.forEach(t,t=>this.getOverlay(e,t).next(e=>{null!==e&&r.set(t,e)})).next(()=>r)}getAllOverlays(e,n){let i=fa();return Lh(e).ee((e,t)=>{var r=Ih(this.serializer,t);r.largestBatchId>n&&i.set(r.getKey(),r)}).next(()=>i)}saveOverlays(n,i,e){let s=[];return e.forEach((e,t)=>{var r=new fh(i,t);s.push(this.Hr(n,r))}),D.waitFor(s)}removeOverlaysForBatchId(r,e,n){let t=new Set,i=(e.forEach(e=>t.add(Dr(e.getCollectionPath()))),[]);return t.forEach(e=>{var t=IDBKeyRange.bound([this.userId,e,n],[this.userId,e,n+1],!1,!0);i.push(Lh(r).Z(An,t))}),D.waitFor(i)}getOverlaysForCollection(e,t,r){let n=fa(),i=Dr(t),s=IDBKeyRange.bound([this.userId,i,r],[this.userId,i,Number.POSITIVE_INFINITY],!0);return Lh(e).H(An,s).next(e=>{for(var t of e){let e=Ih(this.serializer,t);n.set(e.getKey(),e)}return n})}getOverlaysForCollectionGroup(e,t,r,i){let s=fa(),a;var n=IDBKeyRange.bound([this.userId,t,r],[this.userId,t,Number.POSITIVE_INFINITY],!0);return Lh(e).ee({index:xn,range:n},(e,t,r)=>{var n=Ih(this.serializer,t);s.size()<i||n.largestBatchId===a?(s.set(n.getKey(),n),a=n.largestBatchId):r.done()}).next(()=>s)}Hr(e,t){return Lh(e).put(((e,t,r)=>{var[,n,i]=Ah(t,r.mutation.key);return{userId:t,collectionPath:n,documentId:i,collectionGroup:r.mutation.key.getCollectionGroup(),largestBatchId:r.largestBatchId,overlayMutation:t1(e.zr,r.mutation)}})(this.serializer,this.userId,t))}}function Lh(e){return Bn(e,Sn)}class Ph{Jr(e){return Bn(e,Dn)}getSessionToken(e){return this.Jr(e).get("sessionToken").next(e=>{var t=e?.value;return t?k.fromUint8Array(t):k.EMPTY_BYTE_STRING})}setSessionToken(e,t){return this.Jr(e).put({name:"sessionToken",value:t.toUint8Array()})}}class Mh{constructor(){}Yr(e,t){this.Zr(e,t),t.Xr()}Zr(t,r){if("nullValue"in t)this.ei(r,5);else if("booleanValue"in t)this.ei(r,10),r.ti(t.booleanValue?1:0);else if("integerValue"in t)this.ei(r,15),r.ti(L(t.integerValue));else if("doubleValue"in t){var e=L(t.doubleValue);isNaN(e)?this.ei(r,13):(this.ei(r,15),Cr(e)?r.ti(0):r.ti(e))}else if("timestampValue"in t){let e=t.timestampValue;this.ei(r,20),"string"==typeof e&&(e=Xn(e)),r.ni(""+(e.seconds||"")),r.ti(e.nanos||0)}else"stringValue"in t?(this.ri(t.stringValue,r),this.ii(r)):"bytesValue"in t?(this.ei(r,30),r.si(Jn(t.bytesValue)),this.ii(r)):"referenceValue"in t?this._i(t.referenceValue,r):"geoPointValue"in t?(e=t.geoPointValue,this.ei(r,45),r.ti(e.latitude||0),r.ti(e.longitude||0)):"mapValue"in t?Pi(t)?this.ei(r,Number.MAX_SAFE_INTEGER):Ri(t)?this.oi(t.mapValue,r):(this.ai(t.mapValue,r),this.ii(r)):"arrayValue"in t?(this.ui(t.arrayValue,r),this.ii(r)):A(19022,{ci:t})}ri(e,t){this.ei(t,25),this.li(e,t)}li(e,t){t.ni(e)}ai(e,t){var r=e.fields||{};this.ei(t,55);for(let e of Object.keys(r))this.ri(e,t),this.Zr(r[e],t)}oi(e,t){var r=e.fields||{},n=(this.ei(t,53),pi),i=r[n].arrayValue?.values?.length||0;this.ei(t,15),t.ti(L(i)),this.ri(n,t),this.Zr(r[n],t)}ui(e,t){var r=e.values||[];this.ei(t,50);for(let e of r)this.Zr(e,t)}_i(e,t){this.ei(t,37),x.fromName(e).path.forEach(e=>{this.ei(t,60),this.li(e,t)})}ei(e,t){e.ti(t)}ii(e){e.ti(2)}}Mh.Ei=new Mh;function Vh(e){var t=64-(e=>{let t=0;for(let n=0;n<8;++n){var r=(e=>{if(0===e)return 8;let t=0;return e>>4||(t+=4,e<<=4),e>>6||(t+=2,e<<=2),e>>7||(t+=1),t})(255&e[n]);if(t+=r,8!==r)break}return t})(e);return Math.ceil(t/8)}class Fh{constructor(){this.buffer=new Uint8Array(1024),this.position=0}hi(e){var t=e[Symbol.iterator]();let r=t.next();for(;!r.done;)this.Ti(r.value),r=t.next();this.Pi()}Ri(e){var t=e[Symbol.iterator]();let r=t.next();for(;!r.done;)this.Ii(r.value),r=t.next();this.Ai()}Vi(e){for(var t of e){let e=t.charCodeAt(0);if(e<128)this.Ti(e);else if(e<2048)this.Ti(960|e>>>6),this.Ti(128|63&e);else if(t<"\ud800"||"\udbff"<t)this.Ti(480|e>>>12),this.Ti(128|63&e>>>6),this.Ti(128|63&e);else{let e=t.codePointAt(0);this.Ti(240|e>>>18),this.Ti(128|63&e>>>12),this.Ti(128|63&e>>>6),this.Ti(128|63&e)}}this.Pi()}di(e){for(var t of e){let e=t.charCodeAt(0);if(e<128)this.Ii(e);else if(e<2048)this.Ii(960|e>>>6),this.Ii(128|63&e);else if(t<"\ud800"||"\udbff"<t)this.Ii(480|e>>>12),this.Ii(128|63&e>>>6),this.Ii(128|63&e);else{let e=t.codePointAt(0);this.Ii(240|e>>>18),this.Ii(128|63&e>>>12),this.Ii(128|63&e>>>6),this.Ii(128|63&e)}}this.Ai()}fi(e){var t=this.mi(e),r=Vh(t);this.pi(1+r),this.buffer[this.position++]=255&r;for(let n=t.length-r;n<t.length;++n)this.buffer[this.position++]=255&t[n]}gi(e){var t=this.mi(e),r=Vh(t);this.pi(1+r),this.buffer[this.position++]=~(255&r);for(let n=t.length-r;n<t.length;++n)this.buffer[this.position++]=~(255&t[n])}yi(){this.wi(255),this.wi(255)}bi(){this.Si(255),this.Si(255)}reset(){this.position=0}seed(e){this.pi(e.length),this.buffer.set(e,this.position),this.position+=e.length}Di(){return this.buffer.slice(0,this.position)}mi(e){e=e,(t=new DataView(new ArrayBuffer(8))).setFloat64(0,e,!1);var t,r=new Uint8Array(t.buffer),n=!!(128&r[0]);r[0]^=n?255:128;for(let i=1;i<r.length;++i)r[i]^=n?255:0;return r}Ti(e){var t=255&e;0==t?(this.wi(0),this.wi(255)):255==t?(this.wi(255),this.wi(0)):this.wi(t)}Ii(e){var t=255&e;0==t?(this.Si(0),this.Si(255)):255==t?(this.Si(255),this.Si(0)):this.Si(e)}Pi(){this.wi(0),this.wi(1)}Ai(){this.Si(0),this.Si(1)}wi(e){this.pi(1),this.buffer[this.position++]=e}Si(e){this.pi(1),this.buffer[this.position++]=~e}pi(e){var t=e+this.position;if(!(t<=this.buffer.length)){let e=2*this.buffer.length;e<t&&(e=t);t=new Uint8Array(e);t.set(this.buffer),this.buffer=t}}}class Uh{constructor(e){this.xi=e}si(e){this.xi.hi(e)}ni(e){this.xi.Vi(e)}ti(e){this.xi.fi(e)}Xr(){this.xi.yi()}}class Bh{constructor(e){this.xi=e}si(e){this.xi.Ri(e)}ni(e){this.xi.di(e)}ti(e){this.xi.gi(e)}Xr(){this.xi.bi()}}class qh{constructor(){this.xi=new Fh,this.ascending=new Uh(this.xi),this.descending=new Bh(this.xi)}seed(e){this.xi.seed(e)}Ci(e){return 0===e?this.ascending:this.descending}Di(){return this.xi.Di()}reset(){this.xi.reset()}}class Gh{constructor(e,t,r,n){this.Fi=e,this.Oi=t,this.Mi=r,this.Ni=n}Li(){var e=this.Ni.length,t=0===e||255===this.Ni[e-1]?e+1:e,r=new Uint8Array(t);return r.set(this.Ni,0),t!==e?r.set([0],this.Ni.length):++r[r.length-1],new Gh(this.Fi,this.Oi,this.Mi,r)}Bi(e,t,r){return{indexId:this.Fi,uid:e,arrayValue:Hh(this.Mi),directionalValue:Hh(this.Ni),orderedDocumentKey:Hh(t),documentKey:r.path.toArray()}}Ui(e,t,r){var n=this.Bi(e,t,r);return[n.indexId,n.uid,n.arrayValue,n.directionalValue,n.orderedDocumentKey,n.documentKey]}}function jh(e,t){var r=e.Fi-t.Fi;return 0!=r||0!==(r=zh(e.Mi,t.Mi))||0!==(r=zh(e.Ni,t.Ni))?r:x.comparator(e.Oi,t.Oi)}function zh(e,t){for(let n=0;n<e.length&&n<t.length;++n){var r=e[n]-t[n];if(0!=r)return r}return e.length-t.length}function Hh(r){if(Z()){var n=r;let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return e}return r}function Kh(e){if("string"!=typeof e)return e;var t=e,r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}class $h{constructor(e){this.ki=new R((e,t)=>h.comparator(e.field,t.field)),this.collectionId=null!=e.collectionGroup?e.collectionGroup:e.path.lastSegment(),this.qi=e.orderBy,this.$i=[];for(var t of e.filters){let e=t;e.isInequality()?this.ki=this.ki.add(e):this.$i.push(e)}}get Ki(){return 1<this.ki.size}Wi(e){if(v(e.collectionGroup===this.collectionId,49279),this.Ki)return!1;let t=zt(e);if(void 0!==t&&!this.Qi(t))return!1;var r=Ht(e);let n=new Set,i=0,s=0;for(;i<r.length&&this.Qi(r[i]);++i)n=n.add(r[i].fieldPath.canonicalString());if(i!==r.length){if(0<this.ki.size){let t=this.ki.getIterator().getNext();if(!n.has(t.field.canonicalString())){let e=r[i];if(!this.Gi(t,e)||!this.zi(this.qi[s++],e))return!1}++i}for(;i<r.length;++i){let e=r[i];if(s>=this.qi.length||!this.zi(this.qi[s++],e))return!1}}return!0}ji(){if(this.Ki)return null;let e=new R(h.comparator);var t,r,n=[];for(t of this.$i)t.field.isKeyField()||("array-contains"===t.op||"array-contains-any"===t.op?n.push(new Kt(t.field,2)):e.has(t.field)||(e=e.add(t.field),n.push(new Kt(t.field,0))));for(r of this.qi)r.field.isKeyField()||e.has(r.field)||(e=e.add(r.field),n.push(new Kt(r.field,"asc"===r.dir?0:1)));return new jt(jt.UNKNOWN_ID,this.collectionId,n,$t.empty())}Qi(e){for(var t of this.$i)if(this.Gi(t,e))return!0;return!1}Gi(e,t){var r;return!(void 0===e||!e.field.isEqual(t.fieldPath))&&(r="array-contains"===e.op||"array-contains-any"===e.op,2===t.kind==r)}zi(e,t){return!!e.field.isEqual(t.fieldPath)&&(0===t.kind&&"asc"===e.dir||1===t.kind&&"desc"===e.dir)}}function Qh(e){var t;return 0===e.getFilters().length?[]:(t=function t(e){if(v(e instanceof P||e instanceof M,34018),e instanceof P)return e;if(1===e.filters.length)return t(e.filters[0]);let r=e.filters.map(e=>t(e));let n=M.create(r,e.op);return n=ec(n),Xh(n)?n:(v(n instanceof M,64498),v(Ts(n),40251),v(1<n.filters.length,57927),n.filters.reduce((e,t)=>Jh(e,t)))}(function t(r){if(v(r instanceof P||r instanceof M,20012),r instanceof P){if(r instanceof ks){let e=r.value.arrayValue?.values?.map(e=>P.create(r.field,"==",e))||[];return M.create(e,"or")}return r}let e=r.filters.map(e=>t(e));return M.create(e,r.op)}(e)),v(Xh(t),7391),Yh(t)||Wh(t)?[t]:t.getFilters())}function Yh(e){return e instanceof P}function Wh(e){return e instanceof M&&Ss(e)}function Xh(e){return Yh(e)||Wh(e)||(e=>{if(e instanceof M&&bs(e)){for(var t of e.getFilters())if(!Yh(t)&&!Wh(t))return!1;return!0}return!1})(e)}function Jh(e,t){var r,n;return v(e instanceof P||e instanceof M,38388),v(t instanceof P||t instanceof M,25473),ec(e instanceof P?t instanceof P?(r=e,n=t,M.create([r,n],"and")):Zh(e,t):t instanceof P?Zh(t,e):((e,t)=>{if(v(0<e.filters.length&&0<t.filters.length,48005),Ts(e)&&Ts(t))return As(e,t.getFilters());let r=bs(e)?e:t,n=bs(e)?t:e,i=r.filters.map(e=>Jh(e,n));return M.create(i,"or")})(e,t))}function Zh(t,e){var r;return Ts(e)?As(e,t.getFilters()):(r=e.filters.map(e=>Jh(t,e)),M.create(r,"or"))}function ec(t){if(v(t instanceof P||t instanceof M,11850),t instanceof P)return t;var e=t.getFilters();if(1===e.length)return ec(e[0]);if(Is(t))return t;let r=e.map(e=>ec(e)),n=[];return r.forEach(e=>{e instanceof P?n.push(e):e instanceof M&&(e.op===t.op?n.push(...e.filters):n.push(e))}),1===n.length?n[0]:M.create(n,t.op)}class tc{constructor(){this.Hi=new rc}addToCollectionParentIndex(e,t){return this.Hi.add(t),D.resolve()}getCollectionParents(e,t){return D.resolve(this.Hi.getEntries(t))}addFieldIndex(e,t){return D.resolve()}deleteFieldIndex(e,t){return D.resolve()}deleteAllFieldIndexes(e){return D.resolve()}createTargetIndexes(e,t){return D.resolve()}getDocumentsMatchingTarget(e,t){return D.resolve(null)}getIndexType(e,t){return D.resolve(0)}getFieldIndexes(e,t){return D.resolve([])}getNextCollectionGroupToUpdate(e){return D.resolve(null)}getMinOffset(e,t){return D.resolve(Wt.min())}getMinOffsetFromCollectionGroup(e,t){return D.resolve(Wt.min())}updateCollectionGroup(e,t,r){return D.resolve()}updateIndexEntries(e,t){return D.resolve()}}class rc{constructor(){this.index={}}add(e){var t=e.lastSegment(),r=e.popLast(),n=this.index[t]||new R(T.comparator),i=!n.has(r);return this.index[t]=n.add(r),i}has(e){var t=e.lastSegment(),r=e.popLast(),t=this.index[t];return t&&t.has(r)}getEntries(e){return(this.index[e]||new R(T.comparator)).toArray()}}let nc="IndexedDbIndexManager",ic=new Uint8Array(0);class sc{constructor(e,t){this.databaseId=t,this.Ji=new rc,this.Yi=new la(e=>Bs(e),(e,t)=>qs(e,t)),this.uid=e.uid||""}addToCollectionParentIndex(e,t){var r,n;return this.Ji.has(t)?D.resolve():(n=t.lastSegment(),r=t.popLast(),e.addOnCommittedListener(()=>{this.Ji.add(t)}),n={collectionId:n,parent:Dr(r)},ac(e).put(n))}getCollectionParents(e,r){let n=[],t=IDBKeyRange.bound([r,""],[xt(r),""],!1,!0);return ac(e).H(t).next(e=>{for(var t of e){if(t.collectionId!==r)break;n.push(Rr(t.parent))}return n})}addFieldIndex(e,r){let t=uc(e),n={indexId:r.indexId,collectionGroup:r.collectionGroup,fields:r.fields.map(e=>[e.fieldPath.canonicalString(),e.kind])};delete n.indexId;var i=t.add(n);if(r.indexState){let t=lc(e);return i.next(e=>{t.put(Ch(e,this.uid,r.indexState.sequenceNumber,r.indexState.offset))})}return i.next()}deleteFieldIndex(e,t){let r=uc(e),n=lc(e),i=oc(e);return r.delete(t.indexId).next(()=>n.delete(IDBKeyRange.bound([t.indexId],[t.indexId+1],!1,!0))).next(()=>i.delete(IDBKeyRange.bound([t.indexId],[t.indexId+1],!1,!0)))}deleteAllFieldIndexes(e){let t=uc(e),r=oc(e),n=lc(e);return t.Z().next(()=>r.Z()).next(()=>n.Z())}createTargetIndexes(r,e){return D.forEach(this.Zi(e),t=>this.getIndexType(r,t).next(e=>{if(0===e||1===e){let e=new $h(t).ji();if(null!=e)return this.addFieldIndex(r,e)}}))}getDocumentsMatchingTarget(e,c){let d=oc(e),r=!0,n=new Map;return D.forEach(this.Zi(c),t=>this.Xi(e,t).next(e=>{r=r&&!!e,n.set(t,e)})).next(()=>{if(r){let l=V(),h=[];return D.forEach(n,(e,t)=>{m(nc,`Using index ${r=e,`id=${r.indexId}|cg=${r.collectionGroup}|f=`+r.fields.map(e=>e.fieldPath+":"+e.kind).join(",")} to execute `+Bs(c));var r,n=((t,e)=>{var r=zt(e);if(void 0!==r)for(let e of zs(t,r.fieldPath))switch(e.op){case"array-contains-any":return e.value.arrayValue.values||[];case"array-contains":return[e.value]}return null})(t,e),i=((t,r)=>{var n,i=new Map;for(n of Ht(r))for(let e of zs(t,n.fieldPath))switch(e.op){case"==":case"in":i.set(n.fieldPath.canonicalString(),e.value);break;case"not-in":case"!=":return i.set(n.fieldPath.canonicalString(),e.value),Array.from(i.values())}return null})(t,e),s=((t,e)=>{var r,n=[];let i=!0;for(r of Ht(e)){let e=(0===r.kind?Hs:Ks)(t,r.fieldPath,t.startAt);n.push(e.value),i=i&&e.inclusive}return new ys(n,i)})(t,e),a=((t,e)=>{var r,n=[];let i=!0;for(r of Ht(e)){let e=(0===r.kind?Ks:Hs)(t,r.fieldPath,t.endAt);n.push(e.value),i=i&&e.inclusive}return new ys(n,i)})(t,e),o=this.es(e,t,s),u=this.es(e,t,a),i=this.ts(e,t,i),n=this.ns(e.indexId,n,o,s.inclusive,u,a.inclusive,i);return D.forEach(n,e=>d.Y(e,c.limit).next(e=>{e.forEach(e=>{var t=x.fromSegments(e.documentKey);l.has(t)||(l=l.add(t),h.push(t))})}))}).next(()=>h)}return D.resolve(null)})}Zi(t){let e=this.Yi.get(t);return e||(e=0===t.filters.length?[t]:Qh(M.create(t.filters,"and")).map(e=>Us(t.path,t.collectionGroup,t.orderBy,e.getFilters(),t.limit,t.startAt,t.endAt)),this.Yi.set(t,e)),e}ns(i,s,a,o,u,l,h){let e=(null!=s?s.length:1)*Math.max(a.length,u.length),c=e/(null!=s?s.length:1),d=[];for(let p=0;p<e;++p){let t=s?this.rs(s[p/c]):ic,e=this.ss(i,t,a[p%c],o),r=this._s(i,t,u[p%c],l),n=h.map(e=>this.ss(i,t,e,!0));d.push(...this.createRange(e,r,n))}return d}ss(e,t,r,n){var i=new Gh(e,x.empty(),t,r);return n?i:i.Li()}_s(e,t,r,n){var i=new Gh(e,x.empty(),t,r);return n?i.Li():i}Xi(e,t){let n=new $h(t),r=null!=t.collectionGroup?t.collectionGroup:t.path.lastSegment();return this.getFieldIndexes(e,r).next(e=>{let t=null;for(var r of e)n.Wi(r)&&(!t||r.fields.length>t.fields.length)&&(t=r);return t})}getIndexType(e,t){let r=2,n=this.Zi(t);return D.forEach(n,t=>this.Xi(e,t).next(e=>{e?0!==r&&e.fields.length<(t=>{let r=new R(h.comparator),n=!1;for(var i of t.filters)for(let e of i.getFlattenedFilters())e.field.isKeyField()||("array-contains"===e.op||"array-contains-any"===e.op?n=!0:r=r.add(e.field));for(let n of t.orderBy)n.field.isKeyField()||(r=r.add(n.field));return r.size+(n?1:0)})(t)&&(r=1):r=0})).next(()=>null!==t.limit&&1<n.length&&2===r?1:r)}us(e,t){var r,n=new qh;for(r of Ht(e)){let e=t.data.field(r.fieldPath);if(null==e)return null;var i=n.Ci(r.kind);Mh.Ei.Yr(e,i)}return n.Di()}rs(e){var t=new qh;return Mh.Ei.Yr(e,t.Ci(0)),t.Di()}cs(e,t){var r,n=new qh;return Mh.Ei.Yr(Si(this.databaseId,t),n.Ci(0===(r=Ht(e)).length?0:r[r.length-1].kind)),n.Di()}ts(e,n,i){if(null===i)return[];let s=[],a=(s.push(new qh),0);for(var o of Ht(e)){let t=i[a++];for(let r of s)if(this.ls(n,o.fieldPath)&&xi(t))s=this.Es(s,o,t);else{let e=r.Ci(o.kind);Mh.Ei.Yr(t,e)}}return this.hs(s)}es(e,t,r){return this.ts(e,t,r.position)}hs(e){var t=[];for(let r=0;r<e.length;++r)t[r]=e[r].Di();return t}Es(r,n,e){let i=[...r],s=[];for(let r of e.arrayValue.values||[])for(let t of i){let e=new qh;e.seed(t.Di()),Mh.Ei.Yr(r,e.Ci(n.kind)),s.push(e)}return s}ls(e,t){return!!e.filters.find(e=>e instanceof P&&e.field.isEqual(t)&&("in"===e.op||"not-in"===e.op))}getFieldIndexes(e,t){let r=uc(e),n=lc(e);return(t?r.H(gn,IDBKeyRange.bound(t,t)):r.H()).next(e=>{let s=[];return D.forEach(e,i=>n.get([i.indexId,this.uid]).next(e=>{var t,r,n;s.push((t=i,r=(e=e)?new $t(e.sequenceNumber,new Wt(_h(e.readTime),new x(Rr(e.documentKey)),e.largestBatchId)):$t.empty(),n=t.fields.map(([e,t])=>new Kt(h.fromServerFormat(e),t)),new jt(t.indexId,t.collectionGroup,n,r)))})).next(()=>s)})}getNextCollectionGroupToUpdate(e){return this.getFieldIndexes(e).next(e=>0===e.length?null:(e.sort((e,t)=>{var r=e.indexState.sequenceNumber-t.indexState.sequenceNumber;return 0!=r?r:C(e.collectionGroup,t.collectionGroup)}),e[0].collectionGroup))}updateCollectionGroup(e,r,n){let i=uc(e),s=lc(e);return this.Ts(e).next(t=>i.H(gn,IDBKeyRange.bound(r,r)).next(e=>D.forEach(e,e=>s.put(Ch(e.indexId,this.uid,t,n)))))}updateIndexEntries(i,e){let r=new Map;return D.forEach(e,(t,n)=>{var e=r.get(t.collectionGroup);return(e?D.resolve(e):this.getFieldIndexes(i,t.collectionGroup)).next(e=>(r.set(t.collectionGroup,e),D.forEach(e,r=>this.Ps(i,t,r).next(e=>{var t=this.Rs(n,r);return e.isEqual(t)?D.resolve():this.Is(i,n,r,e,t)}))))})}As(e,t,r,n){return oc(e).put(n.Bi(this.uid,this.cs(r,t.key),t.key))}Vs(e,t,r,n){return oc(e).delete(n.Ui(this.uid,this.cs(r,t.key),t.key))}Ps(e,r,n){var t=oc(e);let i=new R(jh);return t.ee({index:Tn,range:IDBKeyRange.only([n.indexId,this.uid,Hh(this.cs(n,r))])},(e,t)=>{i=i.add(new Gh(n.indexId,r,Kh(t.arrayValue),Kh(t.directionalValue)))}).next(()=>i)}Rs(t,r){let n=new R(jh);var i=this.us(r,t);if(null!=i){let e=zt(r);if(null!=e){var s=t.data.field(e.fieldPath);if(xi(s))for(let e of s.arrayValue.values||[])n=n.add(new Gh(r.indexId,t.key,this.rs(e),i))}else n=n.add(new Gh(r.indexId,t.key,ic,i))}return n}Is(t,r,s,e,a){m(nc,"Updating index entries for document '%s'",r.key);let o=[];{var u=jh,l=e=>{o.push(this.As(t,r,s,e))},h=e=>{o.push(this.Vs(t,r,s,e))},c=e.getIterator(),d=a.getIterator();let n=zn(c),i=zn(d);for(;n||i;){let t=!1,r=!1;if(n&&i){let e=u(n,i);e<0?r=!0:0<e&&(t=!0)}else null!=n?r=!0:t=!0;t?(l(i),i=zn(d)):r?(h(n),n=zn(c)):(n=zn(c),i=zn(d))}}return D.waitFor(o)}Ts(e){let n=1;return lc(e).ee({index:yn,reverse:!0,range:IDBKeyRange.upperBound([this.uid,Number.MAX_SAFE_INTEGER])},(e,t,r)=>{r.done(),n=t.sequenceNumber+1}).next(()=>n)}createRange(r,n,e){e=e.sort((e,t)=>jh(e,t)).filter((e,t,r)=>!t||0!==jh(e,r[t-1]));var i=[];i.push(r);for(let s of e){let e=jh(s,r),t=jh(s,n);if(0===e)i[0]=r.Li();else if(0<e&&t<0)i.push(s),i.push(s.Li());else if(0<t)break}i.push(n);let s=[];for(let a=0;a<i.length;a+=2){if(this.ds(i[a],i[a+1]))return[];let e=i[a].Ui(this.uid,ic,x.empty()),t=i[a+1].Ui(this.uid,ic,x.empty());s.push(IDBKeyRange.bound(e,t))}return s}ds(e,t){return 0<jh(e,t)}getMinOffsetFromCollectionGroup(e,t){return this.getFieldIndexes(e,t).next(hc)}getMinOffset(t,e){return D.mapArray(this.Zi(e),e=>this.Xi(t,e).next(e=>e||A(44426))).next(hc)}}function ac(e){return Bn(e,ln)}function oc(e){return Bn(e,_n)}function uc(e){return Bn(e,fn)}function lc(e){return Bn(e,mn)}function hc(e){v(0!==e.length,28825);let t=e[0].indexState.offset,r=t.largestBatchId;for(let i=1;i<e.length;i++){var n=e[i].indexState.offset;Xt(n,t)<0&&(t=n),r<n.largestBatchId&&(r=n.largestBatchId)}return new Wt(t.readTime,t.documentKey,r)}function cc(t,r,n){let e=t.store(Vr),i=t.store(zr),s=[],a=IDBKeyRange.only(n.batchId),o=0;var u=e.ee({range:a},(e,t,r)=>(o++,r.delete()));s.push(u.next(()=>{v(1===o,47070,{batchId:n.batchId})}));let l=[];for(let t of n.mutations){let e=Gr(r,t.key.path,n.batchId);s.push(i.delete(e)),l.push(t.key)}return D.waitFor(s).next(()=>l)}function dc(e){if(!e)return 0;let t;if(e.document)t=e.document;else if(e.unknownDocument)t=e.unknownDocument;else{if(!e.noDocument)throw A(14731);t=e.noDocument}return JSON.stringify(t).length}class pc{constructor(e,t,r,n){this.userId=e,this.serializer=t,this.indexManager=r,this.referenceDelegate=n,this.fs={}}static jr(e,t,r,n){v(""!==e.uid,64387);var i=e.isAuthenticated()?e.uid:"";return new pc(i,t,r,n)}checkEmpty(e){let n=!0;var t=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return gc(e).ee({index:Ur,range:t},(e,t,r)=>{n=!1,r.done()}).next(()=>n)}addMutationBatch(c,d,p,f){let g=mc(c),m=gc(c);return m.add({}).next(t=>{v("number"==typeof t,49019);let e=new dh(t,d,p,f),r=(i=this.serializer,s=this.userId,a=e,o=a.baseMutations.map(e=>t1(i.zr,e)),u=a.mutations.map(e=>t1(i.zr,e)),{userId:s,batchId:a.batchId,localWriteTimeMs:a.localWriteTime.toMillis(),baseMutations:o,mutations:u}),n=[];var i,s,a,o,u;let l=new R((e,t)=>C(e.canonicalString(),t.canonicalString()));for(let h of f){let e=Gr(this.userId,h.key.path,t);l=l.add(h.key.path.popLast()),n.push(m.put(r)),n.push(g.put(e,jr))}return l.forEach(e=>{n.push(this.indexManager.addToCollectionParentIndex(c,e))}),c.addOnCommittedListener(()=>{this.fs[t]=e.keys()}),D.waitFor(n).next(()=>e)})}lookupMutationBatch(e,t){return gc(e).get(t).next(e=>e?(v(e.userId===this.userId,48,"Unexpected user for mutation batch",{userId:e.userId,batchId:t}),Eh(this.serializer,e)):null)}ps(e,r){return this.fs[r]?D.resolve(this.fs[r]):this.lookupMutationBatch(e,r).next(e=>{var t;return e?(t=e.keys(),this.fs[r]=t):null})}getNextMutationBatchAfterBatchId(e,t){let n=t+1,r=IDBKeyRange.lowerBound([this.userId,n]),i=null;return gc(e).ee({index:Ur,range:r},(e,t,r)=>{t.userId===this.userId&&(v(t.batchId>=n,47524,{gs:n}),i=Eh(this.serializer,t)),r.done()}).next(()=>i)}getHighestUnacknowledgedBatchId(e){var t=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]);let n=Ir;return gc(e).ee({index:Ur,range:t,reverse:!0},(e,t,r)=>{n=t.batchId,r.done()}).next(()=>n)}getAllMutationBatches(e){var t=IDBKeyRange.bound([this.userId,Ir],[this.userId,Number.POSITIVE_INFINITY]);return gc(e).H(Ur,t).next(e=>e.map(e=>Eh(this.serializer,e)))}getAllMutationBatchesAffectingDocumentKey(o,u){let e=qr(this.userId,u.path),t=IDBKeyRange.lowerBound(e),l=[];return mc(o).ee({range:t},(t,e,r)=>{let[n,i,s]=t,a=Rr(i);if(n===this.userId&&u.path.isEqual(a))return gc(o).get(s).next(e=>{if(!e)throw A(61480,{ys:t,batchId:s});v(e.userId===this.userId,10503,"Unexpected user for mutation batch",{userId:e.userId,batchId:s}),l.push(Eh(this.serializer,e))});r.done()}).next(()=>l)}getAllMutationBatchesAffectingDocumentKeys(t,e){let o=new R(C),r=[];return e.forEach(a=>{var e=qr(this.userId,a.path),e=IDBKeyRange.lowerBound(e),e=mc(t).ee({range:e},(e,t,r)=>{var[n,i,s]=e,i=Rr(i);n===this.userId&&a.path.isEqual(i)?o=o.add(s):r.done()});r.push(e)}),D.waitFor(r).next(()=>this.ws(t,o))}getAllMutationBatchesAffectingQuery(e,t){let a=t.path,o=a.length+1,r=qr(this.userId,a),n=IDBKeyRange.lowerBound(r),u=new R(C);return mc(e).ee({range:n},(e,t,r)=>{var[n,i,s]=e,i=Rr(i);n===this.userId&&a.isPrefixOf(i)?i.length===o&&(u=u.add(s)):r.done()}).next(()=>this.ws(e,u))}ws(e,t){let r=[],n=[];return t.forEach(t=>{n.push(gc(e).get(t).next(e=>{if(null===e)throw A(35274,{batchId:t});v(e.userId===this.userId,9748,"Unexpected user for mutation batch",{userId:e.userId,batchId:t}),r.push(Eh(this.serializer,e))}))}),D.waitFor(n).next(()=>r)}removeMutationBatch(t,r){return cc(t.le,this.userId,r).next(e=>(t.addOnCommittedListener(()=>{this.bs(r.batchId)}),D.forEach(e,e=>this.referenceDelegate.markPotentiallyOrphaned(t,e))))}bs(e){delete this.fs[e]}performConsistencyCheck(r){return this.checkEmpty(r).next(e=>{if(!e)return D.resolve();let t=IDBKeyRange.lowerBound([this.userId]),n=[];return mc(r).ee({range:t},(t,e,r)=>{if(t[0]===this.userId){let e=Rr(t[1]);n.push(e)}else r.done()}).next(()=>{v(0===n.length,56720,{vs:n.map(e=>e.canonicalString())})})})}containsKey(e,t){return fc(e,this.userId,t)}Ss(e){return vc(e).get(this.userId).next(e=>e||{userId:this.userId,lastAcknowledgedBatchId:Ir,lastStreamToken:""})}}function fc(e,s,t){let r=qr(s,t.path),a=r[1],n=IDBKeyRange.lowerBound(r),o=!1;return mc(e).ee({range:n,X:!0},(e,t,r)=>{var[n,i,,]=e;n===s&&i===a&&(o=!0),r.done()}).next(()=>o)}function gc(e){return Bn(e,Vr)}function mc(e){return Bn(e,zr)}function vc(e){return Bn(e,Mr)}class yc{constructor(e){this.Ds=e}next(){return this.Ds+=2,this.Ds}static xs(){return new yc(0)}static Cs(){return new yc(-1)}}class wc{constructor(e,t){this.referenceDelegate=e,this.serializer=t}allocateTargetId(r){return this.Fs(r).next(e=>{var t=new yc(e.highestTargetId);return e.highestTargetId=t.next(),this.Os(r,e).next(()=>e.highestTargetId)})}getLastRemoteSnapshotVersion(e){return this.Fs(e).next(e=>N.fromTimestamp(new w(e.lastRemoteSnapshotVersion.seconds,e.lastRemoteSnapshotVersion.nanoseconds)))}getHighestSequenceNumber(e){return this.Fs(e).next(e=>e.highestListenSequenceNumber)}setTargetsMetadata(t,r,n){return this.Fs(t).next(e=>(e.highestListenSequenceNumber=r,n&&(e.lastRemoteSnapshotVersion=n.toTimestamp()),e.highestListenSequenceNumber<r&&(e.highestListenSequenceNumber=r),this.Os(t,e)))}addTargetData(t,r){return this.Ms(t,r).next(()=>this.Fs(t).next(e=>(e.targetCount+=1,this.Ns(r,e),this.Os(t,e))))}updateTargetData(e,t){return this.Ms(e,t)}removeTargetData(t,e){return this.removeMatchingKeysForTargetId(t,e.targetId).next(()=>_c(t).delete(e.targetId)).next(()=>this.Fs(t)).next(e=>(v(0<e.targetCount,8065),--e.targetCount,this.Os(t,e)))}removeTargets(n,i,s){let a=0,o=[];return _c(n).ee((e,t)=>{var r=Th(this.serializer,t);r.sequenceNumber<=i&&null===s.get(r.targetId)&&(a++,o.push(this.removeTargetData(n,r)))}).next(()=>D.waitFor(o)).next(()=>a)}forEachTarget(e,n){return _c(e).ee((e,t)=>{var r=Th(this.serializer,t);n(r)})}Fs(e){return Ec(e).get(on).next(e=>(v(null!==e,2888),e))}Os(e,t){return Ec(e).put(on,t)}Ms(e,t){return _c(e).put(bh(this.serializer,t))}Ns(e,t){let r=!1;return e.targetId>t.highestTargetId&&(t.highestTargetId=e.targetId,r=!0),t.highestListenSequenceNumber<e.sequenceNumber&&(t.highestListenSequenceNumber=e.sequenceNumber,r=!0),r}getTargetCount(e){return this.Fs(e).next(e=>e.targetCount)}getTargetData(e,i){var t=lh(i),t=IDBKeyRange.bound([t,Number.NEGATIVE_INFINITY],[t,Number.POSITIVE_INFINITY]);let s=null;return _c(e).ee({range:t,index:en},(e,t,r)=>{var n=Th(this.serializer,t);hh(i,n.target)&&(s=n,r.done())}).next(()=>s)}addMatchingKeys(r,e,n){let i=[],s=Tc(r);return e.forEach(e=>{var t=Dr(e.path);i.push(s.put({targetId:n,path:t})),i.push(this.referenceDelegate.addReference(r,n,e))}),D.waitFor(i)}removeMatchingKeys(r,e,n){let i=Tc(r);return D.forEach(e,e=>{var t=Dr(e.path);return D.waitFor([i.delete([n,t]),this.referenceDelegate.removeReference(r,n,e)])})}removeMatchingKeysForTargetId(e,t){var r=Tc(e),n=IDBKeyRange.bound([t],[t+1],!1,!0);return r.delete(n)}getMatchingKeysForTargetId(e,t){var r=IDBKeyRange.bound([t],[t+1],!1,!0),n=Tc(e);let i=V();return n.ee({range:r,X:!0},(e,t,r)=>{var n=Rr(e[1]),n=new x(n);i=i.add(n)}).next(()=>i)}containsKey(e,t){var r=Dr(t.path),r=IDBKeyRange.bound([r],[xt(r)],!1,!0);let n=0;return Tc(e).ee({index:sn,X:!0,range:r},([e],t,r)=>{0!==e&&(n++,r.done())}).next(()=>0<n)}dt(e,t){return _c(e).get(t).next(e=>e?Th(this.serializer,e):null)}}function _c(e){return Bn(e,Zr)}function Ec(e){return Bn(e,un)}function Tc(e){return Bn(e,rn)}class bc{constructor(e,t){this.db=e,this.garbageCollector=Q1(this,t)}lr(e){let r=this.Ls(e);return this.db.getTargetCache().getTargetCount(e).next(t=>r.next(e=>t+e))}Ls(e){let t=0;return this.Er(e,e=>{t++}).next(()=>t)}forEachTarget(e,t){return this.db.getTargetCache().forEachTarget(e,t)}Er(e,r){return this.Bs(e,(e,t)=>r(t))}addReference(e,t,r){return Sc(e,r)}removeReference(e,t,r){return Sc(e,r)}removeTargets(e,t,r){return this.db.getTargetCache().removeTargets(e,t,r)}markPotentiallyOrphaned(e,t){return Sc(e,t)}Us(e,r){{var n=e,i=r;let t=!1;return vc(n).te(e=>fc(n,e,i).next(e=>(e&&(t=!0),D.resolve(!e)))).next(()=>t)}}removeOrphanedDocuments(r,n){let i=this.db.getRemoteDocumentCache().newChangeBuffer(),s=[],a=0;return this.Bs(r,(t,e)=>{if(e<=n){let e=this.Us(r,t).next(e=>{if(!e)return a++,i.getEntry(r,t).next(()=>(i.removeEntry(t,N.min()),Tc(r).delete([0,Dr(t.path)])))});s.push(e)}}).next(()=>D.waitFor(s)).next(()=>i.apply(r)).next(()=>a)}removeTarget(e,t){var r=t.withSequenceNumber(e.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(e,r)}updateLimboDocument(e,t){return Sc(e,t)}Bs(e,n){var t=Tc(e);let i,s=Sr.ce;return t.ee({index:sn},([e],{path:t,sequenceNumber:r})=>{0===e?(s!==Sr.ce&&n(new x(Rr(i)),s),s=r,i=t):s=Sr.ce}).next(()=>{s!==Sr.ce&&n(new x(Rr(i)),s)})}getCacheSize(e){return this.db.getRemoteDocumentCache().getSize(e)}}function Sc(e,t){return Tc(e).put((e=e.currentSequenceNumber,{targetId:0,path:Dr(t.path),sequenceNumber:e}))}function Ic(e,t){let r=t;for(let t of e.stages)r=((t,r,n)=>{var i,s,a,o,u;if(r instanceof ru)return i=r,n.filter(e=>e.isFoundDocument()&&"/"+e.key.getCollectionPath().canonicalString()===i.Vr);if(r instanceof au)return s=t,a=r,n.filter(e=>{var t=yu(U(a.condition).evaluate(s,e));return void 0!==t&&yi(t,gi)});if(r instanceof nu)return o=r,n.filter(e=>e.isFoundDocument()&&e.key.getCollectionPath().lastSegment()===o.collectionId);if(r instanceof iu)return n.filter(e=>e.isFoundDocument());if(r instanceof su)return u=r,n.filter(e=>e.isFoundDocument()&&u.mr.has(e.key.path.toStringWithLeadingSlash()));if(r instanceof ou)return n.slice(0,r.limit);if(r instanceof lu){var l=t,t=n;let e=r.orderings.map(e=>({ks:U(e.expr),direction:e.direction}));return[...t].sort((n,i)=>{for(var{ks:s,direction:a}of e){let e=yu(s.evaluate(l,n)),t=yu(s.evaluate(l,i)),r=_i(e??fi,t??fi);if(0!==r)return"ascending"===a?r:-r}return 0})}throw new Error("Unknown stage: "+r._name)})({serializer:e.serializer,serverTimestampBehavior:e.listenOptions?.serverTimestampBehavior},t,r);return r}function Ac(e,t){return 0<Ic(e,[t]).length}function Cc(e,t){return(sh(e)?Ac:ia)(e,t)}function xc(a){let e=(e=>{for(let r=e.stages.length-1;0<=r;r--){var t=e.stages[r];if(t instanceof lu)return t.orderings}throw new Error("Pipeline must contain at least one Sort stage")})(a);return(n,i)=>{for(var s of e){let e=yu(U(s.expr).evaluate({serializer:a.serializer},n)),t=yu(U(s.expr).evaluate({serializer:a.serializer},i)),r=_i(e||fi,t||fi);if(0!==r)return"ascending"===s.direction?r:-r}return 0}}function Nc(e){for(let r=e.stages.length-1;0<=r;r--){var t=e.stages[r];if(t instanceof ou)return{limit:t.limit}}}class Dc{constructor(){this.changes=new la(e=>e.toString(),(e,t)=>e.isEqual(t)),this.changesApplied=!1}addEntry(e){this.assertNotApplied(),this.changes.set(e.key,e)}removeEntry(e,t){this.assertNotApplied(),this.changes.set(e,Vs.newInvalidDocument(e).setReadTime(t))}getEntry(e,t){this.assertNotApplied();var r=this.changes.get(t);return void 0!==r?D.resolve(r):this.getFromCache(e,t)}getEntries(e,t){return this.getAllFromCache(e,t)}apply(e){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(e)}assertNotApplied(){}}class Oc{constructor(e){this.serializer=e}setIndexManager(e){this.indexManager=e}addEntry(e,t,r){return Pc(e).put(r)}removeEntry(e,t,r){return Pc(e).delete((e=r,[(n=t.path.toArray()).slice(0,n.length-2),n[n.length-2],yh(e),n[n.length-1]]));var n}updateMetadata(t,r){return this.getMetadata(t).next(e=>(e.byteSize+=r,this.qs(t,e)))}getEntry(e,r){let n=Vs.newInvalidDocument(r);return Pc(e).ee({index:$r,range:IDBKeyRange.only(Mc(r))},(e,t)=>{n=this.$s(r,t)}).next(()=>n)}Ks(e,r){let n={size:0,document:Vs.newInvalidDocument(r)};return Pc(e).ee({index:$r,range:IDBKeyRange.only(Mc(r))},(e,t)=>{n={document:this.$s(r,t),size:dc(t)}}).next(()=>n)}getEntries(e,t){let n=ha;return this.Ws(e,t,(e,t)=>{var r=this.$s(e,t);n=n.insert(e,r)}).next(()=>n)}getAllEntries(e){let n=ha;return Pc(e).ee((e,t)=>{var r=this.$s(x.fromSegments(t.prefixPath.concat(t.collectionGroup,t.documentId)),t);n=n.insert(r.key,r)}).next(()=>n)}Qs(e,t){let n=ha,i=new O(x.comparator);return this.Ws(e,t,(e,t)=>{var r=this.$s(e,t);n=n.insert(e,r),i=i.insert(e,dc(t))}).next(()=>({documents:n,Gs:i}))}Ws(e,t,i){if(t.isEmpty())return D.resolve();let r=new R(Fc),n=(t.forEach(e=>r=r.add(e)),IDBKeyRange.bound(Mc(r.first()),Mc(r.last()))),s=r.getIterator(),a=s.getNext();return Pc(e).ee({index:$r,range:n},(e,t,r)=>{for(var n=x.fromSegments([...t.prefixPath,t.collectionGroup,t.documentId]);a&&Fc(a,n)<0;)i(a,null),a=s.getNext();a&&a.isEqual(n)&&(i(a,t),a=s.hasNext()?s.getNext():null),a?r.j(Mc(a)):r.done()}).next(()=>{for(;a;)i(a,null),a=s.hasNext()?s.getNext():null})}getDocumentsMatchingQuery(e,n,t,i,s){var r=sh(n)?T.fromString(fu(n)):n.path,a=[r.popLast().toArray(),r.lastSegment(),yh(t.readTime),t.documentKey.path.isEmpty()?"":t.documentKey.path.lastSegment()],r=[r.popLast().toArray(),r.lastSegment(),[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],""];return Pc(e).H(IDBKeyRange.bound(a,r,!0)).next(e=>{s?.incrementDocumentReadCount(e.length);let t=ha;for(let r of e){let e=this.$s(x.fromSegments(r.prefixPath.concat(r.collectionGroup,r.documentId)),r);e.isFoundDocument()&&(Cc(n,e)||i.has(e.key))&&(t=t.insert(e.key,e))}return t})}getAllFromCollectionGroup(e,t,r,i){let s=ha;var n=Vc(t,r),a=Vc(t,Wt.max());return Pc(e).ee({index:Yr,range:IDBKeyRange.bound(n,a,!0)},(e,t,r)=>{var n=this.$s(x.fromSegments(t.prefixPath.concat(t.collectionGroup,t.documentId)),t);(s=s.insert(n.key,n)).size===i&&r.done()}).next(()=>s)}newChangeBuffer(e){return new kc(this,!!e&&e.trackRemovals)}getSize(e){return this.getMetadata(e).next(e=>e.byteSize)}getMetadata(e){return Lc(e).get(Jr).next(e=>(v(!!e,20021),e))}qs(e,t){return Lc(e).put(Jr,t)}$s(e,t){if(t){let e=((e,r)=>{let n;if(r.document)n=e1(e.zr,r.document,!!r.hasCommittedMutations);else if(r.noDocument){let e=x.fromSegments(r.noDocument.path),t=_h(r.noDocument.readTime);n=Vs.newNoDocument(e,t),r.hasCommittedMutations&&n.setHasCommittedMutations()}else{if(!r.unknownDocument)return A(56709);{let e=x.fromSegments(r.unknownDocument.path),t=_h(r.unknownDocument.version);n=Vs.newUnknownDocument(e,t)}}return r.readTime&&n.setReadTime((e=r.readTime,t=new w(e[0],e[1]),N.fromTimestamp(t))),n;var t})(this.serializer,t);if(!e.isNoDocument()||!e.version.isEqual(N.min()))return e}return Vs.newInvalidDocument(e)}}function Rc(e){return new Oc(e)}class kc extends Dc{constructor(e,t){super(),this.zs=e,this.trackRemovals=t,this.js=new la(e=>e.toString(),(e,t)=>e.isEqual(t))}applyChanges(s){let a=[],o=0,u=new R((e,t)=>C(e.canonicalString(),t.canonicalString()));return this.changes.forEach((t,r)=>{var e=this.js.get(t);if(a.push(this.zs.removeEntry(s,t,e.readTime)),r.isValidDocument()){var n=vh(this.zs.serializer,r),i=(u=u.add(t.path.popLast()),dc(n));o+=i-e.size,a.push(this.zs.addEntry(s,t,n))}else if(o-=e.size,this.trackRemovals){let e=vh(this.zs.serializer,r.convertToNoDocument(N.min()));a.push(this.zs.addEntry(s,t,e))}}),u.forEach(e=>{a.push(this.zs.indexManager.addToCollectionParentIndex(s,e))}),a.push(this.zs.updateMetadata(s,o)),D.waitFor(a)}getFromCache(e,t){return this.zs.Ks(e,t).next(e=>(this.js.set(t,{size:e.size,readTime:e.document.readTime}),e.document))}getAllFromCache(e,t){return this.zs.Qs(e,t).next(({documents:r,Gs:e})=>(e.forEach((e,t)=>{this.js.set(e,{size:t,readTime:r.get(e).readTime})}),r))}}function Lc(e){return Bn(e,Xr)}function Pc(e){return Bn(e,Hr)}function Mc(e){var t=e.path.toArray();return[t.slice(0,t.length-2),t[t.length-2],t[t.length-1]]}function Vc(e,t){var r=t.documentKey.path.toArray();return[e,yh(t.readTime),r.slice(0,r.length-2),0<r.length?r[r.length-1]:""]}function Fc(e,t){var r=e.path.toArray(),n=t.path.toArray();let i=0;for(let s=0;s<r.length-2&&s<n.length-2;++s)if(i=C(r[s],n[s]))return i;return(i=C(r.length,n.length))||(i=C(r[r.length-2],n[n.length-2]))||C(r[r.length-1],n[n.length-1])}class Uc{constructor(e,t){this.overlayedDocument=e,this.mutatedFields=t}}class Bc{constructor(e,t,r,n){this.remoteDocumentCache=e,this.mutationQueue=t,this.documentOverlayCache=r,this.indexManager=n}getDocument(t,r){let n=null;return this.documentOverlayCache.getOverlay(t,r).next(e=>(n=e,this.remoteDocumentCache.getEntry(t,r))).next(e=>(null!==n&&ls(n.mutation,e,Hn.empty(),w.now()),e))}getDocuments(t,e){return this.remoteDocumentCache.getEntries(t,e).next(e=>this.getLocalViewOfDocuments(t,e,V()).next(()=>e))}getLocalViewOfDocuments(e,t,r=V()){let n=fa();return this.populateOverlays(e,n,t).next(()=>this.computeViews(e,t,n,r).next(e=>{let r=da();return e.forEach((e,t)=>{r=r.insert(e,t.overlayedDocument)}),r}))}getOverlayedDocuments(e,t){let r=fa();return this.populateOverlays(e,r,t).next(()=>this.computeViews(e,t,r,V()))}populateOverlays(e,r,t){let n=[];return t.forEach(e=>{r.has(e)||n.push(e)}),this.documentOverlayCache.getOverlays(e,n).next(e=>{e.forEach((e,t)=>{r.set(e,t)})})}computeViews(e,t,n,i){let s=ha,a=fa(),r=fa();return t.forEach((e,t)=>{var r=n.get(t.key);i.has(t.key)&&(void 0===r||r.mutation instanceof ds)?s=s.insert(t.key,t):void 0!==r?(a.set(t.key,r.mutation.getFieldMask()),ls(r.mutation,t,r.mutation.getFieldMask(),w.now())):a.set(t.key,Hn.empty())}),this.recalculateAndSaveOverlays(e,s).next(e=>(e.forEach((e,t)=>a.set(e,t)),t.forEach((e,t)=>r.set(e,new Uc(t,a.get(e)??null))),r))}recalculateAndSaveOverlays(a,o){let u=fa(),l=new O((e,t)=>e-t),h=V();return this.mutationQueue.getAllMutationBatchesAffectingDocumentKeys(a,o).next(e=>{for(let n of e)n.keys().forEach(e=>{var t,r=o.get(e);null!==r&&(t=u.get(e)||Hn.empty(),t=n.applyToLocalView(r,t),u.set(e,t),r=(l.get(n.batchId)||V()).add(e),l=l.insert(n.batchId,r))})}).next(()=>{for(var i=[],s=l.getReverseIterator();s.hasNext();){let e=s.getNext(),t=e.key,r=e.value,n=fa();r.forEach(e=>{var t;h.has(e)||(null!==(t=us(o.get(e),u.get(e)))&&n.set(e,t),h=h.add(e))}),i.push(this.documentOverlayCache.saveOverlays(a,t,n))}return D.waitFor(i)}).next(()=>u)}recalculateAndSaveOverlaysForDocumentKeys(t,e){return this.remoteDocumentCache.getEntries(t,e).next(e=>this.recalculateAndSaveOverlays(t,e))}getDocumentsMatchingQuery(e,t,r,n){return sh(t)?this.getDocumentsMatchingPipeline(e,t,r,n):(i=t,x.isDocumentKey(i.path)&&null===i.collectionGroup&&0===i.filters.length?this.getDocumentsMatchingDocumentQuery(e,t.path):Xs(t)?this.getDocumentsMatchingCollectionGroupQuery(e,t,r,n):this.getDocumentsMatchingCollectionQuery(e,t,r,n));var i}getNextDocuments(s,t,a,o){return this.remoteDocumentCache.getAllFromCollectionGroup(s,t,a,o).next(r=>{var e=0<o-r.size?this.documentOverlayCache.getOverlaysForCollectionGroup(s,t,a.largestBatchId,o-r.size):D.resolve(fa());let n=Gt,i=r;return e.next(e=>D.forEach(e,(t,e)=>(n<e.largestBatchId&&(n=e.largestBatchId),r.get(t)?D.resolve():this.remoteDocumentCache.getEntry(s,t).next(e=>{i=i.insert(t,e)}))).next(()=>this.populateOverlays(s,e,r)).next(()=>this.computeViews(s,i,e,V())).next(e=>({batchId:n,changes:pa(e)})))})}getDocumentsMatchingDocumentQuery(e,t){return this.getDocument(e,new x(t)).next(e=>{let t=da();return t=e.isFoundDocument()?t.insert(e.key,e):t})}getDocumentsMatchingCollectionGroupQuery(n,i,s,a){let o=i.collectionGroup,u=da();return this.indexManager.getCollectionParents(n,o).next(e=>D.forEach(e,e=>{t=i,e=e.child(o);var t,r=new $s(e,null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt);return this.getDocumentsMatchingCollectionQuery(n,r,s,a).next(e=>{e.forEach((e,t)=>{u=u.insert(e,t)})})}).next(()=>u))}getDocumentsMatchingCollectionQuery(t,r,n,i){let s;return this.documentOverlayCache.getOverlaysForCollection(t,r.path,n.largestBatchId).next(e=>(s=e,this.remoteDocumentCache.getDocumentsMatchingQuery(t,r,n,s,i))).next(e=>this.retrieveMatchingLocalDocuments(s,e,e=>ia(r,e)))}getDocumentsMatchingPipeline(a,o,u,l){if("collection_group"===pu(o)){let i=gu(o),s=da();return this.indexManager.getCollectionParents(a,i).next(e=>D.forEach(e,e=>{t=o,r=e.child(i),n=t.stages.map(e=>e instanceof nu?new ru(r.canonicalString(),{}):e);var t,r,n=new du(t.serializer,n);return this.getDocumentsMatchingPipeline(a,n,u,l).next(e=>{e.forEach((e,t)=>{s=s.insert(e,t)})})}).next(()=>s))}{let r;return this.getOverlaysForPipeline(a,o,u.largestBatchId).next(e=>{switch(r=e,pu(o)){case"collection":return this.remoteDocumentCache.getDocumentsMatchingQuery(a,o,u,r,l);case"documents":let e=V();for(let t of vu(o))e=e.add(x.fromPath(t));return this.remoteDocumentCache.getEntries(a,e);case"database":return this.remoteDocumentCache.getAllEntries(a);default:throw new E("invalid-argument","Invalid pipeline source to execute offline: "+nh(o))}}).next(e=>this.retrieveMatchingLocalDocuments(r,e,e=>Ac(o,e)))}}retrieveMatchingLocalDocuments(n,i,s){n.forEach((e,t)=>{var r=t.getKey();null===i.get(r)&&(i=i.insert(r,Vs.newInvalidDocument(r)))});let a=da();return i.forEach((e,t)=>{var r=n.get(e);void 0!==r&&ls(r.mutation,t,Hn.empty(),w.now()),s(t)&&(a=a.insert(e,t))}),a}getOverlaysForPipeline(e,t,r){switch(pu(t)){case"collection":return this.documentOverlayCache.getOverlaysForCollection(e,T.fromString(fu(t)),r);case"collection_group":throw new E("invalid-argument","Unexpected collection group pipeline: "+nh(t));case"documents":return this.documentOverlayCache.getOverlays(e,vu(t).map(e=>x.fromPath(e)));case"database":return this.documentOverlayCache.getAllOverlays(e,r);default:throw new E("invalid-argument","Failed to get overlays for pipeline: "+nh(t))}}}class qc{constructor(e){this.serializer=e,this.Hs=new Map,this.Js=new Map}getBundleMetadata(e,t){return D.resolve(this.Hs.get(t))}saveBundleMetadata(e,t){return this.Hs.set(t.id,{id:t.id,version:t.version,createTime:ja(t.createTime)}),D.resolve()}getNamedQuery(e,t){return D.resolve(this.Js.get(t))}saveNamedQuery(e,t){return this.Js.set(t.name,{name:(t=t).name,query:Sh(t.bundledQuery),readTime:ja(t.readTime)}),D.resolve()}}class Gc{constructor(){this.overlays=new O(x.comparator),this.Ys=new Map}getOverlay(e,t){return D.resolve(this.overlays.get(t))}getOverlays(e,t){let r=fa();return D.forEach(t,t=>this.getOverlay(e,t).next(e=>{null!==e&&r.set(t,e)})).next(()=>r)}getAllOverlays(e,r){let n=fa();return this.overlays.forEach((e,t)=>{t.largestBatchId>r&&n.set(e,t)}),D.resolve(n)}saveOverlays(r,n,e){return e.forEach((e,t)=>{this.Hr(r,n,t)}),D.resolve()}removeOverlaysForBatchId(e,t,r){var n=this.Ys.get(r);return void 0!==n&&(n.forEach(e=>this.overlays=this.overlays.remove(e)),this.Ys.delete(r)),D.resolve()}getOverlaysForCollection(e,r,n){let i=fa(),s=r.length+1,t=new x(r.child("")),a=this.overlays.getIteratorFrom(t);for(;a.hasNext();){let e=a.getNext().value,t=e.getKey();if(!r.isPrefixOf(t.path))break;t.path.length===s&&e.largestBatchId>n&&i.set(e.getKey(),e)}return D.resolve(i)}getOverlaysForCollectionGroup(e,r,n,t){let i=new O((e,t)=>e-t);for(var s=this.overlays.getIterator();s.hasNext();){let t=s.getNext().value;if(t.getKey().getCollectionGroup()===r&&t.largestBatchId>n){let e=i.get(t.largestBatchId);null===e&&(e=fa(),i=i.insert(t.largestBatchId,e)),e.set(t.getKey(),t)}}let a=fa(),o=i.getIterator();for(;o.hasNext()&&(o.getNext().value.forEach((e,t)=>a.set(e,t)),!(a.size()>=t)););return D.resolve(a)}Hr(e,t,r){var n=this.overlays.get(r.key);if(null!==n){let e=this.Ys.get(n.largestBatchId).delete(r.key);this.Ys.set(n.largestBatchId,e)}this.overlays=this.overlays.insert(r.key,new fh(t,r));let i=this.Ys.get(t);void 0===i&&(i=V(),this.Ys.set(t,i)),this.Ys.set(t,i.add(r.key))}}class jc{constructor(){this.sessionToken=k.EMPTY_BYTE_STRING}getSessionToken(e){return D.resolve(this.sessionToken)}setSessionToken(e,t){return this.sessionToken=t,D.resolve()}}class zc{constructor(){this.Zs=new R(Hc.Xs),this.e_=new R(Hc.t_)}isEmpty(){return this.Zs.isEmpty()}addReference(e,t){var r=new Hc(e,t);this.Zs=this.Zs.add(r),this.e_=this.e_.add(r)}n_(e,t){e.forEach(e=>this.addReference(e,t))}removeReference(e,t){this.r_(new Hc(e,t))}i_(e,t){e.forEach(e=>this.removeReference(e,t))}s_(e){let t=new x(new T([])),r=new Hc(t,e),n=new Hc(t,e+1),i=[];return this.e_.forEachInRange([r,n],e=>{this.r_(e),i.push(e.key)}),i}__(){this.Zs.forEach(e=>this.r_(e))}r_(e){this.Zs=this.Zs.delete(e),this.e_=this.e_.delete(e)}o_(e){var t=new x(new T([])),r=new Hc(t,e),t=new Hc(t,e+1);let n=V();return this.e_.forEachInRange([r,t],e=>{n=n.add(e.key)}),n}containsKey(e){var t=new Hc(e,0),t=this.Zs.firstAfterOrEqual(t);return null!==t&&e.isEqual(t.key)}}class Hc{constructor(e,t){this.key=e,this.a_=t}static Xs(e,t){return x.comparator(e.key,t.key)||C(e.a_,t.a_)}static t_(e,t){return C(e.a_,t.a_)||x.comparator(e.key,t.key)}}class Kc{constructor(e,t){this.indexManager=e,this.referenceDelegate=t,this.mutationQueue=[],this.gs=1,this.u_=new R(Hc.Xs)}checkEmpty(e){return D.resolve(0===this.mutationQueue.length)}addMutationBatch(e,t,r,n){var i=this.gs,s=(this.gs++,0<this.mutationQueue.length&&this.mutationQueue[this.mutationQueue.length-1],new dh(i,t,r,n));this.mutationQueue.push(s);for(let t of n)this.u_=this.u_.add(new Hc(t.key,i)),this.indexManager.addToCollectionParentIndex(e,t.key.path.popLast());return D.resolve(s)}lookupMutationBatch(e,t){return D.resolve(this.c_(t))}getNextMutationBatchAfterBatchId(e,t){var r=this.l_(t+1),r=r<0?0:r;return D.resolve(this.mutationQueue.length>r?this.mutationQueue[r]:null)}getHighestUnacknowledgedBatchId(){return D.resolve(0===this.mutationQueue.length?Ir:this.gs-1)}getAllMutationBatches(e){return D.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(e,t){let r=new Hc(t,0),n=new Hc(t,Number.POSITIVE_INFINITY),i=[];return this.u_.forEachInRange([r,n],e=>{var t=this.c_(e.a_);i.push(t)}),D.resolve(i)}getAllMutationBatchesAffectingDocumentKeys(e,t){let n=new R(C);return t.forEach(e=>{var t=new Hc(e,0),r=new Hc(e,Number.POSITIVE_INFINITY);this.u_.forEachInRange([t,r],e=>{n=n.add(e.a_)})}),D.resolve(this.E_(n))}getAllMutationBatchesAffectingQuery(e,t){let r=t.path,n=r.length+1,i=r;x.isDocumentKey(i)||(i=i.child(""));var s=new Hc(new x(i),0);let a=new R(C);return this.u_.forEachWhile(e=>{var t=e.key.path;return!!r.isPrefixOf(t)&&(t.length===n&&(a=a.add(e.a_)),!0)},s),D.resolve(this.E_(a))}E_(e){let r=[];return e.forEach(e=>{var t=this.c_(e);null!==t&&r.push(t)}),r}removeMutationBatch(r,n){v(0===this.h_(n.batchId,"removed"),55003),this.mutationQueue.shift();let i=this.u_;return D.forEach(n.mutations,e=>{var t=new Hc(e.key,n.batchId);return i=i.delete(t),this.referenceDelegate.markPotentiallyOrphaned(r,e.key)}).next(()=>{this.u_=i})}bs(e){}containsKey(e,t){var r=new Hc(t,0),r=this.u_.firstAfterOrEqual(r);return D.resolve(t.isEqual(r&&r.key))}performConsistencyCheck(e){return this.mutationQueue.length,D.resolve()}h_(e,t){return this.l_(e)}l_(e){return 0===this.mutationQueue.length?0:e-this.mutationQueue[0].batchId}c_(e){var t=this.l_(e);return t<0||t>=this.mutationQueue.length?null:this.mutationQueue[t]}}class $c{constructor(e){this.T_=e,this.docs=new O(x.comparator),this.size=0}setIndexManager(e){this.indexManager=e}addEntry(e,t){var r=t.key,n=this.docs.get(r),n=n?n.size:0,i=this.T_(t);return this.docs=this.docs.insert(r,{document:t.mutableCopy(),size:i}),this.size+=i-n,this.indexManager.addToCollectionParentIndex(e,r.path.popLast())}removeEntry(e){var t=this.docs.get(e);t&&(this.docs=this.docs.remove(e),this.size-=t.size)}getEntry(e,t){var r=this.docs.get(t);return D.resolve(r?r.document.mutableCopy():Vs.newInvalidDocument(t))}getEntries(e,t){let r=ha;return t.forEach(e=>{var t=this.docs.get(e);r=r.insert(e,t?t.document.mutableCopy():Vs.newInvalidDocument(e))}),D.resolve(r)}getAllEntries(e){let r=ha;return this.docs.forEach((e,t)=>{r=r.insert(e,t.document)}),D.resolve(r)}getDocumentsMatchingQuery(e,t,r,n){let i,s,a=(s=sh(t)?(i=T.fromString(fu(t)),e=>Ac(t,e)):(i=t.path,e=>ia(t,e)),ha);for(var o=new x(i.child("__id-9223372036854775808__")),u=this.docs.getIteratorFrom(o);u.hasNext();){let{key:e,value:{document:t}}=u.getNext();if(!i.isPrefixOf(e.path))break;e.path.length>i.length+1||Xt(Yt(t),r)<=0||(n.has(t.key)||s(t))&&(a=a.insert(t.key,t.mutableCopy()))}return D.resolve(a)}getAllFromCollectionGroup(e,t,r,n){A(9500)}P_(e,t){return D.forEach(this.docs,e=>t(e))}newChangeBuffer(e){return new Qc(this)}getSize(e){return D.resolve(this.size)}}class Qc extends Dc{constructor(e){super(),this.zs=e}applyChanges(r){let n=[];return this.changes.forEach((e,t)=>{t.isValidDocument()?n.push(this.zs.addEntry(r,t)):this.zs.removeEntry(e)}),D.waitFor(n)}getFromCache(e,t){return this.zs.getEntry(e,t)}getAllFromCache(e,t){return this.zs.getEntries(e,t)}}class Yc{constructor(e){this.persistence=e,this.R_=new la(e=>lh(e),hh),this.lastRemoteSnapshotVersion=N.min(),this.highestTargetId=0,this.I_=0,this.A_=new zc,this.targetCount=0,this.V_=yc.xs()}forEachTarget(e,r){return this.R_.forEach((e,t)=>r(t)),D.resolve()}getLastRemoteSnapshotVersion(e){return D.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(e){return D.resolve(this.I_)}allocateTargetId(e){return this.highestTargetId=this.V_.next(),D.resolve(this.highestTargetId)}setTargetsMetadata(e,t,r){return r&&(this.lastRemoteSnapshotVersion=r),t>this.I_&&(this.I_=t),D.resolve()}Ms(e){this.R_.set(e.target,e);var t=e.targetId;t>this.highestTargetId&&(this.V_=new yc(t),this.highestTargetId=t),e.sequenceNumber>this.I_&&(this.I_=e.sequenceNumber)}addTargetData(e,t){return this.Ms(t),this.targetCount+=1,D.resolve()}updateTargetData(e,t){return this.Ms(t),D.resolve()}removeTargetData(e,t){return this.R_.delete(t.target),this.A_.s_(t.targetId),--this.targetCount,D.resolve()}removeTargets(r,n,i){let s=0,a=[];return this.R_.forEach((e,t)=>{t.sequenceNumber<=n&&null===i.get(t.targetId)&&(this.R_.delete(e),a.push(this.removeMatchingKeysForTargetId(r,t.targetId)),s++)}),D.waitFor(a).next(()=>s)}getTargetCount(e){return D.resolve(this.targetCount)}getTargetData(e,t){var r=this.R_.get(t)||null;return D.resolve(r)}addMatchingKeys(e,t,r){return this.A_.n_(t,r),D.resolve()}removeMatchingKeys(t,e,r){this.A_.i_(e,r);let n=this.persistence.referenceDelegate,i=[];return n&&e.forEach(e=>{i.push(n.markPotentiallyOrphaned(t,e))}),D.waitFor(i)}removeMatchingKeysForTargetId(e,t){return this.A_.s_(t),D.resolve()}getMatchingKeysForTargetId(e,t){var r=this.A_.o_(t);return D.resolve(r)}containsKey(e,t){return D.resolve(this.A_.containsKey(t))}}class Wc{constructor(e,t){this.d_={},this.overlays={},this.f_=new Sr(0),this.m_=!1,this.m_=!0,this.p_=new jc,this.referenceDelegate=e(this),this.g_=new Yc(this),this.indexManager=new tc,this.remoteDocumentCache=(e=e=>this.referenceDelegate.y_(e),new $c(e)),this.serializer=new mh(t),this.w_=new qc(this.serializer)}start(){return Promise.resolve()}shutdown(){return this.m_=!1,Promise.resolve()}get started(){return this.m_}setDatabaseDeletedListener(){}setNetworkEnabled(){}getIndexManager(e){return this.indexManager}getDocumentOverlayCache(e){let t=this.overlays[e.toKey()];return t||(t=new Gc,this.overlays[e.toKey()]=t),t}getMutationQueue(e,t){let r=this.d_[e.toKey()];return r||(r=new Kc(t,this.referenceDelegate),this.d_[e.toKey()]=r),r}getGlobalsCache(){return this.p_}getTargetCache(){return this.g_}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.w_}runTransaction(e,t,r){m("MemoryPersistence","Starting transaction:",e);let n=new Xc(this.f_.next());return this.referenceDelegate.b_(),r(n).next(e=>this.referenceDelegate.v_(n).next(()=>e)).toPromise().then(e=>(n.raiseOnCommittedEvent(),e))}S_(t,r){return D.or(Object.values(this.d_).map(e=>()=>e.containsKey(t,r)))}}class Xc extends Zt{constructor(e){super(),this.currentSequenceNumber=e}}class Jc{constructor(e){this.persistence=e,this.D_=new zc,this.x_=null}static C_(e){return new Jc(e)}get F_(){if(this.x_)return this.x_;throw A(60996)}addReference(e,t,r){return this.D_.addReference(r,t),this.F_.delete(r.toString()),D.resolve()}removeReference(e,t,r){return this.D_.removeReference(r,t),this.F_.add(r.toString()),D.resolve()}markPotentiallyOrphaned(e,t){return this.F_.add(t.toString()),D.resolve()}removeTarget(e,t){this.D_.s_(t.targetId).forEach(e=>this.F_.add(e.toString()));let r=this.persistence.getTargetCache();return r.getMatchingKeysForTargetId(e,t.targetId).next(e=>{e.forEach(e=>this.F_.add(e.toString()))}).next(()=>r.removeTargetData(e,t))}b_(){this.x_=new Set}v_(r){let n=this.persistence.getRemoteDocumentCache().newChangeBuffer();return D.forEach(this.F_,e=>{let t=x.fromPath(e);return this.O_(r,t).next(e=>{e||n.removeEntry(t,N.min())})}).next(()=>(this.x_=null,n.apply(r)))}updateLimboDocument(e,t){return this.O_(e,t).next(e=>{e?this.F_.delete(t.toString()):this.F_.add(t.toString())})}y_(e){return 0}O_(e,t){return D.or([()=>D.resolve(this.D_.containsKey(t)),()=>this.persistence.getTargetCache().containsKey(e,t),()=>this.persistence.S_(e,t)])}}class Zc{constructor(e,t){this.persistence=e,this.M_=new la(e=>Dr(e.path),(e,t)=>e.isEqual(t)),this.garbageCollector=Q1(this,t)}static C_(e,t){return new Zc(e,t)}b_(){}v_(e){return D.resolve()}forEachTarget(e,t){return this.persistence.getTargetCache().forEachTarget(e,t)}lr(e){let r=this.Ls(e);return this.persistence.getTargetCache().getTargetCount(e).next(t=>r.next(e=>t+e))}Ls(e){let t=0;return this.Er(e,e=>{t++}).next(()=>t)}Er(r,n){return D.forEach(this.M_,(e,t)=>this.Us(r,e,t).next(e=>e?D.resolve():n(t)))}removeTargets(e,t,r){return this.persistence.getTargetCache().removeTargets(e,t,r)}removeOrphanedDocuments(e,r){let n=0,t=this.persistence.getRemoteDocumentCache(),i=t.newChangeBuffer();return t.P_(e,t=>this.Us(e,t,r).next(e=>{e||(n++,i.removeEntry(t,N.min()))})).next(()=>i.apply(e)).next(()=>n)}markPotentiallyOrphaned(e,t){return this.M_.set(t,e.currentSequenceNumber),D.resolve()}removeTarget(e,t){var r=t.withSequenceNumber(e.currentSequenceNumber);return this.persistence.getTargetCache().updateTargetData(e,r)}addReference(e,t,r){return this.M_.set(r,e.currentSequenceNumber),D.resolve()}removeReference(e,t,r){return this.M_.set(r,e.currentSequenceNumber),D.resolve()}updateLimboDocument(e,t){return this.M_.set(t,e.currentSequenceNumber),D.resolve()}y_(e){let t=e.key.toString().length;return e.isFoundDocument()&&(t+=function n(e){switch(vi(e)){case 0:case 1:return 4;case 2:return 8;case 3:case 8:return 16;case 4:var t=ii(e);return t?16+n(t):16;case 5:return 2*e.stringValue.length;case 6:return Jn(e.bytesValue).approximateByteSize();case 7:return e.referenceValue.length;case 9:return(e.arrayValue.values||[]).reduce((e,t)=>e+n(t),0);case 10:case 11:{var i=e.mapValue;let r=0;return $n(i.fields,(e,t)=>{r+=e.length+n(t)}),r}default:throw A(13486,{value:e})}}(e.data.value)),t}Us(e,t,r){return D.or([()=>this.persistence.S_(e,t),()=>this.persistence.getTargetCache().containsKey(e,t),()=>{var e=this.M_.get(t);return D.resolve(void 0!==e&&r<e)}])}getCacheSize(e){return this.persistence.getRemoteDocumentCache().getSize(e)}}class e2{constructor(e){this.serializer=e}U(t,e,r,n){let s=new rr("createOrUpgrade",e);var i;r<1&&1<=n&&(t.createObjectStore(Lr),(i=t).createObjectStore(Mr,{keyPath:"userId"}),i.createObjectStore(Vr,{keyPath:Fr,autoIncrement:!0}).createIndex(Ur,Br,{unique:!0}),i.createObjectStore(zr),t2(t),t.createObjectStore(kr));let a=D.resolve();return r<3&&3<=n&&(0!==r&&((i=t).deleteObjectStore(rn),i.deleteObjectStore(Zr),i.deleteObjectStore(un),t2(t)),a=a.next(()=>{return e=s,t=e.store(un),r={highestTargetId:0,highestListenSequenceNumber:0,lastRemoteSnapshotVersion:N.min().toTimestamp(),targetCount:0},t.put(on,r);var e,t,r})),r<4&&4<=n&&(a=(a=0!==r?a.next(()=>{return n=t,(i=s).store(Vr).H().next(e=>{n.deleteObjectStore(Vr),n.createObjectStore(Vr,{keyPath:Fr,autoIncrement:!0}).createIndex(Ur,Br,{unique:!0});let t=i.store(Vr),r=e.map(e=>t.put(e));return D.waitFor(r)});var n,i}):a).next(()=>{t.createObjectStore(cn,{keyPath:"clientId"})})),r<5&&5<=n&&(a=a.next(()=>this.N_(s))),r<6&&6<=n&&(a=a.next(()=>(t.createObjectStore(Xr),this.L_(s)))),r<7&&7<=n&&(a=a.next(()=>this.B_(s))),r<8&&8<=n&&(a=a.next(()=>this.U_(t,s))),r<9&&9<=n&&(a=a.next(()=>{var e;(e=t).objectStoreNames.contains("remoteDocumentChanges")&&e.deleteObjectStore("remoteDocumentChanges")})),r<10&&10<=n&&(a=a.next(()=>this.k_(s))),r<11&&11<=n&&(a=a.next(()=>{t.createObjectStore(dn,{keyPath:"bundleId"}),t.createObjectStore(pn,{keyPath:"name"})})),r<12&&12<=n&&(a=a.next(()=>{var e;(e=t.createObjectStore(Sn,{keyPath:In})).createIndex(An,Cn,{unique:!1}),e.createIndex(xn,Nn,{unique:!1})})),r<13&&13<=n&&(a=a.next(()=>{var e;(e=t.createObjectStore(Hr,{keyPath:Kr})).createIndex($r,Qr),e.createIndex(Yr,Wr)}).next(()=>this.q_(t,s)).next(()=>t.deleteObjectStore(kr))),r<14&&14<=n&&(a=a.next(()=>this.K_(t,s))),r<15&&15<=n&&(a=a.next(()=>{var e;(e=t).createObjectStore(fn,{keyPath:"indexId",autoIncrement:!0}).createIndex(gn,"collectionGroup",{unique:!1}),e.createObjectStore(mn,{keyPath:vn}).createIndex(yn,wn,{unique:!1}),e.createObjectStore(_n,{keyPath:En}).createIndex(Tn,bn,{unique:!1})})),r<16&&16<=n&&(a=a.next(()=>{e.objectStore(mn).clear()}).next(()=>{e.objectStore(_n).clear()})),r<17&&17<=n&&(a=a.next(()=>{t.createObjectStore(Dn,{keyPath:"name"})})),a=r<18&&18<=n&&Z()?a.next(()=>{e.objectStore(mn).clear()}).next(()=>{e.objectStore(_n).clear()}):a}L_(t){let r=0;return t.store(kr).ee((e,t)=>{r+=dc(t)}).next(()=>{var e={byteSize:r};return t.store(Xr).put(Jr,e)})}N_(n){let e=n.store(Mr),t=n.store(Vr);return e.H().next(e=>D.forEach(e,r=>{var e=IDBKeyRange.bound([r.userId,Ir],[r.userId,r.lastAcknowledgedBatchId]);return t.H(Ur,e).next(e=>D.forEach(e,e=>{v(e.userId===r.userId,18650,"Cannot process batch from unexpected user",{batchId:e.batchId});var t=Eh(this.serializer,e);return cc(n,r.userId,t).next(()=>{})}))}))}B_(e){let a=e.store(rn),t=e.store(kr);return e.store(un).get(on).next(i=>{let s=[];return t.ee((e,t)=>{let r=new T(e),n=[0,Dr(r)];s.push(a.get(n).next(e=>e?D.resolve():(e=r,a.put({targetId:0,path:Dr(e),sequenceNumber:i.highestListenSequenceNumber}))))}).next(()=>D.waitFor(s))})}U_(e,t){e.createObjectStore(ln,{keyPath:hn});let n=t.store(ln),i=new rc,s=r=>{if(i.add(r)){let e=r.lastSegment(),t=r.popLast();return n.put({collectionId:e,parent:Dr(t)})}};return t.store(kr).ee({X:!0},(e,t)=>{var r=new T(e);return s(r.popLast())}).next(()=>t.store(zr).ee({X:!0},([,e],t)=>{var r=Rr(e);return s(r.popLast())}))}k_(e){let n=e.store(Zr);return n.ee((e,t)=>{var r=Th(this.serializer,t),r=bh(this.serializer,r);return n.put(r)})}q_(e,s){let t=s.store(kr),a=[];return t.ee((e,t)=>{var r,n=s.store(Hr),i=((r=t).document?new x(T.fromString(r.document.name).popFirst(5)):r.noDocument?x.fromSegments(r.noDocument.path):r.unknownDocument?x.fromSegments(r.unknownDocument.path):A(36783)).path.toArray(),i={prefixPath:i.slice(0,i.length-2),collectionGroup:i[i.length-2],documentId:i[i.length-1],readTime:t.readTime||[0,0],unknownDocument:t.unknownDocument,noDocument:t.noDocument,document:t.document,hasCommittedMutations:!!t.hasCommittedMutations};a.push(n.put(i))}).next(()=>D.waitFor(a))}K_(e,s){let t=s.store(Vr),a=Rc(this.serializer),o=new Wc(Jc.C_,this.serializer.zr);return t.H().next(e=>{let r=new Map;return e.forEach(e=>{let t=r.get(e.userId)??V();Eh(this.serializer,e).keys().forEach(e=>t=t.add(e)),r.set(e.userId,t)}),D.forEach(r,(e,t)=>{var r=new st(t),n=kh.jr(this.serializer,r),i=o.getIndexManager(r),r=pc.jr(r,this.serializer,i,o.referenceDelegate);return new Bc(a,r,n,i).recalculateAndSaveOverlaysForDocumentKeys(new Un(s,Sr.ce),e).next()})})}}function t2(e){e.createObjectStore(rn,{keyPath:nn}).createIndex(sn,an,{unique:!0}),e.createObjectStore(Zr,{keyPath:"targetId"}).createIndex(en,tn,{unique:!0}),e.createObjectStore(un)}let r2="IndexedDbPersistence",n2="Failed to obtain exclusive access to the persistence layer. To allow shared access, multi-tab synchronization has to be enabled in all tabs. If you are using `experimentalForceOwningTab:true`, make sure that only one tab has persistence enabled at any given time.",i2="main";class s2{constructor(e,t,r,n,i,s,a,o,u,l,h=18){if(this.allowTabSynchronization=e,this.persistenceKey=t,this.clientId=r,this.Tn=i,this.window=s,this.document=a,this.W_=u,this.Q_=l,this.G_=h,this.f_=null,this.m_=!1,this.isPrimary=!1,this.networkEnabled=!0,this.z_=null,this.inForeground=!1,this.j_=null,this.H_=null,this.J_=Number.NEGATIVE_INFINITY,this.Y_=e=>Promise.resolve(),!s2.C())throw new E(_.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");this.referenceDelegate=new bc(this,n),this.Z_=t+i2,this.serializer=new mh(o),this.X_=new nr(this.Z_,this.G_,new e2(this.serializer)),this.p_=new Ph,this.g_=new wc(this.referenceDelegate,this.serializer),this.remoteDocumentCache=Rc(this.serializer),this.w_=new Dh,this.window&&this.window.localStorage?this.eo=this.window.localStorage:(this.eo=null,!1===l&&lt(r2,"LocalStorage is unavailable. As a result, persistence may not work reliably. In particular enablePersistence() could fail immediately after refreshing the page."))}start(){return this.no().then(()=>{if(this.isPrimary||this.allowTabSynchronization)return this.ro(),this.io(),this.so(),this.runTransaction("getHighestListenSequenceNumber","readonly",e=>this.g_.getHighestSequenceNumber(e));throw new E(_.FAILED_PRECONDITION,n2)}).then(e=>{this.f_=new Sr(e,this.W_)}).then(()=>{this.m_=!0}).catch(e=>(this.X_&&this.X_.close(),Promise.reject(e)))}_o(t){return this.Y_=async e=>{if(this.started)return t(e)},t(this.isPrimary)}setDatabaseDeletedListener(t){this.X_.q(async e=>{null===e.newVersion&&await t()})}setNetworkEnabled(e){this.networkEnabled!==e&&(this.networkEnabled=e,this.Tn.enqueueAndForget(async()=>{this.started&&await this.no()}))}no(){return this.runTransaction("updateClientMetadataAndTryBecomePrimary","readwrite",t=>o2(t).put({clientId:this.clientId,updateTimeMs:Date.now(),networkEnabled:this.networkEnabled,inForeground:this.inForeground}).next(()=>{if(this.isPrimary)return this.oo(t).next(e=>{e||(this.isPrimary=!1,this.Tn.enqueueRetryable(()=>this.Y_(!1)))})}).next(()=>this.ao(t)).next(e=>this.isPrimary&&!e?this.uo(t).next(()=>!1):!!e&&this.co(t).next(()=>!0))).catch(e=>{if(mr(e))return m(r2,"Failed to extend owner lease: ",e),this.isPrimary;if(this.allowTabSynchronization)return m(r2,"Releasing owner lease after error during lease refresh",e),!1;throw e}).then(e=>{this.isPrimary!==e&&this.Tn.enqueueRetryable(()=>this.Y_(e)),this.isPrimary=e})}oo(e){return a2(e).get(Pr).next(e=>D.resolve(this.lo(e)))}Eo(e){return o2(e).delete(this.clientId)}async ho(){if(this.isPrimary&&!this.To(this.J_,18e5)){this.J_=Date.now();var e=await this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary",e=>{let n=Bn(e,cn);return n.H().next(e=>{let t=this.Po(e,18e5),r=e.filter(e=>-1===t.indexOf(e));return D.forEach(r,e=>n.delete(e.clientId)).next(()=>r)})}).catch(()=>[]);if(this.eo)for(var t of e)this.eo.removeItem(this.Ro(t.clientId))}}so(){this.H_=this.Tn.enqueueAfterDelay("client_metadata_refresh",4e3,()=>this.no().then(()=>this.ho()).then(()=>this.so()))}lo(e){return!!e&&e.ownerId===this.clientId}ao(t){return this.Q_?D.resolve(!0):a2(t).get(Pr).next(e=>{if(null!==e&&this.To(e.leaseTimestampMs,5e3)&&!this.Io(e.ownerId)){if(this.lo(e)&&this.networkEnabled)return!0;if(!this.lo(e)){if(e.allowTabSynchronization)return!1;throw new E(_.FAILED_PRECONDITION,n2)}}return!(!this.networkEnabled||!this.inForeground)||o2(t).H().next(e=>void 0===this.Po(e,5e3).find(e=>{if(this.clientId!==e.clientId){var t=!this.networkEnabled&&e.networkEnabled,r=!this.inForeground&&e.inForeground,n=this.networkEnabled===e.networkEnabled;if(t||r&&n)return!0}return!1}))}).next(e=>(this.isPrimary!==e&&m(r2,`Client ${e?"is":"is not"} eligible for a primary lease.`),e))}async shutdown(){this.m_=!1,this.Ao(),this.H_&&(this.H_.cancel(),this.H_=null),this.Vo(),this.fo(),await this.X_.runTransaction("shutdown","readwrite",[Lr,cn],e=>{let t=new Un(e,Sr.ce);return this.uo(t).next(()=>this.Eo(t))}),this.X_.close(),this.mo()}Po(e,t){return e.filter(e=>this.To(e.updateTimeMs,t)&&!this.Io(e.clientId))}po(){return this.runTransaction("getActiveClients","readonly",e=>o2(e).H().next(e=>this.Po(e,18e5).map(e=>e.clientId)))}get started(){return this.m_}getGlobalsCache(){return this.p_}getMutationQueue(e,t){return pc.jr(e,this.serializer,t,this.referenceDelegate)}getTargetCache(){return this.g_}getRemoteDocumentCache(){return this.remoteDocumentCache}getIndexManager(e){return new sc(e,this.serializer.zr.databaseId)}getDocumentOverlayCache(e){return kh.jr(this.serializer,e)}getBundleCache(){return this.w_}runTransaction(t,r,n){m(r2,"Starting transaction:",t);var e,i="readonly"===r?"readonly":"readwrite",s=18===(e=this.G_)?Fn:17===e?Vn:16===e?Mn:15===e?Pn:14===e?Ln:13===e?kn:12===e?Rn:11===e?On:void A(60245);let a;return this.X_.runTransaction(t,i,s,e=>(a=new Un(e,this.f_?this.f_.next():Sr.ce),"readwrite-primary"===r?this.oo(a).next(e=>!!e||this.ao(a)).next(e=>{if(e)return n(a);throw lt(`Failed to obtain primary lease for action '${t}'.`),this.isPrimary=!1,this.Tn.enqueueRetryable(()=>this.Y_(!1)),new E(_.FAILED_PRECONDITION,Jt)}).next(e=>this.co(a).next(()=>e)):this.yo(a).next(()=>n(a)))).then(e=>(a.raiseOnCommittedEvent(),e))}yo(e){return a2(e).get(Pr).next(e=>{if(null!==e&&this.To(e.leaseTimestampMs,5e3)&&!this.Io(e.ownerId)&&!this.lo(e)&&!(this.Q_||this.allowTabSynchronization&&e.allowTabSynchronization))throw new E(_.FAILED_PRECONDITION,n2)})}co(e){var t={ownerId:this.clientId,allowTabSynchronization:this.allowTabSynchronization,leaseTimestampMs:Date.now()};return a2(e).put(Pr,t)}static C(){return nr.C()}uo(e){let t=a2(e);return t.get(Pr).next(e=>this.lo(e)?(m(r2,"Releasing primary lease."),t.delete(Pr)):D.resolve())}To(e,t){var r=Date.now();return!(e<r-t||r<e&&(lt(`Detected an update time that is in the future: ${e} > `+r),1))}ro(){null!==this.document&&"function"==typeof this.document.addEventListener&&(this.j_=()=>{this.Tn.enqueueAndForget(()=>(this.inForeground="visible"===this.document.visibilityState,this.no()))},this.document.addEventListener("visibilitychange",this.j_),this.inForeground="visible"===this.document.visibilityState)}Vo(){this.j_&&(this.document.removeEventListener("visibilitychange",this.j_),this.j_=null)}io(){"function"==typeof this.window?.addEventListener&&(this.z_=()=>{this.Ao();var e=/(?:Version|Mobile)\/1[456]/;J()&&(navigator.appVersion.match(e)||navigator.userAgent.match(e))&&this.Tn.enterRestrictedMode(!0),this.Tn.enqueueAndForget(()=>this.shutdown())},this.window.addEventListener("pagehide",this.z_))}fo(){this.z_&&(this.window.removeEventListener("pagehide",this.z_),this.z_=null)}Io(e){try{var t=null!==this.eo?.getItem(this.Ro(e));return m(r2,`Client '${e}' ${t?"is":"is not"} zombied in LocalStorage`),t}catch(e){return lt(r2,"Failed to get zombied client id.",e),!1}}Ao(){if(this.eo)try{this.eo.setItem(this.Ro(this.clientId),String(Date.now()))}catch(e){lt("Failed to set zombie client id.",e)}}mo(){if(this.eo)try{this.eo.removeItem(this.Ro(this.clientId))}catch(e){}}Ro(e){return`firestore_zombie_${this.persistenceKey}_`+e}}function a2(e){return Bn(e,Lr)}function o2(e){return Bn(e,cn)}function u2(e,t){let r=e.projectId;return e.isDefaultDatabase||(r+="."+e.database),"firestore/"+t+"/"+r+"/"}class l2{constructor(e,t,r,n){this.targetId=e,this.fromCache=t,this.wo=r,this.bo=n}static vo(e,t){let r=V(),n=V();for(let e of t.docChanges)switch(e.type){case 0:r=r.add(e.doc.key);break;case 1:n=n.add(e.doc.key)}return new l2(e,t.fromCache,r,n)}}function h2(e,t){return x.comparator(e.key,t.key)}class c2{constructor(){this._documentReadCount=0}get documentReadCount(){return this._documentReadCount}incrementDocumentReadCount(e){this._documentReadCount+=e}}class d2{constructor(){this.So=!1,this.Do=!1,this.xo=100,this.Co=J()?8:0<ir(W())?6:4}initialize(e,t){this.Fo=e,this.indexManager=t,this.So=!0}getDocumentsMatchingQuery(r,n,e,t){let i={result:null};return this.Oo(r,n).next(e=>{i.result=e}).next(()=>{if(!i.result)return this.Mo(r,n,t,e).next(e=>{i.result=e})}).next(()=>{if(!i.result){let t=new c2;return this.No(r,n,t).next(e=>{if(i.result=e,this.Do)return this.Lo(r,n,t,e.size)})}}).next(()=>i.result)}Lo(e,t,r,n){return sh(t)?D.resolve():r.documentReadCount<this.xo?(ut()<=c.DEBUG&&m("QueryEngine","SDK will not create cache indexes for query:",na(t),"since it only creates cache indexes for collection contains","more than or equal to",this.xo,"documents"),D.resolve()):(ut()<=c.DEBUG&&m("QueryEngine","Query:",na(t),"scans",r.documentReadCount,"local documents and returns",n,"documents as results."),r.documentReadCount>this.Co*n?(ut()<=c.DEBUG&&m("QueryEngine","The SDK decides to create cache indexes for query:",na(t),"as using cache indexes may help improve performance."),this.indexManager.createTargetIndexes(e,Zs(t))):D.resolve())}Oo(i,e){if(sh(e))return D.resolve(null);let s=e;if(Ws(s))return D.resolve(null);let t=Zs(s);return this.indexManager.getIndexType(i,t).next(e=>0===e?null:(null!==s.limit&&1===e&&(s=ta(s,null,"F"),t=Zs(s)),this.indexManager.getDocumentsMatchingTarget(i,t).next(e=>{let n=V(...e);return this.Fo.getDocuments(i,n).next(r=>this.indexManager.getMinOffset(i,t).next(e=>{var t=this.Bo(s,r);return this.Uo(s,t,n,e.readTime)?this.Oo(i,ta(s,null,"F")):this.ko(i,t,s,e)}))})))}Mo(r,n,i,s){return(sh(n)?e=>{for(var t of e.stages){if(t instanceof ou||!1)return;if(t instanceof au&&!(t.condition instanceof Qo&&"exists"===t.condition._expr.name&&t.condition._expr.params[0]instanceof Go&&t.condition._expr.params[0].fieldName===Nt))return}return 1}:Ws)(n)||s.isEqual(N.min())?D.resolve(null):this.Fo.getDocuments(r,i).next(e=>{var t=this.Bo(n,e);return this.Uo(n,t,i,s)?D.resolve(null):(ut()<=c.DEBUG&&m("QueryEngine","Re-using previous result from %s to execute query: %s",s.toString(),ah(n)),this.ko(r,t,n,Qt(s,Gt)).next(e=>e))})}Bo(t,e){let r,n;return n=sh(t)?(r=new R(h2),e=>Ac(t,e)):(r=new R(sa(t)),e=>ia(t,e)),e.forEach((e,t)=>{n(t)&&(r=r.add(t))}),r}Uo(e,t,r,n){var i;return sh(e)?e.stages.some(e=>e instanceof ou||!1):null!==e.limit&&(r.size!==t.size||!!(i="F"===e.limitType?t.last():t.first())&&(i.hasPendingWrites||0<i.version.compareTo(n)))}No(e,t,r){return ut()<=c.DEBUG&&m("QueryEngine","Using full collection scan to execute query:",ah(t)),this.Fo.getDocumentsMatchingQuery(e,t,Wt.min(),r)}ko(e,r,t,n){return this.Fo.getDocumentsMatchingQuery(e,t,n).next(t=>(r.forEach(e=>{t=t.insert(e.key,e)}),t))}}let p2="LocalStore",f2=3e8;class g2{constructor(e,t,r,n){this.persistence=e,this.qo=t,this.serializer=n,this.$o=new O(C),this.Ko=new la(e=>lh(e),hh),this.Wo=new Map,this.Qo=e.getRemoteDocumentCache(),this.g_=e.getTargetCache(),this.w_=e.getBundleCache(),this.Go(r)}Go(e){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(e),this.indexManager=this.persistence.getIndexManager(e),this.mutationQueue=this.persistence.getMutationQueue(e,this.indexManager),this.localDocuments=new Bc(this.Qo,this.mutationQueue,this.documentOverlayCache,this.indexManager),this.Qo.setIndexManager(this.indexManager),this.qo.initialize(this.localDocuments,this.indexManager)}collectGarbage(t){return this.persistence.runTransaction("Collect garbage","readwrite-primary",e=>t.collect(e,this.$o))}}function m2(e,t,r,n){return new g2(e,t,r,n)}async function v2(e,t){let o=e;return o.persistence.runTransaction("Handle user change","readonly",s=>{let a;return o.mutationQueue.getAllMutationBatches(s).next(e=>(a=e,o.Go(t),o.mutationQueue.getAllMutationBatches(s))).next(e=>{let t=[],r=[],n=V();for(let i of a){t.push(i.batchId);for(let e of i.mutations)n=n.add(e.key)}for(let i of e){r.push(i.batchId);for(let e of i.mutations)n=n.add(e.key)}return o.localDocuments.getDocuments(s,n).next(e=>({zo:e,removedBatchIds:t,addedBatchIds:r}))})})}function y2(e,n){let i=e;return i.persistence.runTransaction("Acknowledge batch","readwrite-primary",e=>{let t=n.batch.keys(),r=i.Qo.newChangeBuffer({trackRemovals:!0});return((e,t,n,i)=>{let s=n.batch,r=s.keys(),a=D.resolve();return r.forEach(r=>{a=a.next(()=>i.getEntry(t,r)).next(e=>{var t=n.docVersions.get(r);v(null!==t,48541),e.version.compareTo(t)<0&&(s.applyToRemoteDocument(e,n),e.isValidDocument())&&(e.setReadTime(n.commitVersion),i.addEntry(e))})}),a.next(()=>e.mutationQueue.removeMutationBatch(t,s))})(i,e,n,r).next(()=>r.apply(e)).next(()=>i.mutationQueue.performConsistencyCheck(e)).next(()=>i.documentOverlayCache.removeOverlaysForBatchId(e,t,n.batch.batchId)).next(()=>i.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(e,(e=>{let t=V();for(let r=0;r<e.mutationResults.length;++r)0<e.mutationResults[r].transformResults.length&&(t=t.add(e.batch.mutations[r].key));return t})(n))).next(()=>i.localDocuments.getDocuments(e,t))})}function w2(e){let t=e;return t.persistence.runTransaction("Get last remote snapshot version","readonly",e=>t.g_.getLastRemoteSnapshotVersion(e))}function _2(e,l){let h=e,c=l.snapshotVersion,d=h.$o;return h.persistence.runTransaction("Apply remote event","readwrite-primary",o=>{let e=h.Qo.newChangeBuffer({trackRemovals:!0}),u=(d=h.$o,[]),t=(l.targetChanges.forEach((t,r)=>{var n,i,s,a=d.get(r);if(a){u.push(h.g_.removeMatchingKeys(o,t.removedDocuments,r).next(()=>h.g_.addMatchingKeys(o,t.addedDocuments,r)));let e=a.withSequenceNumber(o.currentSequenceNumber);null!==l.targetMismatches.get(r)?e=e.withResumeToken(k.EMPTY_BYTE_STRING,N.min()).withLastLimboFreeSnapshotVersion(N.min()):0<t.resumeToken.approximateByteSize()&&(e=e.withResumeToken(t.resumeToken,c)),d=d.insert(r,e),n=a,i=e,s=t,(0===n.resumeToken.approximateByteSize()||i.snapshotVersion.toMicroseconds()-n.snapshotVersion.toMicroseconds()>=f2||0<s.addedDocuments.size+s.modifiedDocuments.size+s.removedDocuments.size)&&u.push(h.g_.updateTargetData(o,e))}}),ha),r=V();if(l.documentUpdates.forEach(e=>{l.resolvedLimboDocuments.has(e)&&u.push(h.persistence.referenceDelegate.updateLimboDocument(o,e))}),u.push(E2(o,e,l.documentUpdates).next(e=>{t=e.jo,r=e.Ho})),!c.isEqual(N.min())){let e=h.g_.getLastRemoteSnapshotVersion(o).next(e=>h.g_.setTargetsMetadata(o,o.currentSequenceNumber,c));u.push(e)}return D.waitFor(u).next(()=>e.apply(o)).next(()=>h.localDocuments.getLocalViewOfDocuments(o,t,r)).next(()=>t)}).then(e=>(h.$o=d,e))}function E2(e,s,t){let r=V(),a=V();return t.forEach(e=>r=r.add(e)),s.getEntries(e,r).next(n=>{let i=ha;return t.forEach((e,t)=>{var r=n.get(e);t.isFoundDocument()!==r.isFoundDocument()&&(a=a.add(e)),t.isNoDocument()&&t.version.isEqual(N.min())?(s.removeEntry(e,t.readTime),i=i.insert(e,t)):!r.isValidDocument()||0<t.version.compareTo(r.version)||0===t.version.compareTo(r.version)&&r.hasPendingWrites?(s.addEntry(t),i=i.insert(e,t)):m(p2,"Ignoring outdated watch update for ",e,". Current version:",r.version," Watch version:",t.version)}),{jo:i,Ho:a}})}function T2(e,n){let i=e;return i.persistence.runTransaction("Allocate target","readwrite",t=>{let r;return i.g_.getTargetData(t,n).next(e=>e?(r=e,D.resolve(r)):i.g_.allocateTargetId(t).next(e=>(r=new gh(n,e,"TargetPurposeListen",t.currentSequenceNumber),i.g_.addTargetData(t,r).next(()=>r))))}).then(e=>{var t=i.$o.get(e.targetId);return(null===t||0<e.snapshotVersion.compareTo(t.snapshotVersion))&&(i.$o=i.$o.insert(e.targetId,e),i.Ko.set(n,e.targetId)),e})}async function b2(e,t,r){let n=e,i=n.$o.get(t),s=r?"readwrite":"readwrite-primary";try{r||await n.persistence.runTransaction("Release target",s,e=>n.persistence.referenceDelegate.removeTarget(e,i))}catch(e){if(!mr(e))throw e;m(p2,`Failed to update sequence numbers for target ${t}: `+e)}n.$o=n.$o.remove(t),n.Ko.delete(i.target)}function S2(e,a,o){let u=e,l=N.min(),h=V();return u.persistence.runTransaction("Execute query","readwrite",t=>{return e=u,r=t,n=sh(a)?a:Zs(a),(void 0!==(s=(i=e).Ko.get(n))?D.resolve(i.$o.get(s)):i.g_.getTargetData(r,n)).next(e=>{if(e)return l=e.lastLimboFreeSnapshotVersion,u.g_.getMatchingKeysForTargetId(t,e.targetId).next(e=>{h=e})}).next(()=>u.qo.getDocumentsMatchingQuery(t,a,o?l:N.min(),o?h:V())).next(e=>(C2(u,e),{documents:e,Jo:h}));var e,r,n,i,s})}function I2(e,t){let r=e,n=r.g_,i=r.$o.get(t);return i?Promise.resolve(i.target??null):r.persistence.runTransaction("Get target data","readonly",e=>n.dt(e,t).next(e=>e?.target??null))}function A2(e,t){let r=e,n=r.Wo.get(t)||N.min();return r.persistence.runTransaction("Get new document changes","readonly",e=>r.Qo.getAllFromCollectionGroup(e,t,Qt(n,Gt),Number.MAX_SAFE_INTEGER)).then(e=>(C2(r,e),e))}function C2(i,e){e.forEach((e,t)=>{var r=t.key.getCollectionGroup(),n=i.Wo.get(r)||N.min();0<t.readTime.compareTo(n)&&i.Wo.set(r,t.readTime)})}let x2="firestore_clients";function N2(e,t){return x2+`_${e}_`+t}let D2="firestore_mutations";function O2(e,t,r){let n=D2+`_${e}_`+r;return t.isAuthenticated()&&(n+="_"+t.uid),n}let R2="firestore_targets";function k2(e,t){return R2+`_${e}_`+t}let L2="SharedClientState";class P2{constructor(e,t,r,n){this.user=e,this.batchId=t,this.state=r,this.error=n}static ea(e,t,r){var n=JSON.parse(r);let i,s="object"==typeof n&&-1!==["pending","acknowledged","rejected"].indexOf(n.state)&&(void 0===n.error||"object"==typeof n.error);return s&&n.error&&(s="string"==typeof n.error.message&&"string"==typeof n.error.code)&&(i=new E(n.error.code,n.error.message)),s?new P2(e,t,n.state,i):(lt(L2,`Failed to parse mutation state for ID '${t}': `+r),null)}ta(){var e={state:this.state,updateTimeMs:Date.now()};return this.error&&(e.error={code:this.error.code,message:this.error.message}),JSON.stringify(e)}}class M2{constructor(e,t,r){this.targetId=e,this.state=t,this.error=r}static ea(e,t){var r=JSON.parse(t);let n,i="object"==typeof r&&-1!==["not-current","current","rejected"].indexOf(r.state)&&(void 0===r.error||"object"==typeof r.error);return i&&r.error&&(i="string"==typeof r.error.message&&"string"==typeof r.error.code)&&(n=new E(r.error.code,r.error.message)),i?new M2(e,r.state,n):(lt(L2,`Failed to parse target state for ID '${e}': `+t),null)}ta(){var e={state:this.state,updateTimeMs:Date.now()};return this.error&&(e.error={code:this.error.code,message:this.error.message}),JSON.stringify(e)}}class V2{constructor(e,t){this.clientId=e,this.activeTargetIds=t}static ea(e,t){var r=JSON.parse(t);let n="object"==typeof r&&r.activeTargetIds instanceof Array,i=va;for(let s=0;n&&s<r.activeTargetIds.length;++s)n=xr(r.activeTargetIds[s]),i=i.add(r.activeTargetIds[s]);return n?new V2(e,i):(lt(L2,`Failed to parse client data for instance '${e}': `+t),null)}}class F2{constructor(e,t){this.clientId=e,this.onlineState=t}static ea(e){var t=JSON.parse(e);return"object"==typeof t&&-1!==["Unknown","Online","Offline"].indexOf(t.onlineState)&&"string"==typeof t.clientId?new F2(t.clientId,t.onlineState):(lt(L2,"Failed to parse online state: "+e),null)}}class U2{constructor(){this.activeTargetIds=va}na(e){this.activeTargetIds=this.activeTargetIds.add(e)}ra(e){this.activeTargetIds=this.activeTargetIds.delete(e)}ta(){var e={activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()};return JSON.stringify(e)}}class B2{constructor(e,t,r,n,i){this.window=e,this.Tn=t,this.persistenceKey=r,this.ia=n,this.syncEngine=null,this.onlineStateHandler=null,this.sequenceNumberHandler=null,this.sa=this._a.bind(this),this.oa=new O(C),this.started=!1,this.aa=[];var s=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");this.storage=this.window.localStorage,this.currentUser=i,this.ua=N2(this.persistenceKey,this.ia),this.ca="firestore_sequence_number_"+this.persistenceKey,this.oa=this.oa.insert(this.ia,new U2),this.la=new RegExp(`^${x2}_${s}_([^_]*)$`),this.Ea=new RegExp(`^${D2}_${s}_(\\d+)(?:_(.*))?$`),this.ha=new RegExp(`^${R2}_${s}_(\\d+)$`),this.Ta="firestore_online_state_"+this.persistenceKey,this.Pa="firestore_bundle_loaded_v2_"+this.persistenceKey,this.window.addEventListener("storage",this.sa)}static C(e){return!(!e||!e.localStorage)}async start(){let e=await this.syncEngine.po();for(let r of e)if(r!==this.ia){let e=this.getItem(N2(this.persistenceKey,r));var t;e&&(t=V2.ea(r,e))&&(this.oa=this.oa.insert(t.clientId,t))}this.Ra();let r=this.storage.getItem(this.Ta);if(r){let e=this.Ia(r);e&&this.Aa(e)}for(let e of this.aa)this._a(e);this.aa=[],this.window.addEventListener("pagehide",()=>this.shutdown()),this.started=!0}writeSequenceNumber(e){this.setItem(this.ca,JSON.stringify(e))}getAllActiveQueryTargets(){return this.Va(this.oa)}isActiveQueryTarget(r){let n=!1;return this.oa.forEach((e,t)=>{t.activeTargetIds.has(r)&&(n=!0)}),n}addPendingMutation(e){this.da(e,"pending")}updateMutationState(e,t,r){this.da(e,t,r),this.fa(e)}addLocalQueryTarget(t,e=!0){let r="not-current";if(this.isActiveQueryTarget(t)){let e=this.storage.getItem(k2(this.persistenceKey,t));var n;e&&(n=M2.ea(t,e))&&(r=n.state)}return e&&this.ma.na(t),this.Ra(),r}removeLocalQueryTarget(e){this.ma.ra(e),this.Ra()}isLocalQueryTarget(e){return this.ma.activeTargetIds.has(e)}clearQueryState(e){this.removeItem(k2(this.persistenceKey,e))}updateQueryState(e,t,r){this.pa(e,t,r)}handleUserChange(e,t,r){t.forEach(e=>{this.fa(e)}),this.currentUser=e,r.forEach(e=>{this.addPendingMutation(e)})}setOnlineState(e){this.ga(e)}notifyBundleLoaded(e){this.ya(e)}shutdown(){this.started&&(this.window.removeEventListener("storage",this.sa),this.removeItem(this.ua),this.started=!1)}getItem(e){var t=this.storage.getItem(e);return m(L2,"READ",e,t),t}setItem(e,t){m(L2,"SET",e,t),this.storage.setItem(e,t)}removeItem(e){m(L2,"REMOVE",e),this.storage.removeItem(e)}_a(e){let t=e;t.storageArea===this.storage&&(m(L2,"EVENT",t.key,t.newValue),t.key===this.ua?lt("Received WebStorage notification for local change. Another client might have garbage-collected our state"):this.Tn.enqueueRetryable(async()=>{if(this.started){if(null!==t.key){if(this.la.test(t.key))return null==t.newValue?(e=this.wa(t.key),this.ba(e,null)):(e=this.va(t.key,t.newValue))?this.ba(e.clientId,e):void 0;if(this.Ea.test(t.key)){if(null!==t.newValue){var e=this.Sa(t.key,t.newValue);if(e)return this.Da(e)}}else if(this.ha.test(t.key)){if(null!==t.newValue){var e=this.xa(t.key,t.newValue);if(e)return this.Ca(e)}}else if(t.key===this.Ta){if(null!==t.newValue){var e=this.Ia(t.newValue);if(e)return this.Aa(e)}}else t.key===this.ca?(e=(e=>{let t=Sr.ce;if(null!=e)try{var r=JSON.parse(e);v("number"==typeof r,30636,{Fa:e}),t=r}catch(e){lt(L2,"Failed to read sequence number from WebStorage",e)}return t})(t.newValue))!==Sr.ce&&this.sequenceNumberHandler(e):t.key===this.Pa&&(e=this.Oa(t.newValue),await Promise.all(e.map(e=>this.syncEngine.Ma(e))))}}else this.aa.push(t)}))}get ma(){return this.oa.get(this.ia)}Ra(){this.setItem(this.ua,this.ma.ta())}da(e,t,r){var n=new P2(this.currentUser,e,t,r),i=O2(this.persistenceKey,this.currentUser,e);this.setItem(i,n.ta())}fa(e){var t=O2(this.persistenceKey,this.currentUser,e);this.removeItem(t)}ga(e){var t={clientId:this.ia,onlineState:e};this.storage.setItem(this.Ta,JSON.stringify(t))}pa(e,t,r){var n=k2(this.persistenceKey,e),i=new M2(e,t,r);this.setItem(n,i.ta())}ya(e){var t=JSON.stringify(Array.from(e));this.setItem(this.Pa,t)}wa(e){var t=this.la.exec(e);return t?t[1]:null}va(e,t){var r=this.wa(e);return V2.ea(r,t)}Sa(e,t){var r=this.Ea.exec(e),n=Number(r[1]),r=void 0!==r[2]?r[2]:null;return P2.ea(new st(r),n,t)}xa(e,t){var r=this.ha.exec(e),r=Number(r[1]);return M2.ea(r,t)}Ia(e){return F2.ea(e)}Oa(e){return JSON.parse(e)}async Da(e){if(e.user.uid===this.currentUser.uid)return this.syncEngine.Na(e.batchId,e.state,e.error);m(L2,"Ignoring mutation for non-active user "+e.user.uid)}Ca(e){return this.syncEngine.La(e.targetId,e.state,e.error)}ba(e,t){let r=t?this.oa.insert(e,t):this.oa.remove(e),n=this.Va(this.oa),i=this.Va(r),s=[],a=[];return i.forEach(e=>{n.has(e)||s.push(e)}),n.forEach(e=>{i.has(e)||a.push(e)}),this.syncEngine.Ba(s,a).then(()=>{this.oa=r})}Aa(e){this.oa.get(e.clientId)&&this.onlineStateHandler(e.onlineState)}Va(e){let r=va;return e.forEach((e,t)=>{r=r.unionWith(t.activeTargetIds)}),r}}class q2{constructor(){this.Ua=new U2,this.ka={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(e){}updateMutationState(e,t,r){}addLocalQueryTarget(e,t=!0){return t&&this.Ua.na(e),this.ka[e]||"not-current"}updateQueryState(e,t,r){this.ka[e]=t}removeLocalQueryTarget(e){this.Ua.ra(e)}isLocalQueryTarget(e){return this.Ua.activeTargetIds.has(e)}clearQueryState(e){delete this.ka[e]}getAllActiveQueryTargets(){return this.Ua.activeTargetIds}isActiveQueryTarget(e){return this.Ua.activeTargetIds.has(e)}start(){return this.Ua=new U2,Promise.resolve()}handleUserChange(e,t,r){}setOnlineState(e){}shutdown(){}writeSequenceNumber(e){}notifyBundleLoaded(e){}}function G2(){return"undefined"!=typeof window?window:null}function j2(){return"undefined"!=typeof document?document:null}class z2{constructor(e,t){this.asyncQueue=e,this.onlineStateHandler=t,this.state="Unknown",this.qa=0,this.$a=null,this.Ka=!0}Wa(){0===this.qa&&(this.Qa("Unknown"),this.$a=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,()=>(this.$a=null,this.Ga("Backend didn't respond within 10 seconds."),this.Qa("Offline"),Promise.resolve())))}za(e){"Online"===this.state?this.Qa("Unknown"):(this.qa++,1<=this.qa&&(this.ja(),this.Ga("Connection failed 1 times. Most recent error: "+e.toString()),this.Qa("Offline")))}set(e){this.ja(),this.qa=0,"Online"===e&&(this.Ka=!1),this.Qa(e)}Qa(e){e!==this.state&&(this.state=e,this.onlineStateHandler(e))}Ga(e){var t=`Could not reach Cloud Firestore backend. ${e}
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.`;this.Ka?(lt(t),this.Ka=!1):m("OnlineStateTracker",t)}ja(){null!==this.$a&&(this.$a.cancel(),this.$a=null)}}let H2="RemoteStore";class K2{constructor(e,t,r,n,i){this.localStore=e,this.datastore=t,this.asyncQueue=r,this.remoteSyncer={},this.Ha=[],this.Ja=new Map,this.Ya=new Map,this.Za=new Map,this.Xa=new yc(1e3),this.eu=new yc(1001),this.tu=new Set,this.nu=[],this.ru=i,this.ru.bt(e=>{r.enqueueAndForget(async()=>{var e;r6(this)&&(m(H2,"Restarting streams for network reachability change."),(e=this).tu.add(4),await Q2(e),e.iu.set("Unknown"),e.tu.delete(4),await $2(e))})}),this.iu=new z2(r,n)}}async function $2(e){if(r6(e))for(var t of e.nu)await t(!0)}async function Q2(e){for(var t of e.nu)await t(!1)}function Y2(e,t){return e.Ya.get(t)||void 0}function W2(e,t){var r,n,i,s=e,a=Y2(s,t.targetId);void 0!==a&&s.Ja.has(a)||(void 0!==(a=Y2(e=s,r=t.targetId))&&e.Za.delete(a),n=e,a=(r%2!=0?n.eu:n.Xa).next(),e.Ya.set(r,a),e.Za.set(a,r),a=a,m(H2,"remoteStoreListen mapping SDK target ID to remote",t.targetId,a),i=new gh(t.target,a,t.purpose,t.sequenceNumber,t.snapshotVersion,t.lastLimboFreeSnapshotVersion,t.resumeToken),s.Ja.set(a,i),t6(s)?e6(s):d6(s).Fn()&&J2(s,i))}function X2(e,t){var r=e,n=d6(r),i=Y2(r,t);m(H2,"remoteStoreUnlisten removing mapping of SDK target ID to remote",t,i),r.Ja.delete(i),r.Ya.delete(t),r.Za.delete(i),n.Fn()&&Z2(r,i),0===r.Ja.size&&(n.Fn()?n.Nn():r6(r)&&r.iu.set("Unknown"))}function J2(e,t){if(e.su.We(t.targetId),0<t.resumeToken.approximateByteSize()||0<t.snapshotVersion.compareTo(N.min())){var r=e.Za.get(t.targetId);if(void 0===r)return m(H2,"SDK target ID not found for remote ID: "+t.targetId);r=e.remoteSyncer.getRemoteKeysForTarget(r).size;t=t.withExpectedCount(r)}d6(e).jn(t)}function Z2(e,t){e.su.We(t),d6(e).Hn(t)}function e6(r){r.su=new Oa({getRemoteKeysForTarget:e=>{var t=r.Za.get(e);return void 0!==t?r.remoteSyncer.getRemoteKeysForTarget(t):V()},dt:e=>r.Ja.get(e)||null,Tt:()=>r.datastore.serializer.databaseId}),d6(r).start(),r.iu.Wa()}function t6(e){return r6(e)&&!d6(e).Cn()&&0<e.Ja.size}function r6(e){return 0===e.tu.size}function n6(e){e.su=void 0}async function i6(t,e,r){if(t.iu.set("Online"),e instanceof xa&&2===e.state&&e.cause)try{var n,i=t,s=e,a=s.cause;for(n of s.targetIds){if(i.Ja.has(n)){let e=i.Za.get(n);void 0!==e&&(await i.remoteSyncer.rejectListen(e,a),i.Ya.delete(e),i.Za.delete(n)),i.Ja.delete(n)}i.su.removeTarget(n)}}catch(r){m(H2,"Failed to remove targets %s: %s ",e.targetIds.join(","),r),await s6(t,r)}else if(e instanceof Aa?t.su.et(e):e instanceof Ca?t.su.ot(e):t.su.rt(e),!r.isEqual(N.min()))try{let e=await w2(t.localStore);0<=r.compareTo(e)&&(u=r,(l=(o=t).su.Rt(u)).targetChanges.forEach((e,t)=>{var r;0<e.resumeToken.approximateByteSize()&&(r=o.Ja.get(t))&&o.Ja.set(t,r.withResumeToken(e.resumeToken,u))}),l.targetMismatches.forEach((e,t)=>{var r=o.Ja.get(e);r&&(o.Ja.set(e,r.withResumeToken(k.EMPTY_BYTE_STRING,r.snapshotVersion)),Z2(o,e),r=new gh(r.target,e,t,r.sequenceNumber),J2(o,r))}),l=((n,e)=>{let i=new Map,s=(e.targetChanges.forEach((e,t)=>{var r=n.Za.get(t);void 0!==r&&i.set(r,e)}),new O(C));return e.targetMismatches.forEach((e,t)=>{var r=n.Za.get(e);void 0!==r&&(s=s.insert(r,t))}),new Sa(e.snapshotVersion,i,s,e.documentUpdates,e.augmentedDocumentUpdates,e.resolvedLimboDocuments)})(o,l),await o.remoteSyncer.applyRemoteEvent(l))}catch(e){m(H2,"Failed to raise snapshot:",e),await s6(t,e)}var o,u,l}async function s6(e,t,r){if(!mr(t))throw t;e.tu.add(1),await Q2(e),e.iu.set("Offline"),r=r||(()=>w2(e.localStore)),e.asyncQueue.enqueueRetryable(async()=>{m(H2,"Retrying IndexedDB access"),await r(),e.tu.delete(1),await $2(e)})}function a6(t,r){return r().catch(e=>s6(t,e,r))}async function o6(e){var t,r,n,i,s=e,a=p6(s);let o=0<s.Ha.length?s.Ha[s.Ha.length-1].batchId:Ir;for(;r6(i=s)&&i.Ha.length<10;)try{let e=await((e,t)=>{let r=e;return r.persistence.runTransaction("Get next mutation batch","readonly",e=>(void 0===t&&(t=Ir),r.mutationQueue.getNextMutationBatchAfterBatchId(e,t)))})(s.localStore,o);if(null===e){0===s.Ha.length&&a.Nn();break}o=e.batchId,t=s,r=e,n=void 0,t.Ha.push(r),(n=p6(t)).Fn()&&n.Jn&&n.Yn(r.mutations)}catch(e){await s6(s,e)}u6(s)&&l6(s)}function u6(e){return r6(e)&&!p6(e).Cn()&&0<e.Ha.length}function l6(e){p6(e).start()}async function h6(e,t){var r=e,n=(r.asyncQueue.verifyOperationInProgress(),m(H2,"RemoteStore received new credentials"),r6(r));r.tu.add(3),await Q2(r),n&&r.iu.set("Unknown"),await r.remoteSyncer.handleCredentialChange(t),r.tu.delete(3),await $2(r)}async function c6(e,t){var r=e;t?(r.tu.delete(2),await $2(r)):(r.tu.add(2),await Q2(r),r.iu.set("Unknown"))}function d6(t){return t._u||(t._u=(e=t.datastore,r=t.asyncQueue,n={Qt:(async function(e){e.iu.set("Online")}).bind(null,t),zt:(async function(r){r.Ja.forEach((e,t)=>{J2(r,e)})}).bind(null,t),Ht:(async function(e,t){n6(e),t6(e)?(e.iu.za(t),e6(e)):e.iu.set("Unknown")}).bind(null,t),zn:i6.bind(null,t)},(i=e).nr(),new V1(r,i.connection,i.authCredentials,i.appCheckCredentials,i.serializer,n)),t.nu.push(async e=>{e?(t._u.Mn(),t6(t)?e6(t):t.iu.set("Unknown")):(await t._u.stop(),n6(t))})),t._u;var e,r,n,i}function p6(t){return t.ou||(t.ou=(e=t.datastore,r=t.asyncQueue,n={Qt:()=>Promise.resolve(),zt:(async function(e){p6(e).er()}).bind(null,t),Ht:(async function(e,t){if(t&&p6(e).Jn){var r=e,n=t;if(oa(t=n.code)&&t!==_.ABORTED){let e=r.Ha.shift();p6(r).Mn(),await a6(r,()=>r.remoteSyncer.rejectFailedWrite(e.batchId,n)),await o6(r)}await 0}u6(e)&&l6(e)}).bind(null,t),Zn:(async function(e){var t,r=p6(e);for(t of e.Ha)r.Yn(t.mutations)}).bind(null,t),Xn:(async function(e,t,r){let n=e.Ha.shift(),i=ph.from(n,t,r);await a6(e,()=>e.remoteSyncer.applySuccessfulWrite(i)),await o6(e)}).bind(null,t)},(i=e).nr(),new F1(r,i.connection,i.authCredentials,i.appCheckCredentials,i.serializer,n)),t.nu.push(async e=>{e?(t.ou.Mn(),await o6(t)):(await t.ou.stop(),0<t.Ha.length&&(m(H2,`Stopping write stream with ${t.Ha.length} pending writes`),t.Ha=[]))})),t.ou;var e,r,n,i}class f6{constructor(e,t,r,n,i){this.asyncQueue=e,this.timerId=t,this.targetTimeMs=r,this.op=n,this.removalCallback=i,this.deferred=new pt,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch(e=>{})}get promise(){return this.deferred.promise}static createAndSchedule(e,t,r,n,i){var s=Date.now()+r,s=new f6(e,t,s,n,i);return s.start(r),s}start(e){this.timerHandle=setTimeout(()=>this.handleDelayElapsed(),e)}skipDelay(){return this.handleDelayElapsed()}cancel(e){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new E(_.CANCELLED,"Operation cancelled"+(e?": "+e:""))))}handleDelayElapsed(){this.asyncQueue.enqueueAndForget(()=>null!==this.timerHandle?(this.clearTimeout(),this.op().then(e=>this.deferred.resolve(e))):Promise.resolve())}clearTimeout(){null!==this.timerHandle&&(this.removalCallback(this),clearTimeout(this.timerHandle),this.timerHandle=null)}}function g6(e,t){if(lt("AsyncQueue",t+": "+e),mr(e))return new E(_.UNAVAILABLE,t+": "+e);throw e}class m6{static emptySet(e){return new m6(e.comparator)}constructor(r){this.comparator=r?(e,t)=>r(e,t)||x.comparator(e.key,t.key):(e,t)=>x.comparator(e.key,t.key),this.keyedMap=da(),this.sortedSet=new O(this.comparator)}has(e){return null!=this.keyedMap.get(e)}get(e){return this.keyedMap.get(e)}first(){return this.sortedSet.minKey()}last(){return this.sortedSet.maxKey()}isEmpty(){return this.sortedSet.isEmpty()}indexOf(e){var t=this.keyedMap.get(e);return t?this.sortedSet.indexOf(t):-1}get size(){return this.sortedSet.size}forEach(r){this.sortedSet.inorderTraversal((e,t)=>(r(e),!1))}add(e){var t=this.delete(e.key);return t.copy(t.keyedMap.insert(e.key,e),t.sortedSet.insert(e,null))}delete(e){var t=this.get(e);return t?this.copy(this.keyedMap.remove(e),this.sortedSet.remove(t)):this}isEqual(e){if(!(e instanceof m6))return!1;if(this.size!==e.size)return!1;for(var r=this.sortedSet.getIterator(),n=e.sortedSet.getIterator();r.hasNext();){let e=r.getNext().key,t=n.getNext().key;if(!e.isEqual(t))return!1}return!0}toString(){let t=[];return this.forEach(e=>{t.push(e.toString())}),0===t.length?"DocumentSet ()":"DocumentSet (\n  "+t.join("  \n")+"\n)"}copy(e,t){var r=new m6;return r.comparator=this.comparator,r.keyedMap=e,r.sortedSet=t,r}}class v6{constructor(){this.au=new O(x.comparator)}track(e){var t=e.doc.key,r=this.au.get(t);!r||0!==e.type&&3===r.type?this.au=this.au.insert(t,e):3===e.type&&1!==r.type?this.au=this.au.insert(t,{type:r.type,doc:e.doc}):2===e.type&&2===r.type?this.au=this.au.insert(t,{type:2,doc:e.doc}):2===e.type&&0===r.type?this.au=this.au.insert(t,{type:0,doc:e.doc}):1===e.type&&0===r.type?this.au=this.au.remove(t):1===e.type&&2===r.type?this.au=this.au.insert(t,{type:1,doc:r.doc}):0===e.type&&1===r.type?this.au=this.au.insert(t,{type:2,doc:e.doc}):A(63341,{ft:e,uu:r})}cu(){let r=[];return this.au.inorderTraversal((e,t)=>{r.push(t)}),r}}class y6{constructor(e,t,r,n,i,s,a,o,u){this.query=e,this.docs=t,this.oldDocs=r,this.docChanges=n,this.mutatedKeys=i,this.fromCache=s,this.syncStateChanged=a,this.excludesMetadataChanges=o,this.hasCachedResults=u}static fromInitialDocuments(e,t,r,n,i){let s=[];return t.forEach(e=>{s.push({type:0,doc:e})}),new y6(e,t,m6.emptySet(t),s,r,n,!0,!1,i)}get hasPendingWrites(){return!this.mutatedKeys.isEmpty()}isEqual(e){if(!(this.fromCache===e.fromCache&&this.hasCachedResults===e.hasCachedResults&&this.syncStateChanged===e.syncStateChanged&&this.mutatedKeys.isEqual(e.mutatedKeys)&&uh(this.query,e.query)&&this.docs.isEqual(e.docs)&&this.oldDocs.isEqual(e.oldDocs)))return!1;var t=this.docChanges,r=e.docChanges;if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(t[n].type!==r[n].type||!t[n].doc.isEqual(r[n].doc))return!1;return!0}}class w6{constructor(){this.lu=void 0,this.Eu=[]}hu(){return this.Eu.some(e=>e.Tu())}}class _6{constructor(){this.queries=E6(),this.onlineState="Unknown",this.Pu=new Set}terminate(){var e,r,t,n;e=this,r=new E(_.ABORTED,"Firestore shutting down"),n=(t=e).queries,t.queries=E6(),n.forEach((e,t)=>{for(let e of t.Eu)e.onError(r)})}}function E6(){return new la(e=>oh(e),uh)}async function T6(t,r){let e=t,n=3;var i=r.query;let s=e.queries.get(i);s?!s.hu()&&r.Tu()&&(n=2):(s=new w6,n=r.Tu()?0:1);try{switch(n){case 0:s.lu=await e.onListen(i,!0);break;case 1:s.lu=await e.onListen(i,!1);break;case 2:await e.onFirstRemoteStoreListen(i)}}catch(t){let e=g6(t,`Initialization of query '${(sh(r.query)?nh:na)(r.query)}' failed`);return void r.onError(e)}e.queries.set(i,s),s.Eu.push(r),r.Ru(e.onlineState),s.lu&&r.Iu(s.lu)&&S6(e)}async function b6(e,t){var r=e,n=t.query;let i=3;var s=r.queries.get(n);if(s){let e=s.Eu.indexOf(t);0<=e&&(s.Eu.splice(e,1),0===s.Eu.length?i=t.Tu()?0:1:!s.hu()&&t.Tu()&&(i=2))}switch(i){case 0:return r.queries.delete(n),r.onUnlisten(n,!0);case 1:return r.queries.delete(n),r.onUnlisten(n,!1);case 2:return r.onLastRemoteStoreUnlisten(n);default:return}}function S6(e){e.Pu.forEach(e=>{e.next()})}(B0=Ve=Ve||{}).Default="default",B0.Cache="cache";class I6{constructor(e,t,r){this.query=e,this.Au=t,this.Vu=!1,this.du=null,this.onlineState="Unknown",this.options=r||{}}Iu(t){if(!this.options.includeMetadataChanges){let e=[];for(var r of t.docChanges)3!==r.type&&e.push(r);t=new y6(t.query,t.docs,t.oldDocs,e,t.mutatedKeys,t.fromCache,t.syncStateChanged,!0,t.hasCachedResults)}let e=!1;return this.Vu?this.fu(t)&&(this.Au.next(t),e=!0):this.mu(t,this.onlineState)&&(this.pu(t),e=!0),this.du=t,e}onError(e){this.Au.error(e)}Ru(e){this.onlineState=e;let t=!1;return this.du&&!this.Vu&&this.mu(this.du,e)&&(this.pu(this.du),t=!0),t}mu(e,t){return!e.fromCache||!this.Tu()||(!this.options.waitForSyncWhenOnline||!("Offline"!==t))&&(!e.docs.isEmpty()||e.hasCachedResults||"Offline"===t)}fu(e){var t;return 0<e.docChanges.length||(t=this.du&&this.du.hasPendingWrites!==e.hasPendingWrites,!(!e.syncStateChanged&&!t)&&!0===this.options.includeMetadataChanges)}pu(e){e=y6.fromInitialDocuments(e.query,e.docs,e.mutatedKeys,e.fromCache,e.hasCachedResults),this.Vu=!0,this.Au.next(e)}Tu(){return this.options.source!==Ve.Cache}}class A6{constructor(e,t){this.gu=e,this.byteLength=t}yu(){return"metadata"in this.gu}}class C6{constructor(e){this.serializer=e}Yo(e){return Qa(this.serializer,e)}Zo(e){return e.metadata.exists?e1(this.serializer,e.document,!1):Vs.newNoDocument(this.Yo(e.metadata.name),this.Xo(e.metadata.readTime))}Xo(e){return ja(e)}}class x6{constructor(e,t){this.wu=e,this.serializer=t,this.bu=[],this.vu=[],this.collectionGroups=new Set,this.progress=N6(e)}get queries(){return this.bu}get documents(){return this.vu}o(e){this.progress.bytesLoaded+=e.byteLength;let t=this.progress.documentsLoaded;var r;return e.gu.namedQuery?this.bu.push(e.gu.namedQuery):e.gu.documentMetadata?(this.vu.push({metadata:e.gu.documentMetadata}),e.gu.documentMetadata.exists||++t,r=T.fromString(e.gu.documentMetadata.name),this.collectionGroups.add(r.get(r.length-2))):e.gu.document&&(this.vu[this.vu.length-1].document=e.gu.document,++t),t!==this.progress.documentsLoaded?(this.progress.documentsLoaded=t,{...this.progress}):null}Du(e){let r=new Map,n=new C6(this.serializer);for(var i of e)if(i.metadata.queries){let e=n.Yo(i.metadata.name);for(let t of i.metadata.queries){var s=(r.get(t)||V()).add(e);r.set(t,s)}}return r}async xu(e){let t=await(async(r,n,e,t)=>{let i=r,s=V(),a=ha;for(let r of e){let e=n.Yo(r.metadata.name),t=(r.document&&(s=s.add(e)),n.Zo(r));t.setReadTime(n.Xo(r.metadata.readTime)),a=a.insert(e,t)}let o=i.Qo.newChangeBuffer({trackRemovals:!0}),u=await T2(i,(r=t,Zs(Ys(T.fromString("__bundle__/docs/"+r)))));return i.persistence.runTransaction("Apply bundle documents","readwrite",t=>E2(t,o,a).next(e=>(o.apply(t),e)).next(e=>i.g_.removeMatchingKeysForTargetId(t,u.targetId).next(()=>i.g_.addMatchingKeys(t,s,u.targetId)).next(()=>i.localDocuments.getLocalViewOfDocuments(t,e.jo,e.Ho)).next(()=>e.jo)))})(e,new C6(this.serializer),this.vu,this.wu.id),r=this.Du(this.documents);for(let t of this.bu)await(async(e,r,n=V())=>{let i=await T2(e,Zs(Sh(r.bundledQuery))),s=e;return s.persistence.runTransaction("Save named query","readwrite",e=>{var t=ja(r.readTime);return 0<=i.snapshotVersion.compareTo(t)?s.w_.saveNamedQuery(e,r):(t=i.withResumeToken(k.EMPTY_BYTE_STRING,t),s.$o=s.$o.insert(t.targetId,t),s.g_.updateTargetData(e,t).next(()=>s.g_.removeMatchingKeysForTargetId(e,i.targetId)).next(()=>s.g_.addMatchingKeys(e,n,i.targetId)).next(()=>s.w_.saveNamedQuery(e,r)))})})(e,t,r.get(t.name));return this.progress.taskState="Success",{progress:this.progress,Cu:this.collectionGroups,Fu:t}}}function N6(e){return{taskState:"Running",documentsLoaded:0,bytesLoaded:0,totalDocuments:e.totalDocuments,totalBytes:e.totalBytes}}class D6{constructor(e){this.key=e}}class O6{constructor(e){this.key=e}}class R6{constructor(e,t){this.query=e,this.Ou=t,this.Mu=null,this.hasCachedResults=!1,this.current=!1,this.Nu=V(),this.mutatedKeys=V(),this.Lu=(sh(e)?xc:sa)(e),this.Bu=new m6(this.Lu)}get Uu(){return this.Ou}ku(e,t){let o=t?t.qu:new v6,u=(t||this).Bu,l=(t||this).mutatedKeys,h=u,c=!1,[d,p]=this.$u(this.query,u);e.inorderTraversal((e,t)=>{var r=u.get(e),n=Cc(this.query,t)?t:null,i=!!r&&this.mutatedKeys.has(r.key),s=!!n&&(n.hasLocalMutations||this.mutatedKeys.has(n.key)&&n.hasCommittedMutations);let a=!1;r&&n?r.data.isEqual(n.data)?i!==s&&(o.track({type:3,doc:n}),a=!0):!this.Ku(r,n)&&(o.track({type:2,doc:n}),a=!0,d&&0<this.Lu(n,d)||p&&this.Lu(n,p)<0)&&(c=!0):!r&&n?(o.track({type:0,doc:n}),a=!0):r&&!n&&(o.track({type:1,doc:r}),a=!0,d||p)&&(c=!0),a&&(l=n?(h=h.add(n),s?l.add(e):l.delete(e)):(h=h.delete(e),l.delete(e)))});var r=this.Wu(this.query);if(r)if(sh(this.query)){let t=[],e=(h.forEach(e=>t.push(e)),Ic(this.query,t)),r=new m6(xc(this.query));for(let t of e)r=r.add(t);h.forEach(e=>{r.has(e.key)||(l=l.delete(e.key),o.track({type:1,doc:e}))}),h=r}else{let t=this.Qu(this.query);for(;h.size>r;){let e="F"===t?h.last():h.first();h=h.delete(e.key),l=l.delete(e.key),o.track({type:1,doc:e})}}return{Bu:h,qu:o,Uo:c,mutatedKeys:l}}Wu(e){return sh(e)?Nc(e)?.limit:e.limit||void 0}Qu(e){var t;return sh(e)?(t=Nc(e))&&t.limit<0?"L":"F":e.limitType}$u(e,t){var r;return sh(e)?(r=Nc(e)?.limit,[t.size===r?t.last():null,null]):["F"===e.limitType&&t.size===this.Wu(this.query)?t.last():null,"L"===e.limitType&&t.size===this.Wu(this.query)?t.first():null]}Ku(e,t){return e.hasLocalMutations&&t.hasCommittedMutations&&!t.hasLocalMutations}applyChanges(e,t,r,n){var i=this.Bu,s=(this.Bu=e.Bu,this.mutatedKeys=e.mutatedKeys,e.qu.cu()),a=(s.sort((e,t)=>{return r=e.type,n=t.type,(i=e=>{switch(e){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return A(20277,{ft:e})}})(r)-i(n)||this.Lu(e.doc,t.doc);var r,n,i}),this.Gu(r),n=n??!1,t&&!n?this.zu():[]),o=0===this.Nu.size&&this.current&&!n?1:0,u=o!==this.Mu;return this.Mu=o,0!==s.length||u?{snapshot:new y6(this.query,e.Bu,i,s,e.mutatedKeys,0==o,u,!1,!!r&&0<r.resumeToken.approximateByteSize()),ju:a}:{ju:a}}Ru(e){return this.current&&"Offline"===e?(this.current=!1,this.applyChanges({Bu:this.Bu,qu:new v6,mutatedKeys:this.mutatedKeys,Uo:!1},!1)):{ju:[]}}Hu(e){return!this.Ou.has(e)&&!!this.Bu.has(e)&&!this.Bu.get(e).hasLocalMutations}Gu(e){e&&(e.addedDocuments.forEach(e=>this.Ou=this.Ou.add(e)),e.modifiedDocuments.forEach(e=>{}),e.removedDocuments.forEach(e=>this.Ou=this.Ou.delete(e)),this.current=e.current)}zu(){if(!this.current)return[];let t=this.Nu,r=(this.Nu=V(),this.Bu.forEach(e=>{this.Hu(e.key)&&(this.Nu=this.Nu.add(e.key))}),[]);return t.forEach(e=>{this.Nu.has(e)||r.push(new O6(e))}),this.Nu.forEach(e=>{t.has(e)||r.push(new D6(e))}),r}Ju(e){this.Ou=e.Jo,this.Nu=V();var t=this.ku(e.documents);return this.applyChanges(t,!0)}Yu(){return y6.fromInitialDocuments(this.query,this.Bu,this.mutatedKeys,0===this.Mu,this.hasCachedResults)}}let k6="SyncEngine";class L6{constructor(e,t,r){this.query=e,this.targetId=t,this.view=r}}class P6{constructor(e){this.key=e,this.Zu=!1}}class M6{constructor(e,t,r,n,i,s){this.localStore=e,this.remoteStore=t,this.eventManager=r,this.sharedClientState=n,this.currentUser=i,this.maxConcurrentLimboResolutions=s,this.Xu={},this.ec=new la(e=>oh(e),uh),this.tc=new Map,this.nc=new Set,this.rc=new O(x.comparator),this.sc=new Map,this._c=new zc,this.oc={},this.ac=new Map,this.uc=yc.Cs(),this.onlineState="Unknown",this.cc=void 0}get isPrimaryClient(){return!0===this.cc}}async function V6(e,t,r,n){var i=await T2(e.localStore,sh(t)?t:Zs(t)),s=i.targetId,a=e.sharedClientState.addLocalQueryTarget(s,r);let o;return n&&(o=await F6(e,t,s,"current"===a,i.resumeToken)),e.isPrimaryClient&&r&&W2(e.remoteStore,i),o}async function F6(n,e,t,r,i){n.lc=(e,t,r)=>(async(e,t,r,n)=>{let i=t.view.ku(r);i.Uo&&(i=await S2(e.localStore,t.query,!1).then(({documents:e})=>t.view.ku(e,i)));var s=n&&n.targetChanges.get(t.targetId),a=n&&null!=n.targetMismatches.get(t.targetId),s=t.view.applyChanges(i,e.isPrimaryClient,s,a);return Q6(e,t.targetId,s.ju),s.snapshot})(n,e,t,r);var s=await S2(n.localStore,e,!0),a=new R6(e,s.Jo),s=a.ku(s.documents),o=Ia.createSynthesizedTargetChangeForCurrentChange(t,r&&"Offline"!==n.onlineState,i),s=a.applyChanges(s,n.isPrimaryClient,o),o=(Q6(n,t,s.ju),new L6(e,t,a));return n.ec.set(e,o),n.tc.has(t)?n.tc.get(t).push(e):n.tc.set(t,[e]),s.snapshot}async function U6(t,e,r){var n=r0(t);try{let t=await((e,i)=>{let s=e,a=w.now(),o=i.reduce((e,t)=>e.add(t.key),V()),u,l;return s.persistence.runTransaction("Locally write mutations","readwrite",n=>{let t=ha,r=V();return s.Qo.getEntries(n,o).next(e=>{(t=e).forEach((e,t)=>{t.isValidDocument()||(r=r.add(e))})}).next(()=>s.localDocuments.getOverlayedDocuments(n,t)).next(e=>{u=e;var t=[];for(let r of i){let e=((e,r)=>{let n=null;for(var i of e.fieldTransforms){let e=r.data.field(i.field),t=zi(i.transform,e||null);null!=t&&(n=null===n?Ui.empty():n).set(i.field,t)}return n||null})(r,u.get(r.key).overlayedDocument);null!=e&&t.push(new ds(r.key,e,function i(e){let s=[];return $n(e.fields,(e,r)=>{var n=new h([e]);if(Oi(r)){let t=i(r.mapValue).fields;if(0===t.length)s.push(n);else for(let e of t)s.push(n.child(e))}else s.push(n)}),new Hn(s)}(e.value.mapValue),ss.exists(!0)))}return s.mutationQueue.addMutationBatch(n,a,t,i)}).next(e=>{var t=(l=e).applyToLocalDocumentSet(u,r);return s.documentOverlayCache.saveOverlays(n,e.batchId,t)})}).then(()=>({batchId:l.batchId,changes:pa(u)}))})(n.localStore,e);n.sharedClientState.addPendingMutation(t.batchId);{var i=n;var s=t.batchId;var a=r;let e=i.oc[i.currentUser.toKey()];e=(e=e||new O(C)).insert(s,a),i.oc[i.currentUser.toKey()]=e}await W6(n,t.changes),await o6(n.remoteStore)}catch(t){let e=g6(t,"Failed to persist write");r.reject(e)}}async function B6(e,t){let n=e;try{let e=await _2(n.localStore,t);t.targetChanges.forEach((e,t)=>{var r=n.sc.get(t);r&&(v(e.addedDocuments.size+e.modifiedDocuments.size+e.removedDocuments.size<=1,22616),0<e.addedDocuments.size?r.Zu=!0:0<e.modifiedDocuments.size?v(r.Zu,14607):0<e.removedDocuments.size&&(v(r.Zu,42227),r.Zu=!1))}),await W6(n,e,t)}catch(e){await er(e)}}function q6(e,i,t){var s=e;if(s.isPrimaryClient&&0===t||!s.isPrimaryClient&&1===t){let n=[];s.ec.forEach((e,t)=>{var r=t.view.Ru(i);r.snapshot&&n.push(r.snapshot)});{t=s.eventManager;var a=i;var o=t;o.onlineState=a;let r=!1;o.queries.forEach((e,t)=>{for(let e of t.Eu)e.Ru(a)&&(r=!0)}),r&&S6(o)}n.length&&s.Xu.zn(n),s.onlineState=i,s.isPrimaryClient&&s.sharedClientState.setOnlineState(i)}}async function G6(e,t,r){var n=e;try{let e=await((e,n)=>{let i=e;return i.persistence.runTransaction("Reject batch","readwrite-primary",t=>{let r;return i.mutationQueue.lookupMutationBatch(t,n).next(e=>(v(null!==e,37113),r=e.keys(),i.mutationQueue.removeMutationBatch(t,e))).next(()=>i.mutationQueue.performConsistencyCheck(t)).next(()=>i.documentOverlayCache.removeOverlaysForBatchId(t,r,n)).next(()=>i.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(t,r)).next(()=>i.localDocuments.getDocuments(t,r))})})(n.localStore,t);H6(n,t,r),z6(n,t),n.sharedClientState.updateMutationState(t,"rejected",r),await W6(n,e)}catch(r){await er(r)}}async function j6(t,r){let n=t;r6(n.remoteStore)||m(k6,"The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled.");try{let e=await(e=>{let t=e;return t.persistence.runTransaction("Get highest unacknowledged batch id","readonly",e=>t.mutationQueue.getHighestUnacknowledgedBatchId(e))})(n.localStore);var i;e===Ir?r.resolve():((i=n.ac.get(e)||[]).push(r),n.ac.set(e,i))}catch(t){let e=g6(t,"Initialization of waitForPendingWrites() operation failed");r.reject(e)}}function z6(e,t){(e.ac.get(t)||[]).forEach(e=>{e.resolve()}),e.ac.delete(t)}function H6(e,t,r){var n=e;let i=n.oc[n.currentUser.toKey()];if(i){let e=i.get(t);e&&(r?e.reject(r):e.resolve(),i=i.remove(t)),n.oc[n.currentUser.toKey()]=i}}function K6(t,e,r=null){t.sharedClientState.removeLocalQueryTarget(e);for(var n of t.tc.get(e))t.ec.delete(n),r&&t.Xu.Ec(n,r);t.tc.delete(e),t.isPrimaryClient&&t._c.s_(e).forEach(e=>{t._c.containsKey(e)||$6(t,e)})}function $6(e,t){e.nc.delete(t.path.canonicalString());var r=e.rc.get(t);null!==r&&(X2(e.remoteStore,r),e.rc=e.rc.remove(t),e.sc.delete(r),Y6(e))}function Q6(e,t,r){for(var n of r)n instanceof D6?(e._c.addReference(n.key,t),i=e,s=n,o=a=void 0,a=s.key,o=a.path.canonicalString(),i.rc.get(a)||i.nc.has(o)||(m(k6,"New document in limbo: "+a),i.nc.add(o),Y6(i))):n instanceof O6?(m(k6,"Document no longer in limbo: "+n.key),e._c.removeReference(n.key,t),e._c.containsKey(n.key)||$6(e,n.key)):A(19791,{hc:n});var i,s,a,o}function Y6(e){for(;0<e.nc.size&&e.rc.size<e.maxConcurrentLimboResolutions;){var t=e.nc.values().next().value,t=(e.nc.delete(t),new x(T.fromString(t))),r=e.uc.next();e.sc.set(r,new P6(t)),e.rc=e.rc.insert(t,r),W2(e.remoteStore,new gh(Zs(Ys(t.path)),r,"TargetPurposeLimboResolution",Sr.ce))}}async function W6(e,t,n){let s=e,i=[],a=[],o=[];if(!s.ec.isEmpty()){s.ec.forEach((e,r)=>{o.push(s.lc(r,t,n).then(e=>{var t;(e||n)&&s.isPrimaryClient&&(t=e?!e.fromCache:n?.targetChanges.get(r.targetId)?.current,s.sharedClientState.updateQueryState(r.targetId,t?"current":"not-current")),e&&(i.push(e),t=l2.vo(r.targetId,e),a.push(t))}))}),await Promise.all(o),s.Xu.zn(i);{var r=s.localStore,u=a;let i=r;try{await i.persistence.runTransaction("notifyLocalViewChanges","readwrite",r=>D.forEach(u,t=>D.forEach(t.wo,e=>i.persistence.referenceDelegate.addReference(r,t.targetId,e)).next(()=>D.forEach(t.bo,e=>i.persistence.referenceDelegate.removeReference(r,t.targetId,e)))))}catch(r){if(!mr(r))throw r;m(p2,"Failed to update sequence numbers: "+r)}for(let e of u){let n=e.targetId;if(!e.fromCache){let e=i.$o.get(n),t=e.snapshotVersion,r=e.withLastLimboFreeSnapshotVersion(t);i.$o=i.$o.insert(n,r)}}}}}async function X6(e,t,r,n){var i=e,s=await((e,r)=>{let n=e,i=n.mutationQueue;return n.persistence.runTransaction("Lookup mutation documents","readonly",t=>i.ps(t,r).next(e=>e?n.localDocuments.getDocuments(t,e):D.resolve(null)))})(i.localStore,t);null!==s?("pending"===r?await o6(i.remoteStore):"acknowledged"===r||"rejected"===r?(H6(i,t,n||null),z6(i,t),i.localStore.mutationQueue.bs(t)):A(6720,"Unknown batchState",{Tc:r}),await W6(i,s)):m(k6,"Cannot apply mutation batch with id: "+t)}async function J6(r,e){var n,i,s,a=r,o=[],u=[];for(let r of e){let t,e=a.tc.get(r);if(e&&0!==e.length){t=await T2(a.localStore,sh(e[0])?e[0]:Zs(e[0]));for(let r of e){let e=a.ec.get(r),t=(n=e,s=i=void 0,s=await S2((i=a).localStore,n.query,!0),s=n.view.Ju(s),i.isPrimaryClient&&Q6(i,n.targetId,s.ju),await s);t.snapshot&&u.push(t.snapshot)}}else{let e=await I2(a.localStore,r);t=await T2(a.localStore,e),await F6(a,Z6(e),r,!1,t.resumeToken)}o.push(t)}return a.Xu.zn(u),o}function Z6(e){return Gs(e)?e:Qs(e.path,e.collectionGroup,e.orderBy,e.filters,e.limit,"F",e.startAt,e.endAt)}async function e0(e,r,n,t){var i=e;if(i.cc)m(k6,"Ignoring unexpected query state notification.");else{var s,a=i.tc.get(r);if(a&&0<a.length)switch(n){case"current":case"not-current":{let e;if(sh(a[0]))switch(pu(a[0])){case"collection_group":case"collection":e=await A2(i.localStore,mu(a[0]));break;case"documents":e=await((e,t)=>{let r=e,n=V(...vu(t).map(e=>x.fromPath(e)));return r.persistence.runTransaction("Get documents for pipeline","readonly",e=>r.Qo.getEntries(e,n)).then(e=>e)})(i.localStore,a[0]);break;default:ht(""),e=da()}else e=await A2(i.localStore,(s=a[0]).collectionGroup||(s.path.length%2==1?s.path.lastSegment():s.path.get(s.path.length-2)));let t=Sa.createSynthesizedRemoteEventForCurrentChange(r,"current"===n,k.EMPTY_BYTE_STRING);await W6(i,e,t);break}case"rejected":await b2(i.localStore,r,!0),K6(i,r,t);break;default:A(64155,n)}}}function t0(e){var t=e;return t.remoteStore.remoteSyncer.applyRemoteEvent=B6.bind(null,t),t.remoteStore.remoteSyncer.getRemoteKeysForTarget=(function(e,t){let n=e,r=n.sc.get(t);if(r&&r.Zu)return V().add(r.key);{let r=V(),e=n.tc.get(t);if(e)for(let t of e??[]){let e=n.ec.get(t);r=r.unionWith(e.view.Uu)}return r}}).bind(null,t),t.remoteStore.remoteSyncer.rejectListen=(async function(e,n,t){let i=e,r=(i.sharedClientState.updateQueryState(n,"rejected",t),i.sc.get(n)),s=r&&r.key;if(s){let e=new O(x.comparator),t=(e=e.insert(s,Vs.newNoDocument(s,N.min())),V().add(s)),r=new Sa(N.min(),new Map,new O(C),e,ha,t);await B6(i,r),i.rc=i.rc.remove(s),i.sc.delete(n),Y6(i)}else await b2(i.localStore,n,!1).then(()=>K6(i,n,t)).catch(er)}).bind(null,t),t.Xu.zn=(function(r,e){var n=r;let i=!1;for(let r of e){let e=r.query,t=n.queries.get(e);if(t){for(let e of t.Eu)e.Iu(r)&&(i=!0);t.lu=r}}i&&S6(n)}).bind(null,t.eventManager),t.Xu.Ec=(function(e,t,r){var n=e,i=n.queries.get(t);if(i)for(let e of i.Eu)e.onError(r);n.queries.delete(t)}).bind(null,t.eventManager),t}function r0(e){var t=e;return t.remoteStore.remoteSyncer.applySuccessfulWrite=(async function(e,t){var r=e,n=t.batch.batchId;try{let e=await y2(r.localStore,t);H6(r,n,null),z6(r,n),r.sharedClientState.updateMutationState(n,"acknowledged"),await W6(r,e)}catch(e){await er(e)}}).bind(null,t),t.remoteStore.remoteSyncer.rejectFailedWrite=G6.bind(null,t),t}function n0(e,t,r){let n=e;(async(e,r,n)=>{try{var i=await r.getMetadata();if(await((e,t)=>{let r=e,n=ja(t.createTime);return r.persistence.runTransaction("hasNewerBundle","readonly",e=>r.w_.getBundleMetadata(e,t.id)).then(e=>!!e&&0<=e.createTime.compareTo(n))})(e.localStore,i))return await r.close(),n._completeWith({taskState:"Success",documentsLoaded:i.totalDocuments,bytesLoaded:i.totalBytes,totalDocuments:i.totalDocuments,totalBytes:i.totalBytes}),Promise.resolve(new Set);n._updateProgress(N6(i));var s=new x6(i,r.serializer);let t=await r.Pc();for(;t;){let e=await s.o(t);e&&n._updateProgress(e),t=await r.Pc()}var a=await s.xu(e.localStore);return await W6(e,a.Fu,void 0),await((e,t)=>{let r=e;return r.persistence.runTransaction("Save bundle","readwrite",e=>r.w_.saveBundleMetadata(e,t))})(e.localStore,i),n._completeWith(a.progress),Promise.resolve(a.Cu)}catch(e){return ht(k6,"Loading bundle failed with "+e),n._failWith(e),Promise.resolve(new Set)}})(n,t,r).then(e=>{n.sharedClientState.notifyBundleLoaded(e)})}class i0{constructor(){this.kind="memory",this.synchronizeTabs=!1}async initialize(e){this.serializer=v1(e.databaseInfo.databaseId),this.sharedClientState=this.Rc(e),this.persistence=this.Ic(e),await this.persistence.start(),this.localStore=this.Ac(e),this.gcScheduler=this.Vc(e,this.localStore),this.indexBackfillerScheduler=this.dc(e,this.localStore)}Vc(e,t){return null}dc(e,t){return null}Ac(e){return m2(this.persistence,new d2,e.initialUser,this.serializer)}Ic(e){return new Wc(Jc.C_,this.serializer)}Rc(e){return new q2}async terminate(){this.gcScheduler?.stop(),this.indexBackfillerScheduler?.stop(),this.sharedClientState.shutdown(),await this.persistence.shutdown()}}i0.provider={build:()=>new i0};class s0 extends i0{constructor(e){super(),this.cacheSizeBytes=e}Vc(e,t){v(this.persistence.referenceDelegate instanceof Zc,46915);var r=this.persistence.referenceDelegate.garbageCollector;return new K1(r,e.asyncQueue,t)}Ic(e){let t=void 0!==this.cacheSizeBytes?G1.withCacheSize(this.cacheSizeBytes):G1.DEFAULT;return new Wc(e=>Zc.C_(e,t),this.serializer)}}class a0 extends i0{constructor(e,t,r){super(),this.fc=e,this.cacheSizeBytes=t,this.forceOwnership=r,this.kind="persistent",this.synchronizeTabs=!1}async initialize(e){await super.initialize(e),await this.fc.initialize(this,e),await r0(this.fc.syncEngine),await o6(this.fc.remoteStore),await this.persistence._o(()=>(this.gcScheduler&&!this.gcScheduler.started&&this.gcScheduler.start(),this.indexBackfillerScheduler&&!this.indexBackfillerScheduler.started&&this.indexBackfillerScheduler.start(),Promise.resolve()))}Ac(e){return m2(this.persistence,new d2,e.initialUser,this.serializer)}Vc(e,t){var r=this.persistence.referenceDelegate.garbageCollector;return new K1(r,e.asyncQueue,t)}dc(e,t){var r=new br(t,this.persistence);return new Tr(e.asyncQueue,r)}Ic(e){var t=u2(e.databaseInfo.databaseId,e.databaseInfo.persistenceKey),r=void 0!==this.cacheSizeBytes?G1.withCacheSize(this.cacheSizeBytes):G1.DEFAULT;return new s2(this.synchronizeTabs,t,e.clientId,r,e.asyncQueue,G2(),j2(),this.serializer,this.sharedClientState,!!this.forceOwnership)}Rc(e){return new q2}}class o0 extends a0{constructor(e,t){super(e,t,!1),this.fc=e,this.cacheSizeBytes=t,this.synchronizeTabs=!0}async initialize(e){await super.initialize(e);var t=this.fc.syncEngine;this.sharedClientState instanceof B2&&(this.sharedClientState.syncEngine={Na:X6.bind(null,t),La:e0.bind(null,t),Ba:(async function(e,t,n){let i=t0(e);if(i.cc){for(let r of t)if(i.tc.has(r)&&i.sharedClientState.isActiveQueryTarget(r))m(k6,"Adding an already active target "+r);else{let e=await I2(i.localStore,r),t=await T2(i.localStore,e);await F6(i,Z6(e),t.targetId,!1,t.resumeToken),W2(i.remoteStore,t)}for(let r of n)i.tc.has(r)&&await b2(i.localStore,r,!1).then(()=>{X2(i.remoteStore,r),K6(i,r)}).catch(er)}}).bind(null,t),po:(function(e){return e.localStore.persistence.po()}).bind(null,t),Ma:(async function(e,t){let r=e;return A2(r.localStore,t).then(e=>W6(r,e))}).bind(null,t)},await this.sharedClientState.start()),await this.persistence._o(async e=>{{var t=this.fc.syncEngine,s=e;let i=t;if(t0(i),r0(i),!0===s&&!0!==i.cc){let e=i.sharedClientState.getAllActiveQueryTargets(),t=await J6(i,e.toArray());i.cc=!0,await c6(i.remoteStore,!0);for(let e of t)W2(i.remoteStore,e)}else if(!1===s&&!1!==i.cc){let r=[],n=Promise.resolve();i.tc.forEach((e,t)=>{i.sharedClientState.isLocalQueryTarget(t)?r.push(t):n=n.then(()=>(K6(i,t),b2(i.localStore,t,!0))),X2(i.remoteStore,t)}),await n,await J6(i,r);{s=i;let r=s;r.sc.forEach((e,t)=>{X2(r.remoteStore,t)}),r._c.__(),r.sc=new Map,r.rc=new O(x.comparator)}i.cc=!1,await c6(i.remoteStore,!1)}}await 0,this.gcScheduler&&(e&&!this.gcScheduler.started?this.gcScheduler.start():e||this.gcScheduler.stop()),this.indexBackfillerScheduler&&(e&&!this.indexBackfillerScheduler.started?this.indexBackfillerScheduler.start():e||this.indexBackfillerScheduler.stop())})}Rc(e){var t,r=G2();if(B2.C(r))return t=u2(e.databaseInfo.databaseId,e.databaseInfo.persistenceKey),new B2(r,e.asyncQueue,t,e.clientId,e.initialUser);throw new E(_.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.")}}class u0{async initialize(e,t){this.localStore||(this.localStore=e.localStore,this.sharedClientState=e.sharedClientState,this.datastore=this.createDatastore(t),this.remoteStore=this.createRemoteStore(t),this.eventManager=this.createEventManager(t),this.syncEngine=this.createSyncEngine(t,!e.synchronizeTabs),this.sharedClientState.onlineStateHandler=e=>q6(this.syncEngine,e,1),this.remoteStore.remoteSyncer.handleCredentialChange=(async function(e,t){var r,n,i=e;if(!i.currentUser.isEqual(t)){m(k6,"User change. New user:",t.toKey());let e=await v2(i.localStore,t);i.currentUser=t,n="'waitForPendingWrites' promise is rejected due to a user change.",(r=i).ac.forEach(e=>{e.forEach(e=>{e.reject(new E(_.CANCELLED,n))})}),r.ac.clear(),i.sharedClientState.handleUserChange(t,e.removedBatchIds,e.addedBatchIds),await W6(i,e.zo)}}).bind(null,this.syncEngine),await c6(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(e){return new _6}createDatastore(e){var t,r,n,i=v1(e.databaseInfo.databaseId),s=(t=e.databaseInfo,new k1(t));return t=e.authCredentials,e=e.appCheckCredentials,r=s,n=i,new U1(t,e,r,n)}createRemoteStore(e){return t=this.localStore,r=this.datastore,e=e.asyncQueue,n=e=>q6(this.syncEngine,e,0),i=new(I1.C()?I1:b1),new K2(t,r,e,n,i);var t,r,n,i}createSyncEngine(e,t){return r=this.localStore,n=this.remoteStore,i=this.eventManager,s=this.sharedClientState,a=e.initialUser,e=e.maxConcurrentLimboResolutions,t=t,o=new M6(r,n,i,s,a,e),t&&(o.cc=!0),o;var r,n,i,s,a,o}async terminate(){var e,t;e=this.remoteStore,t=e,m(H2,"RemoteStore shutting down."),t.tu.add(5),await Q2(t),t.ru.shutdown(),await!t.iu.set("Unknown"),this.datastore?.terminate(),this.eventManager?.terminate()}}function l0(t,r=10240){let n=0;return{async read(){var e;return n<t.byteLength?(e={value:t.slice(n,n+r),done:!1},n+=r,e):{done:!0}},async cancel(){},releaseLock(){},closed:Promise.resolve()}}u0.provider={build:()=>new u0};class h0{constructor(e){this.observer=e,this.muted=!1}next(e){this.muted||this.observer.next&&this.mc(this.observer.next,e)}error(e){this.muted||(this.observer.error?this.mc(this.observer.error,e):lt("Uncaught Error in snapshot listener:",e.toString()))}gc(){this.muted=!0}mc(e,t){setTimeout(()=>{this.muted||e(t)},0)}}class c0{constructor(e,t){this.yc=e,this.serializer=t,this.metadata=new pt,this.buffer=new Uint8Array,this.wc=new TextDecoder("utf-8"),this.bc().then(e=>{e&&e.yu()?this.metadata.resolve(e.gu.metadata):this.metadata.reject(new Error(`The first element of the bundle is not a metadata, it is
             `+JSON.stringify(e?.gu)))},e=>this.metadata.reject(e))}close(){return this.yc.cancel()}async getMetadata(){return this.metadata.promise}async Pc(){return await this.getMetadata(),this.bc()}async bc(){var e,t,r=await this.vc();return null===r?null:(t=this.wc.decode(r),e=Number(t),isNaN(e)&&this.Sc(`length string (${t}) is not valid number`),t=await this.Dc(e),new A6(JSON.parse(t),r.length+e))}xc(){return this.buffer.findIndex(e=>e==="{".charCodeAt(0))}async vc(){for(;this.xc()<0&&!await this.Cc(););var e,t;return 0===this.buffer.length?null:((e=this.xc())<0&&this.Sc("Reached the end of bundle when a length string is expected."),t=this.buffer.slice(0,e),this.buffer=this.buffer.slice(e),t)}async Dc(e){for(;this.buffer.length<e;)await this.Cc()&&this.Sc("Reached the end of bundle when more is expected.");var t=this.wc.decode(this.buffer.slice(0,e));return this.buffer=this.buffer.slice(e),t}Sc(e){throw this.yc.cancel(),new Error("Invalid bundle format: "+e)}async Cc(){var e,t=await this.yc.read();return t.done||((e=new Uint8Array(this.buffer.length+t.value.length)).set(this.buffer),e.set(t.value,this.buffer.length),this.buffer=e),t.done}}class d0{constructor(e){this.datastore=e,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastTransactionError=null,this.writtenDocs=new Set}async lookup(e){if(this.ensureCommitNotCalled(),0<this.mutations.length)throw this.lastTransactionError=new E(_.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes."),this.lastTransactionError;var t=await(async(e,t)=>{let u=e,r={documents:t.map(e=>$a(u.serializer,e))},n=await u.$t("BatchGetDocuments",u.serializer.databaseId,T.emptyPath(),r,t.length),l=new Map,i=(n.forEach(e=>{t=u.serializer;var t,r,n,i,s,a,o="found"in(e=e)?(r=t,v(!!(n=e).found,43571),n.found.name,n.found.updateTime,i=Qa(r,n.found.name),s=ja(n.found.updateTime),o=n.found.createTime?ja(n.found.createTime):N.min(),a=new Ui({mapValue:{fields:n.found.fields}}),Vs.newFoundDocument(i,s,o,a)):"missing"in e?(r=t,v(!!(n=e).missing,3894),v(!!n.readTime,22933),i=Qa(r,n.missing),s=ja(n.readTime),Vs.newNoDocument(i,s)):A(7234,{result:e});l.set(o.key.toString(),o)}),[]);return t.forEach(e=>{var t=l.get(e.toString());v(!!t,55234,{key:e}),i.push(t)}),i})(this.datastore,e);return t.forEach(e=>this.recordVersion(e)),t}set(e,t){this.write(t.toMutation(e,this.precondition(e))),this.writtenDocs.add(e.toString())}update(e,t){try{this.write(t.toMutation(e,this.preconditionForUpdate(e)))}catch(e){this.lastTransactionError=e}this.writtenDocs.add(e.toString())}delete(e){this.write(new ms(e,this.precondition(e))),this.writtenDocs.add(e.toString())}async commit(){if(this.ensureCommitNotCalled(),this.lastTransactionError)throw this.lastTransactionError;let t=this.readVersions;this.mutations.forEach(e=>{t.delete(e.key.toString())}),t.forEach((e,t)=>{var r=x.fromPath(t);this.mutations.push(new vs(r,this.precondition(r)))});{var r=this.datastore,n=this.mutations;let t=r,e={writes:n.map(e=>t1(t.serializer,e))};await t.Bt("Commit",t.serializer.databaseId,T.emptyPath(),e)}await 0,this.committed=!0}recordVersion(e){let t;if(e.isFoundDocument())t=e.version;else{if(!e.isNoDocument())throw A(50498,{Oc:e.constructor.name});t=N.min()}var r=this.readVersions.get(e.key.toString());if(r){if(!t.isEqual(r))throw new E(_.ABORTED,"Document version changed between two reads.")}else this.readVersions.set(e.key.toString(),t)}precondition(e){var t=this.readVersions.get(e.toString());return!this.writtenDocs.has(e.toString())&&t?t.isEqual(N.min())?ss.exists(!1):ss.updateTime(t):ss.none()}preconditionForUpdate(e){var t=this.readVersions.get(e.toString());if(this.writtenDocs.has(e.toString())||!t)return ss.exists(!0);if(t.isEqual(N.min()))throw new E(_.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return ss.updateTime(t)}write(e){this.ensureCommitNotCalled(),this.mutations.push(e)}ensureCommitNotCalled(){}}class p0{constructor(e,t,r,n,i){this.asyncQueue=e,this.datastore=t,this.options=r,this.updateFunction=n,this.deferred=i,this.Mc=r.maxAttempts,this.xn=new L1(this.asyncQueue,"transaction_retry")}Nc(){--this.Mc,this.Lc()}Lc(){this.xn.mn(async()=>{let t=new d0(this.datastore),e=this.Bc(t);e&&e.then(e=>{this.asyncQueue.enqueueAndForget(()=>t.commit().then(()=>{this.deferred.resolve(e)}).catch(e=>{this.Uc(e)}))}).catch(e=>{this.Uc(e)})})}Bc(e){try{var t=this.updateFunction(e);return!Ar(t)&&t.catch&&t.then?t:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(e){return this.deferred.reject(e),null}}Uc(e){0<this.Mc&&this.kc(e)?(--this.Mc,this.asyncQueue.enqueueAndForget(()=>(this.Lc(),Promise.resolve()))):this.deferred.reject(e)}kc(e){var t;return"FirebaseError"===e?.name&&("aborted"===(t=e.code)||"failed-precondition"===t||"already-exists"===t||!oa(t))}}let f0="FirestoreClient";class g0{constructor(e,t,r,n,i){this.authCredentials=e,this.appCheckCredentials=t,this.asyncQueue=r,this._databaseInfo=n,this.user=st.UNAUTHENTICATED,this.clientId=Tt.newId(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this._uninitializedComponentsProvider=i,this.authCredentials.start(r,async e=>{m(f0,"Received user=",e.uid),await this.authCredentialListener(e),this.user=e}),this.appCheckCredentials.start(r,e=>(m(f0,"Received new app check token=",e),this.appCheckCredentialListener(e,this.user)))}get configuration(){return{asyncQueue:this.asyncQueue,databaseInfo:this._databaseInfo,clientId:this.clientId,authCredentials:this.authCredentials,appCheckCredentials:this.appCheckCredentials,initialUser:this.user,maxConcurrentLimboResolutions:100}}setCredentialChangeListener(e){this.authCredentialListener=e}setAppCheckTokenChangeListener(e){this.appCheckCredentialListener=e}terminate(){this.asyncQueue.enterRestrictedMode();let r=new pt;return this.asyncQueue.enqueueAndForgetEvenWhileRestricted(async()=>{try{this._onlineComponents&&await this._onlineComponents.terminate(),this._offlineComponents&&await this._offlineComponents.terminate(),this.authCredentials.shutdown(),this.appCheckCredentials.shutdown(),r.resolve()}catch(e){var t=g6(e,"Failed to shutdown persistence");r.reject(t)}}),r.promise}}async function m0(e,t){e.asyncQueue.verifyOperationInProgress(),m(f0,"Initializing OfflineComponentProvider");var r=e.configuration;await t.initialize(r);let n=r.initialUser;e.setCredentialChangeListener(async e=>{n.isEqual(e)||(await v2(t.localStore,e),n=e)}),t.persistence.setDatabaseDeletedListener(()=>e.terminate()),e._offlineComponents=t}async function v0(e,r){e.asyncQueue.verifyOperationInProgress();var t=await y0(e);m(f0,"Initializing OnlineComponentProvider"),await r.initialize(t,e.configuration),e.setCredentialChangeListener(e=>h6(r.remoteStore,e)),e.setAppCheckTokenChangeListener((e,t)=>h6(r.remoteStore,t)),e._onlineComponents=r}async function y0(t){if(!t._offlineComponents)if(t._uninitializedComponentsProvider){m(f0,"Using user provided OfflineComponentProvider");try{await m0(t,t._uninitializedComponentsProvider._offline)}catch(e){var r=e;if(!("FirebaseError"===(n=r).name?n.code===_.FAILED_PRECONDITION||n.code===_.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&n instanceof DOMException)||22===n.code||20===n.code||11===n.code))throw r;ht("Error using user provided cache. Falling back to memory cache: "+r),await m0(t,new i0)}}else m(f0,"Using default OfflineComponentProvider"),await m0(t,new s0(void 0));var n;return t._offlineComponents}async function w0(e){return e._onlineComponents||(e._uninitializedComponentsProvider?(m(f0,"Using user provided OnlineComponentProvider"),await v0(e,e._uninitializedComponentsProvider._online)):(m(f0,"Using default OnlineComponentProvider"),await v0(e,new u0))),e._onlineComponents}function _0(e){return y0(e).then(e=>e.persistence)}function E0(e){return y0(e).then(e=>e.localStore)}function T0(e){return w0(e).then(e=>e.remoteStore)}function b0(e){return w0(e).then(e=>e.syncEngine)}async function S0(e){var t=await w0(e),r=t.eventManager;return r.onListen=(async function(e,t,r=!0){var n=t0(e);let i;var s=n.ec.get(t);return i=s?(n.sharedClientState.addLocalQueryTarget(s.targetId),s.view.Yu()):await V6(n,t,r,!0)}).bind(null,t.syncEngine),r.onUnlisten=(async function(e,t,r){let n=e,i=n.ec.get(t),s=n.tc.get(i.targetId);1<s.length?(n.tc.set(i.targetId,s.filter(e=>!uh(e,t))),n.ec.delete(t)):n.isPrimaryClient?(n.sharedClientState.removeLocalQueryTarget(i.targetId),n.sharedClientState.isActiveQueryTarget(i.targetId)||await b2(n.localStore,i.targetId,!1).then(()=>{n.sharedClientState.clearQueryState(i.targetId),r&&X2(n.remoteStore,i.targetId),K6(n,i.targetId)}).catch(er)):(K6(n,i.targetId),await b2(n.localStore,i.targetId,!0))}).bind(null,t.syncEngine),r.onFirstRemoteStoreListen=(async function(e,t){await V6(t0(e),t,!0,!1)}).bind(null,t.syncEngine),r.onLastRemoteStoreUnlisten=(async function(e,t){var r=e,n=r.ec.get(t),i=r.tc.get(n.targetId);r.isPrimaryClient&&1===i.length&&(r.sharedClientState.removeLocalQueryTarget(n.targetId),X2(r.remoteStore,n.targetId))}).bind(null,t.syncEngine),r}function I0(r){return r.asyncQueue.enqueue(async()=>{var e=await _0(r),t=await T0(r);return e.setNetworkEnabled(!1),(async e=>{var t=e;t.tu.add(0),await Q2(t),t.iu.set("Offline")})(t)})}function A0(e,t){let r=new pt;return e.asyncQueue.enqueueAndForget(async()=>(async(e,t,r)=>{try{var n=await((e,t)=>{let r=e;return r.persistence.runTransaction("read document","readonly",e=>r.localDocuments.getDocument(e,t))})(e,t);n.isFoundDocument()?r.resolve(n):n.isNoDocument()?r.resolve(null):r.reject(new E(_.UNAVAILABLE,"Failed to get document from cache. (However, this document may exist on the server. Run again without setting 'source' in the GetOptions to attempt to retrieve the document from the server.)"))}catch(e){n=g6(e,`Failed to get document '${t} from cache`);r.reject(n)}})(await E0(e),t,r)),r.promise}function C0(e,t,l={}){let h=new pt;return e.asyncQueue.enqueueAndForget(async()=>{{var i=await S0(e),s=e.asyncQueue,a=t,o=l,u=h;let r=new h0({next:e=>{r.gc(),s.enqueueAndForget(()=>b6(i,n));var t=e.docs.has(a);!t&&e.fromCache?u.reject(new E(_.UNAVAILABLE,"Failed to get document because the client is offline.")):t&&e.fromCache&&o&&"server"===o.source?u.reject(new E(_.UNAVAILABLE,'Failed to get document from server. (However, this document does exist in the local cache. Run again without setting source to "server" to retrieve the cached document.)')):u.resolve(e)},error:e=>u.reject(e)}),n=new I6(Ys(a.path),r,{includeMetadataChanges:!0,waitForSyncWhenOnline:!0});return T6(i,n)}}),h.promise}function x0(e,t){let r=new pt;return e.asyncQueue.enqueueAndForget(async()=>(async(e,t,r)=>{try{var n=await S2(e,t,!0),i=new R6(t,n.Jo),s=i.ku(n.documents),a=i.applyChanges(s,!1);r.resolve(a.snapshot)}catch(e){n=g6(e,`Failed to execute query '${t} against cache`);r.reject(n)}})(await E0(e),t,r)),r.promise}function N0(o,u,l={}){let h=new pt;return o.asyncQueue.enqueueAndForget(async()=>{{var n=await S0(o),i=o.asyncQueue,e=u,s=l,a=h;let t=new h0({next:e=>{t.gc(),i.enqueueAndForget(()=>b6(n,r)),e.fromCache&&"server"===s.source?a.reject(new E(_.UNAVAILABLE,'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')):a.resolve(e)},error:e=>a.reject(e)}),r=new I6(!1?ch(e):e,t,{includeMetadataChanges:!0,waitForSyncWhenOnline:!0});return T6(n,r)}}),h.promise}function D0(r,e){let n=new h0(e);return r.asyncQueue.enqueueAndForget(async()=>{return e=await S0(r),t=n,e.Pu.add(t),void t.next();var e,t}),()=>{n.gc(),r.asyncQueue.enqueueAndForget(async()=>{var e,t;e=await S0(r),t=n,e.Pu.delete(t)})}}function O0(t,r,n){let i=new pt;return t.asyncQueue.enqueueAndForget(async()=>{var e=await w0(t).then(e=>e.datastore);new p0(t.asyncQueue,e,n,r,i).Nc()}),i.promise}function R0(e,t,r,n){r=r,t=v1(t),s="string"==typeof r?ya().encode(r):r,r=((e,t)=>{if(e instanceof Uint8Array)return l0(e,t);if(e instanceof ArrayBuffer)return l0(new Uint8Array(e),t);if(e instanceof ReadableStream)return e.getReader();throw new Error("Source of `toByteStreamReader` has to be a ArrayBuffer or ReadableStream")})(s),t=t;let i=new c0(r,t);var s;e.asyncQueue.enqueueAndForget(async()=>{n0(await b0(e),i,n)})}function k0(n,i){return n.asyncQueue.enqueue(async()=>{{var e=await E0(n),r=i;let t=e;return t.persistence.runTransaction("Get named query","readonly",e=>t.w_.getNamedQuery(e,r))}})}let L0="AsyncQueue";class P0{constructor(e=Promise.resolve()){this.qc=[],this.$c=!1,this.Kc=[],this.Wc=null,this.Qc=!1,this.Gc=!1,this.zc=[],this.xn=new L1(this,"async_queue_retry"),this.jc=()=>{var e=j2();e&&m(L0,"Visibility state changed to "+e.visibilityState),this.xn.gn()},this.Hc=e;var t=j2();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.jc)}get isShuttingDown(){return this.$c}enqueueAndForget(e){this.enqueue(e)}enqueueAndForgetEvenWhileRestricted(e){this.Jc(),this.Yc(e)}enterRestrictedMode(e){var t;this.$c||(this.$c=!0,this.Gc=e||!1,(t=j2())&&"function"==typeof t.removeEventListener&&t.removeEventListener("visibilitychange",this.jc))}enqueue(e){if(this.Jc(),this.$c)return new Promise(()=>{});let t=new pt;return this.Yc(()=>this.$c&&this.Gc?Promise.resolve():(e().then(t.resolve,t.reject),t.promise)).then(()=>t.promise)}enqueueRetryable(e){this.enqueueAndForget(()=>(this.qc.push(e),this.Zc()))}async Zc(){if(0!==this.qc.length){try{await this.qc[0](),this.qc.shift(),this.xn.reset()}catch(e){if(!mr(e))throw e;m(L0,"Operation failed with retryable error: "+e)}0<this.qc.length&&this.xn.mn(()=>this.Zc())}}Yc(e){var t=this.Hc.then(()=>(this.Qc=!0,e().catch(e=>{throw this.Wc=e,this.Qc=!1,lt("INTERNAL UNHANDLED ERROR: ",M0(e)),e}).then(e=>(this.Qc=!1,e))));return this.Hc=t}enqueueAfterDelay(e,t,r){this.Jc(),-1<this.zc.indexOf(e)&&(t=0);var n=f6.createAndSchedule(this,e,t,r,e=>this.Xc(e));return this.Kc.push(n),n}Jc(){this.Wc&&A(47125,{el:M0(this.Wc)})}verifyOperationInProgress(){}async tl(){for(var e;await(e=this.Hc),e!==this.Hc;);}nl(e){for(var t of this.Kc)if(t.timerId===e)return!0;return!1}rl(t){return this.tl().then(()=>{this.Kc.sort((e,t)=>e.targetTimeMs-t.targetTimeMs);for(var e of this.Kc)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.tl()})}il(e){this.zc.push(e)}Xc(e){var t=this.Kc.indexOf(e);this.Kc.splice(t,1)}}function M0(e){let t=e.message||"";return t=e.stack?e.stack.includes(e.message)?e.stack:e.message+"\n"+e.stack:t}class V0{constructor(){this._progressObserver={},this._taskCompletionResolver=new pt,this._lastProgress={taskState:"Running",totalBytes:0,totalDocuments:0,bytesLoaded:0,documentsLoaded:0}}onProgress(e,t,r){this._progressObserver={next:e,error:t,complete:r}}catch(e){return this._taskCompletionResolver.promise.catch(e)}then(e,t){return this._taskCompletionResolver.promise.then(e,t)}_completeWith(e){this._updateProgress(e),this._progressObserver.complete&&this._progressObserver.complete(),this._taskCompletionResolver.resolve(e)}_failWith(e){this._lastProgress.taskState="Error",this._progressObserver.next&&this._progressObserver.next(this._lastProgress),this._progressObserver.error&&this._progressObserver.error(e),this._taskCompletionResolver.reject(e)}_updateProgress(e){this._lastProgress=e,this._progressObserver.next&&this._progressObserver.next(e)}}var F0,U0,B0,q0;class G0 extends X1{constructor(e,t,r,n){super(e,t,r,n),this.type="firestore",this._queue=new P0,this._persistenceKey=n?.name||"[DEFAULT]"}async _terminate(){var e;this._firestoreClient&&(e=this._firestoreClient.terminate(),this._queue=new P0(e),this._firestoreClient=void 0,await e)}}function j0(e){if(e._terminated)throw new E(_.FAILED_PRECONDITION,"The client has already been terminated.");return e._firestoreClient||z0(e),e._firestoreClient}function z0(e){var t,r,n,i,s,a=e._freezeSettings(),o=(s=e._databaseId,t=e._app?.options.appId||"",r=e._persistenceKey,n=e._app?.options.apiKey,i=a,new ai(s,t,r,i.host,i.ssl,i.experimentalForceLongPolling,i.experimentalAutoDetectLongPolling,T1(i.experimentalLongPollingOptions),i.useFetchStreams,i.isUsingEmulator,n));e._componentsProvider||a.localCache?._offlineComponentProvider&&a.localCache?._onlineComponentProvider&&(e._componentsProvider={_offline:a.localCache._offlineComponentProvider,_online:a.localCache._onlineComponentProvider}),e._firestoreClient=new g0(e._authCredentials,e._appCheckCredentials,e._queue,o,e._componentsProvider&&(s=e._componentsProvider,a=s?._online.build(),{_offline:s?._offline.build(a),_online:a}))}function H0(e,t,r){if((e=y(e,G0))._firestoreClient||e._terminated)throw new E(_.FAILED_PRECONDITION,"Firestore has already been started and persistence can no longer be enabled. You can only enable persistence before calling any other methods on a Firestore object.");if(e._componentsProvider||e._getSettings().localCache)throw new E(_.FAILED_PRECONDITION,"SDK cache is already specified.");e._componentsProvider={_online:t,_offline:r},z0(e)}function K0(r){if(r._initialized&&!r._terminated)throw new E(_.FAILED_PRECONDITION,"Persistence can only be cleared before a Firestore instance is initialized or after it is terminated.");let n=new pt;return r._queue.enqueueAndForgetEvenWhileRestricted(async()=>{try{e=u2(r._databaseId,r._persistenceKey),await(nr.C()?(t=e+i2,void await nr.delete(t)):Promise.resolve()),n.resolve()}catch(e){n.reject(e)}var e,t}),n.promise}function $0(e){return(r=j0(e=y(e,G0))).asyncQueue.enqueue(async()=>{var e=await _0(r),t=await T0(r);return e.setNetworkEnabled(!0),(e=t).tu.delete(0),$2(e)});var r}class Q0{convertValue(e,t="none"){switch(vi(e)){case 0:return null;case 1:return e.booleanValue;case 2:return L(e.integerValue||e.doubleValue);case 3:return this.convertTimestamp(e.timestampValue);case 4:return this.convertServerTimestamp(e,t);case 5:return e.stringValue;case 6:return this.convertBytes(Jn(e.bytesValue));case 7:return this.convertReference(e.referenceValue);case 8:return this.convertGeoPoint(e.geoPointValue);case 9:return this.convertArray(e.arrayValue,t);case 11:return this.convertObject(e.mapValue,t);case 10:return this.convertVectorValue(e.mapValue);default:throw A(62114,{value:e})}}convertObject(e,t){return this.convertObjectMap(e.fields,t)}convertObjectMap(e,r="none"){let n={};return $n(e,(e,t)=>{n[e]=this.convertValue(t,r)}),n}convertVectorValue(e){var t=e.fields?.[pi].arrayValue?.values?.map(e=>L(e.doubleValue));return new so(t)}convertGeoPoint(e){return new E1(L(e.latitude),L(e.longitude))}convertArray(e,t){return(e.values||[]).map(e=>this.convertValue(e,t))}convertServerTimestamp(e,t){switch(t){case"previous":var r=ii(e);return null==r?null:this.convertValue(r,t);case"estimate":return this.convertTimestamp(si(e));default:return null}}convertTimestamp(e){var t=Xn(e);return new w(t.seconds,t.nanos)}convertDocumentKey(e,t){var r=T.fromString(e),n=(v(p1(r),9688,{name:e}),new ui(r.get(1),r.get(3))),r=new x(r.popFirst(5));return n.isEqual(t)||lt(`Document ${r} contains a document reference within a different database (${n.projectId}/${n.database}) which is not supported. It will be treated as a reference in the current database (${t.projectId}/${t.database}) instead.`),r}}class Y0 extends Q0{constructor(e){super(),this.firestore=e}convertBytes(e){return new y1(e)}convertReference(e){var t=this.convertDocumentKey(e,this.firestore._databaseId);return new F(this.firestore,null,t)}}let W0="@firebase/firestore";function X0(t){var r=t,t=["next","error","complete"];if("object"==typeof r&&null!==r){var n=r;for(let e of t)if(e in n&&"function"==typeof n[e])return 1}}class J0{constructor(e,t,r,n,i){this._firestore=e,this._userDataWriter=t,this._key=r,this._document=n,this._converter=i}get id(){return this._key.path.lastSegment()}get ref(){return new F(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){var e;if(this._document)return this._converter?(e=new Z0(this._firestore,this._userDataWriter,this._key,this._document,null),this._converter.fromFirestore(e)):this._userDataWriter.convertValue(this._document.data.value)}_fieldsProto(){return this._document?.data.clone().value.mapValue.fields??void 0}get(e){if(this._document){var t=this._document.data.field(xo("DocumentSnapshot.get",e));if(null!==t)return this._userDataWriter.convertValue(t)}}}class Z0 extends J0{data(){return super.data()}}function ed(e){if("L"===e.limitType&&0===e.explicitOrderBy.length)throw new E(_.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}class td{}class rd extends td{}function nd(e,t,...r){let n=[];t instanceof td&&n.push(t);var t=n=n.concat(r),i=t.filter(e=>!1).length,s=t.filter(e=>e instanceof id).length;if(1<i||0<i&&0<s)throw new E(_.INVALID_ARGUMENT,"InvalidQuery. When using composite filters, you cannot use more than one filter at the top level. Consider nesting the multiple filters within an `and(...)` statement. For example: change `query(query, where(...), or(...))` to `query(query, and(where(...), or(...)))`.");for(let t of n)e=t._apply(e);return e}class id extends rd{constructor(e,t,r){super(),this._field=e,this._op=t,this._value=r,this.type="where"}static _create(e,t,r){return new id(e,t,r)}_apply(e){var t=this._parse(e);return dd(e._query,t),new Z1(e.firestore,e.converter,ea(e._query,t))}_parse(e){var t=po(e.firestore);{var n=e._query,i="where",s=t,a=e.firestore._databaseId,o=(e=this._field,this._op),u=this._value;let r;if(e.isKeyField()){if("array-contains"===o||"array-contains-any"===o)throw new E(_.INVALID_ARGUMENT,`Invalid Query. You can't perform '${o}' queries on documentId().`);if("in"===o||"not-in"===o){cd(u,o);let e=[];for(let t of u)e.push(hd(a,n,t));r={arrayValue:{values:e}}}else r=hd(a,n,u)}else"in"!==o&&"not-in"!==o&&"array-contains-any"!==o||cd(u,o),r=bo(s,i,u,"in"===o||"not-in"===o);return P.create(e,o,r)}}}(class extends td{});class sd extends rd{constructor(e,t){super(),this._field=e,this._direction=t,this.type="orderBy"}static _create(e,t){return new sd(e,t)}_apply(e){var t=((e,t,r)=>{if(null!==e.startAt)throw new E(_.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==e.endAt)throw new E(_.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");return new Ms(t,r)})(e._query,this._field,this._direction);return new Z1(e.firestore,e.converter,(t=(e=e._query).explicitOrderBy.concat([t]),new $s(e.path,e.collectionGroup,t,e.filters.slice(),e.limit,e.limitType,e.startAt,e.endAt)))}}class ad extends rd{constructor(e,t,r){super(),this.type=e,this._limit=t,this._limitType=r}static _create(e,t,r){return new ad(e,t,r)}_apply(e){return new Z1(e.firestore,e.converter,ta(e._query,this._limit,this._limitType))}}class od extends rd{constructor(e,t,r){super(),this.type=e,this._docOrFields=t,this._inclusive=r}static _create(e,t,r){return new od(e,t,r)}_apply(e){var t,r=ld(e,this.type,this._docOrFields,this._inclusive);return new Z1(e.firestore,e.converter,(e=e._query,t=r,new $s(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),e.limit,e.limitType,t,e.endAt)))}}class ud extends rd{constructor(e,t,r){super(),this.type=e,this._docOrFields=t,this._inclusive=r}static _create(e,t,r){return new ud(e,t,r)}_apply(e){var t,r=ld(e,this.type,this._docOrFields,this._inclusive);return new Z1(e.firestore,e.converter,(e=e._query,t=r,new $s(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),e.limit,e.limitType,e.startAt,t)))}}function ld(e,r,n,i){if(n[0]=se(n[0]),n[0]instanceof J0){var s=e._query,a=e.firestore._databaseId,o=r,u=n[0]._document,l=i;if(!u)throw new E(_.NOT_FOUND,`Can't use a DocumentSnapshot that doesn't exist for ${o}().`);var h=[];for(let t of Js(s))if(t.field.isKeyField())h.push(Si(a,u.key));else{let e=u.data.field(t.field);if(ni(e))throw new E(_.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+t.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===e){let e=t.field.canonicalString();throw new E(_.INVALID_ARGUMENT,`Invalid query. You are trying to start or end a query using a document for which the field '${e}' (used as the orderBy) does not exist.`)}h.push(e)}return new ys(h,l)}var t=po(e.firestore),c=e._query,d=e.firestore._databaseId,p=t,f=r,g=n,o=i,m=c.explicitOrderBy;if(g.length>m.length)throw new E(_.INVALID_ARGUMENT,`Too many arguments provided to ${f}(). The number of arguments must be less than or equal to the number of orderBy() clauses`);var v=[];for(let w=0;w<g.length;w++){var y=g[w];if(m[w].field.isKeyField()){if("string"!=typeof y)throw new E(_.INVALID_ARGUMENT,`Invalid query. Expected a string for document ID in ${f}(), but got a `+typeof y);if(!Xs(c)&&-1!==y.indexOf("/"))throw new E(_.INVALID_ARGUMENT,`Invalid query. When querying a collection and ordering by documentId(), the value passed to ${f}() must be a plain document ID, but '${y}' contains a slash.`);let e=c.path.child(T.fromString(y));if(!x.isDocumentKey(e))throw new E(_.INVALID_ARGUMENT,`Invalid query. When querying a collection group and ordering by documentId(), the value passed to ${f}() must result in a valid document path, but '${e}' is not because it contains an odd number of segments.`);let t=new x(e);v.push(Si(d,t))}else{let e=bo(p,f,y);v.push(e)}}return new ys(v,o)}function hd(e,t,r){if("string"==typeof(r=se(r))){if(""===r)throw new E(_.INVALID_ARGUMENT,"Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");if(!Xs(t)&&-1!==r.indexOf("/"))throw new E(_.INVALID_ARGUMENT,`Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${r}' contains a '/' character.`);var n=t.path.child(T.fromString(r));if(x.isDocumentKey(n))return Si(e,new x(n));throw new E(_.INVALID_ARGUMENT,`Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${n}' is not because it has an odd number of segments (${n.length}).`)}if(r instanceof F)return Si(e,r._key);throw new E(_.INVALID_ARGUMENT,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${Vt(r)}.`)}function cd(e,t){if(!Array.isArray(e)||0===e.length)throw new E(_.INVALID_ARGUMENT,`Invalid Query. A non-empty array is required for '${t.toString()}' filters.`)}function dd(e,t){var r=((t,r)=>{for(var n of t)for(let e of n.getFlattenedFilters())if(0<=r.indexOf(e.op))return e.op;return null})(e.filters,(e=>{switch(e){case"!=":return["!=","not-in"];case"array-contains-any":case"in":return["not-in"];case"not-in":return["array-contains-any","in","not-in","!="];default:return[]}})(t.op));if(null!==r)throw r===t.op?new E(_.INVALID_ARGUMENT,`Invalid query. You cannot use more than one '${t.op.toString()}' filter.`):new E(_.INVALID_ARGUMENT,`Invalid query. You cannot use '${t.op.toString()}' filters with '${r.toString()}' filters.`)}function pd(e,t,r){return e?r&&(r.merge||r.mergeFields)?e.toFirestore(t,r):e.toFirestore(t):t}class fd extends Q0{constructor(e){super(),this.firestore=e}convertBytes(e){return new y1(e)}convertReference(e){var t=this.convertDocumentKey(e,this.firestore._databaseId);return new F(this.firestore,null,t)}}class gd{constructor(e,t){this.hasPendingWrites=e,this.fromCache=t}isEqual(e){return this.hasPendingWrites===e.hasPendingWrites&&this.fromCache===e.fromCache}}class md extends J0{constructor(e,t,r,n,i,s){super(e,t,r,n,s),this._firestore=e,this._firestoreImpl=e,this.metadata=i}exists(){return super.exists()}data(e={}){var t;if(this._document)return this._converter?(t=new vd(this._firestore,this._userDataWriter,this._key,this._document,this.metadata,null),this._converter.fromFirestore(t,e)):this._userDataWriter.convertValue(this._document.data.value,e.serverTimestamps)}get(e,t={}){if(this._document){var r=this._document.data.field(xo("DocumentSnapshot.get",e));if(null!==r)return this._userDataWriter.convertValue(r,t.serverTimestamps)}}toJSON(){if(this.metadata.hasPendingWrites)throw new E(_.FAILED_PRECONDITION,"DocumentSnapshot.toJSON() attempted to serialize a document with pending writes. Await waitForPendingWrites() before invoking toJSON().");var e=this._document,t={};return t.type=md._jsonSchemaVersion,t.bundle="",t.bundleSource="DocumentSnapshot",t.bundleName=this._key.toString(),e&&e.isValidDocument()&&e.isFoundDocument()&&(this._userDataWriter.convertObjectMap(e.data.value.mapValue.fields,"previous"),t.bundle=(this._firestore,this.ref.path,"NOT SUPPORTED")),t}}md._jsonSchemaVersion="firestore/documentSnapshot/1.0",md._jsonSchema={type:Ut("string",md._jsonSchemaVersion),bundleSource:Ut("string","DocumentSnapshot"),bundleName:Ut("string"),bundle:Ut("string")};class vd extends md{data(e={}){return super.data(e)}}class yd{constructor(e,t,r,n){this._firestore=e,this._userDataWriter=t,this._snapshot=n,this.metadata=new gd(n.hasPendingWrites,n.fromCache),this.query=r}get docs(){let t=[];return this.forEach(e=>t.push(e)),t}get size(){return this._snapshot.docs.size}get empty(){return 0===this.size}forEach(t,r){this._snapshot.docs.forEach(e=>{t.call(r,new vd(this._firestore,this._userDataWriter,e.key,e,new gd(this._snapshot.mutatedKeys.has(e.key),this._snapshot.fromCache),this.query.converter))})}docChanges(e={}){var t=!!e.includeMetadataChanges;if(t&&this._snapshot.excludesMetadataChanges)throw new E(_.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===t||(this._cachedChanges=((s,t)=>{if(s._snapshot.oldDocs.isEmpty()){let r=0;return s._snapshot.docChanges.map(e=>{sh(s._snapshot.query)?xc(s._snapshot.query):sa(s.query._query);var t=new vd(s._firestore,s._userDataWriter,e.doc.key,e.doc,new gd(s._snapshot.mutatedKeys.has(e.doc.key),s._snapshot.fromCache),s.query.converter);return e.doc,{type:"added",doc:t,oldIndex:-1,newIndex:r++}})}{let i=s._snapshot.oldDocs;return s._snapshot.docChanges.filter(e=>t||3!==e.type).map(e=>{var t=new vd(s._firestore,s._userDataWriter,e.doc.key,e.doc,new gd(s._snapshot.mutatedKeys.has(e.doc.key),s._snapshot.fromCache),s.query.converter);let r=-1,n=-1;return 0!==e.type&&(r=i.indexOf(e.doc.key),i=i.delete(e.doc.key)),1!==e.type&&(i=i.add(e.doc),n=i.indexOf(e.doc.key)),{type:(e=>{switch(e){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return A(61501,{type:e})}})(e.type),doc:t,oldIndex:r,newIndex:n}})}})(this,t),this._cachedChangesIncludeMetadataChanges=t),this._cachedChanges}toJSON(){if(this.metadata.hasPendingWrites)throw new E(_.FAILED_PRECONDITION,"QuerySnapshot.toJSON() attempted to serialize a document with pending writes. Await waitForPendingWrites() before invoking toJSON().");var e={};e.type=yd._jsonSchemaVersion,e.bundleSource="QuerySnapshot",e.bundleName=Tt.newId(),this._firestore._databaseId.database,this._firestore._databaseId.projectId;let t=[],r=[],n=[];return this.docs.forEach(e=>{null!==e._document&&(t.push(e._document),r.push(this._userDataWriter.convertObjectMap(e._document.data.value.mapValue.fields,"previous")),n.push(e.ref.path))}),e.bundle=(this._firestore,this.query._query,"NOT SUPPORTED"),e}}function wd(e,t){return e instanceof md&&t instanceof md?e._firestore===t._firestore&&e._key.isEqual(t._key)&&(null===e._document?null===t._document:e._document.isEqual(t._document))&&e._converter===t._converter:e instanceof yd&&t instanceof yd&&e._firestore===t._firestore&&io(e.query,t.query)&&e.metadata.isEqual(t.metadata)&&e._snapshot.isEqual(t._snapshot)}yd._jsonSchemaVersion="firestore/querySnapshot/1.0",yd._jsonSchema={type:Ut("string",yd._jsonSchemaVersion),bundleSource:Ut("string","QuerySnapshot"),bundleName:Ut("string"),bundle:Ut("string")};let _d={maxAttempts:5};class Ed{constructor(e,t){this._firestore=e,this._commitHandler=t,this._mutations=[],this._committed=!1,this._dataReader=po(e)}set(e,t,r){this._verifyNotCommitted();var n=Td(e,this._firestore),i=pd(n.converter,t,r),i=fo(this._dataReader,"WriteBatch.set",n._key,i,null!==n.converter,r);return this._mutations.push(i.toMutation(n._key,ss.none())),this}update(e,t,r,...n){this._verifyNotCommitted();var i=Td(e,this._firestore),s="string"==typeof(t=se(t))||t instanceof w1?To(this._dataReader,"WriteBatch.update",i._key,t,r,n):Eo(this._dataReader,"WriteBatch.update",i._key,t);return this._mutations.push(s.toMutation(i._key,ss.exists(!0))),this}delete(e){this._verifyNotCommitted();var t=Td(e,this._firestore);return this._mutations=this._mutations.concat(new ms(t._key,ss.none())),this}commit(){return this._verifyNotCommitted(),this._committed=!0,0<this._mutations.length?this._commitHandler(this._mutations):Promise.resolve()}_verifyNotCommitted(){if(this._committed)throw new E(_.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")}}function Td(e,t){if((e=se(e)).firestore!==t)throw new E(_.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return e}class bd extends class{constructor(e,t){this._firestore=e,this._transaction=t,this._dataReader=po(e)}get(e){let r=Td(e,this._firestore),n=new fd(this._firestore);return this._transaction.lookup([r._key]).then(e=>{if(!e||1!==e.length)return A(24041);var t=e[0];if(t.isFoundDocument())return new J0(this._firestore,n,t.key,t,r.converter);if(t.isNoDocument())return new J0(this._firestore,n,r._key,null,r.converter);throw A(18433,{doc:t})})}set(e,t,r){var n=Td(e,this._firestore),i=pd(n.converter,t,r),i=fo(this._dataReader,"Transaction.set",n._key,i,null!==n.converter,r);return this._transaction.set(n._key,i),this}update(e,t,r,...n){var i=Td(e,this._firestore),s="string"==typeof(t=se(t))||t instanceof w1?To(this._dataReader,"Transaction.update",i._key,t,r,n):Eo(this._dataReader,"Transaction.update",i._key,t);return this._transaction.update(i._key,s),this}delete(e){var t=Td(e,this._firestore);return this._transaction.delete(t._key),this}}{constructor(e,t){super(e,t),this._firestore=e}get(e){let t=Td(e,this._firestore),r=new Y0(this._firestore);return super.get(e).then(e=>new md(this._firestore,r,t._key,e._document,new gd(!1,!1),t.converter))}}function Sd(e,t,r){e=y(e,F);var n=y(e.firestore,G0),i=pd(e.converter,t,r);return Cd(n,[fo(po(n),"setDoc",e._key,i,null!==e.converter,r).toMutation(e._key,ss.none())])}function Id(e,t,r,...n){e=y(e,F);var i=y(e.firestore,G0),s=po(i);return Cd(i,[("string"==typeof(t=se(t))||t instanceof w1?To(s,"updateDoc",e._key,t,r,n):Eo(s,"updateDoc",e._key,t)).toMutation(e._key,ss.exists(!0))])}function Ad(n,...i){n=se(n);let e={includeMetadataChanges:!1,source:"default"},s=0,r={includeMetadataChanges:(e="object"!=typeof i[s]||X0(i[s])?e:i[s++]).includeMetadataChanges,source:e.source};if(X0(i[s])){let e=i[s];i[s]=e.next?.bind(e),i[s+1]=e.error?.bind(e),i[s+2]=e.complete?.bind(e)}let a,o,u;if(n instanceof F)o=y(n.firestore,G0),u=Ys(n._key.path),a={next:e=>{i[s]&&i[s](xd(o,n,e))},error:i[s+1],complete:i[s+2]};else{let t=y(n,Z1),r=(o=y(t.firestore,G0),u=t._query,new Y0(o));a={next:e=>{i[s]&&i[s](new yd(o,r,t,e))},error:i[s+1],complete:i[s+2]},ed(n._query)}var l=j0(o);{var h=l,c=u,d=r,p=a;let e=new h0(p),t=new I6(c,e,d);return h.asyncQueue.enqueueAndForget(async()=>T6(await S0(h),t)),()=>{e.gc(),h.asyncQueue.enqueueAndForget(async()=>b6(await S0(h),t))}}}function Cd(e,t){var r=j0(e);{var n=r,i=t;let e=new pt;return n.asyncQueue.enqueueAndForget(async()=>U6(await b0(n),i,e)),e.promise}}function xd(e,t,r){var n=r.docs.get(t._key),i=new Y0(e);return new md(e,i,t._key,n,new gd(r.hasPendingWrites,r.fromCache),t.converter)}U0=!0,B0=n7.SDK_VERSION,at=B0,n7._registerComponent(new oe("firestore",(e,{instanceIdentifier:t,options:r})=>{var n=e.getProvider("app").getImmediate(),n=new G0(new vt(e.getProvider("auth-internal")),new Et(n,e.getProvider("app-check-internal")),((e,t)=>{if(Object.prototype.hasOwnProperty.apply(e.options,["projectId"]))return new ui(e.options.projectId,t);throw new E(_.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.')})(n,t),n);return r={useFetchStreams:U0,...r},n._setSettings(r),n},"PUBLIC").setMultipleInstances(!0)),n7.registerVersion(W0,"4.16.0",F0),n7.registerVersion(W0,"4.16.0","esm2020");let Nd="@firebase/firestore-compat",Dd="0.4.11";function Od(e,t){if(void 0===t)return{merge:!1};if(void 0!==t.mergeFields&&void 0!==t.merge)throw new E("invalid-argument",`Invalid options passed to function ${e}(): You cannot `+'specify both "merge" and "mergeFields".');return t}function Rd(){if("undefined"==typeof Uint8Array)throw new E("unimplemented","Uint8Arrays are not available in this environment.")}function kd(){if("undefined"==typeof atob)throw new E("unimplemented","Blobs are unavailable in Firestore in this environment.")}class Ld{constructor(e){this._delegate=e}static fromBase64String(e){return kd(),new Ld(y1.fromBase64String(e))}static fromUint8Array(e){return Rd(),new Ld(y1.fromUint8Array(e))}toBase64(){return kd(),this._delegate.toBase64()}toUint8Array(){return Rd(),this._delegate.toUint8Array()}isEqual(e){return this._delegate.isEqual(e._delegate)}toString(){return"Blob(base64: "+this.toBase64()+")"}}function Pd(e){var t=["next","error","complete"];if("object"==typeof e&&null!==e){var r,n=e;for(r of t)if(r in n&&"function"==typeof n[r])return 1}}class Md{enableIndexedDbPersistence(e,r){{e=e._delegate;var n={forceOwnership:r};ht("enableIndexedDbPersistence() will be deprecated in the future, you can use `FirestoreSettings.cache` instead.");let t=e._freezeSettings();return H0(e,u0.provider,{build:e=>new a0(e,t.cacheSizeBytes,n?.forceOwnership)}),Promise.resolve()}}enableMultiTabIndexedDbPersistence(e){return(async e=>{ht("enableMultiTabIndexedDbPersistence() will be deprecated in the future, you can use `FirestoreSettings.cache` instead.");let t=e._freezeSettings();H0(e,u0.provider,{build:e=>new o0(e,t.cacheSizeBytes)})})(e._delegate)}clearIndexedDbPersistence(e){return K0(e._delegate)}}class Vd{constructor(e,t,r){this._delegate=t,this._persistenceProvider=r,this.INTERNAL={delete:()=>this.terminate()},e instanceof ui||(this._appCompat=e)}get _databaseId(){return this._delegate._databaseId}settings(e){var t=this._delegate._getSettings();e.merge||t.host===e.host||ht("You are overriding the original host. If you did not intend to override your settings, use {merge: true}."),e.merge&&delete(e={...t,...e}).merge,this._delegate._setSettings(e)}useEmulator(e,t,r={}){J1(this._delegate,e,t,r)}enableNetwork(){return $0(this._delegate)}disableNetwork(){return I0(j0(y(this._delegate,G0)))}enablePersistence(e){let t=!1,r=!1;return e&&(t=!!e.synchronizeTabs,r=!!e.experimentalForceOwningTab,kt("synchronizeTabs",t,"experimentalForceOwningTab",r)),t?this._persistenceProvider.enableMultiTabIndexedDbPersistence(this):this._persistenceProvider.enableIndexedDbPersistence(this,r)}clearPersistence(){return this._persistenceProvider.clearIndexedDbPersistence(this)}terminate(){return this._appCompat&&(this._appCompat._removeServiceInstance("firestore-compat"),this._appCompat._removeServiceInstance("firestore")),this._delegate._delete()}waitForPendingWrites(){var t=this._delegate;{var r=j0(t=y(t,G0));let e=new pt;return r.asyncQueue.enqueueAndForget(async()=>j6(await b0(r),e)),e.promise}}onSnapshotsInSync(e){return t=this._delegate,e=e,D0(j0(t=y(t,G0)),X0(e)?e:{next:e});var t}get app(){if(this._appCompat)return this._appCompat;throw new E("failed-precondition","Firestore was not initialized using the Firebase SDK. 'app' is not available")}collection(e){try{return new Xd(this,to(this._delegate,e))}catch(e){throw jd(e,"collection()","Firestore.collection()")}}doc(e){try{return new Gd(this,ro(this._delegate,e))}catch(e){throw jd(e,"doc()","Firestore.doc()")}}collectionGroup(e){try{return new Qd(this,((e,t)=>{if(e=y(e,X1),Rt("collectionGroup","collection id",t),0<=t.indexOf("/"))throw new E(_.INVALID_ARGUMENT,`Invalid collection ID '${t}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);return new Z1(e,null,(e=t,new $s(T.emptyPath(),e)))})(this._delegate,e))}catch(e){throw jd(e,"collectionGroup()","Firestore.collectionGroup()")}}runTransaction(t){var r=this._delegate,n=e=>t(new Ud(this,e)),e=void 0,i=(r=y(r,G0),{..._d,...e});if(i.maxAttempts<1)throw new E(_.INVALID_ARGUMENT,"Max attempts must be at least 1");return O0(j0(r),e=>n(new bd(r,e)),i)}batch(){return j0(this._delegate),new Bd(new Ed(this._delegate,e=>Cd(this._delegate,e)))}loadBundle(e){return t=this._delegate,e=e,r=j0(t=y(t,G0)),n=new V0,R0(r,t._databaseId,e,n),n;var t,r,n}namedQuery(e){return t=this._delegate,e=e,k0(j0(t=y(t,G0)),e).then(e=>e?new Z1(t,null,e.query):null).then(e=>e?new Qd(this,e):null);var t}}class Fd extends Q0{constructor(e){super(),this.firestore=e}convertBytes(e){return new Ld(new y1(e))}convertReference(e){var t=this.convertDocumentKey(e,this.firestore._databaseId);return Gd.forKey(t,this.firestore,null)}}class Ud{constructor(e,t){this._firestore=e,this._delegate=t,this._userDataWriter=new Fd(e)}get(e){let t=Jd(e);return this._delegate.get(t).then(e=>new Kd(this._firestore,new md(this._firestore._delegate,this._userDataWriter,e._key,e._document,e.metadata,t.converter)))}set(e,t,r){var n=Jd(e);return r?(Od("Transaction.set",r),this._delegate.set(n,t,r)):this._delegate.set(n,t),this}update(e,t,r,...n){var i=Jd(e);return 2===arguments.length?this._delegate.update(i,t):this._delegate.update(i,t,r,...n),this}delete(e){var t=Jd(e);return this._delegate.delete(t),this}}class Bd{constructor(e){this._delegate=e}set(e,t,r){var n=Jd(e);return r?(Od("WriteBatch.set",r),this._delegate.set(n,t,r)):this._delegate.set(n,t),this}update(e,t,r,...n){var i=Jd(e);return 2===arguments.length?this._delegate.update(i,t):this._delegate.update(i,t,r,...n),this}delete(e){var t=Jd(e);return this._delegate.delete(t),this}commit(){return this._delegate.commit()}}class qd{constructor(e,t,r){this._firestore=e,this._userDataWriter=t,this._delegate=r}fromFirestore(e,t){var r=new vd(this._firestore._delegate,this._userDataWriter,e._key,e._document,e.metadata,null);return this._delegate.fromFirestore(new $d(this._firestore,r),t??{})}toFirestore(e,t){return t?this._delegate.toFirestore(e,t):this._delegate.toFirestore(e)}static getInstance(e,t){var r=qd.INSTANCES;let n=r.get(e),i=(n||(n=new WeakMap,r.set(e,n)),n.get(t));return i||(i=new qd(e,new Fd(e),t),n.set(t,i)),i}}qd.INSTANCES=new WeakMap;class Gd{constructor(e,t){this.firestore=e,this._delegate=t,this._userDataWriter=new Fd(e)}static forPath(e,t,r){if(e.length%2!=0)throw new E("invalid-argument","Invalid document reference. Document references must have an even number of segments, but "+e.canonicalString()+" has "+e.length);return new Gd(t,new F(t._delegate,r,new x(e)))}static forKey(e,t,r){return new Gd(t,new F(t._delegate,r,e))}get id(){return this._delegate.id}get parent(){return new Xd(this.firestore,this._delegate.parent)}get path(){return this._delegate.path}collection(e){try{return new Xd(this.firestore,to(this._delegate,e))}catch(e){throw jd(e,"collection()","DocumentReference.collection()")}}isEqual(e){return(e=se(e))instanceof F&&no(this._delegate,e)}set(e,t){t=Od("DocumentReference.set",t);try{return t?Sd(this._delegate,e,t):Sd(this._delegate,e)}catch(e){throw jd(e,"setDoc()","DocumentReference.set()")}}update(e,t,...r){try{return 1===arguments.length?Id(this._delegate,e):Id(this._delegate,e,t,...r)}catch(e){throw jd(e,"updateDoc()","DocumentReference.update()")}}delete(){return Cd(y((e=this._delegate).firestore,G0),[new ms(e._key,ss.none())]);var e}onSnapshot(...e){var t=zd(e),r=Hd(e,e=>new Kd(this.firestore,new md(this.firestore._delegate,this._userDataWriter,e._key,e._document,e.metadata,this._delegate.converter)));return Ad(this._delegate,t,r)}get(e){let t;return(t=("cache"===e?.source?t=>{t=y(t,F);let r=y(t.firestore,G0),e=j0(r),n=new Y0(r);return A0(e,t._key).then(e=>new md(r,n,t._key,e,new gd(null!==e&&e.hasLocalMutations,!0),t.converter))}:"server"===e?.source?t=>{t=y(t,F);let r=y(t.firestore,G0),e=j0(r);return C0(e,t._key,{source:"server"}).then(e=>xd(r,t,e))}:t=>{t=y(t,F);let r=y(t.firestore,G0),e=j0(r);return C0(e,t._key).then(e=>xd(r,t,e))})(this._delegate)).then(e=>new Kd(this.firestore,new md(this.firestore._delegate,this._userDataWriter,e._key,e._document,e.metadata,this._delegate.converter)))}withConverter(e){return new Gd(this.firestore,e?this._delegate.withConverter(qd.getInstance(this.firestore,e)):this._delegate.withConverter(null))}}function jd(e,t,r){return e.message=e.message.replace(t,r),e}function zd(e){for(var t of e)if("object"==typeof t&&!Pd(t))return t;return{}}function Hd(e,t){let r;return{next:e=>{r.next&&r.next(t(e))},error:(r=Pd(e[0])?e[0]:Pd(e[1])?e[1]:"function"==typeof e[0]?{next:e[0],error:e[1],complete:e[2]}:{next:e[1],error:e[2],complete:e[3]}).error?.bind(r),complete:r.complete?.bind(r)}}class Kd{constructor(e,t){this._firestore=e,this._delegate=t}get ref(){return new Gd(this._firestore,this._delegate.ref)}get id(){return this._delegate.id}get metadata(){return this._delegate.metadata}get exists(){return this._delegate.exists()}data(e){return this._delegate.data(e)}get(e,t){return this._delegate.get(e,t)}isEqual(e){return wd(this._delegate,e._delegate)}}class $d extends Kd{data(e){var t=this._delegate.data(e);return this._delegate._converter||(e="Document in a QueryDocumentSnapshot should exist",void 0!==t)||A(57014,e),t}}class Qd{constructor(e,t){this.firestore=e,this._delegate=t,this._userDataWriter=new Fd(e)}where(e,t,r){try{return new Qd(this.firestore,nd(this._delegate,(n=r,i=t,s=xo("where",e),id._create(s,i,n))))}catch(e){throw jd(e,/(orderBy|where)\(\)/,"Query.$1()")}var n,i,s}orderBy(e,t){try{return new Qd(this.firestore,nd(this._delegate,([r,n="asc"]=[e,t],i=n,s=xo("orderBy",r),sd._create(s,i))))}catch(e){throw jd(e,/(orderBy|where)\(\)/,"Query.$1()")}var r,n,i,s}limit(e){try{return new Qd(this.firestore,nd(this._delegate,(Ft("limit",t=e),ad._create("limit",t,"F"))))}catch(e){throw jd(e,"limit()","Query.limit()")}var t}limitToLast(e){try{return new Qd(this.firestore,nd(this._delegate,(Ft("limitToLast",t=e),ad._create("limitToLast",t,"L"))))}catch(e){throw jd(e,"limitToLast()","Query.limitToLast()")}var t}startAt(...e){try{return new Qd(this.firestore,nd(this._delegate,([...t]=[...e],od._create("startAt",t,!0))))}catch(e){throw jd(e,"startAt()","Query.startAt()")}var t}startAfter(...e){try{return new Qd(this.firestore,nd(this._delegate,([...t]=[...e],od._create("startAfter",t,!1))))}catch(e){throw jd(e,"startAfter()","Query.startAfter()")}var t}endBefore(...e){try{return new Qd(this.firestore,nd(this._delegate,([...t]=[...e],ud._create("endBefore",t,!1))))}catch(e){throw jd(e,"endBefore()","Query.endBefore()")}var t}endAt(...e){try{return new Qd(this.firestore,nd(this._delegate,([...t]=[...e],ud._create("endAt",t,!0))))}catch(e){throw jd(e,"endAt()","Query.endAt()")}var t}isEqual(e){return io(this._delegate,e._delegate)}get(e){let t;return(t=("cache"===e?.source?t=>{t=y(t,Z1);let r=y(t.firestore,G0),e=j0(r),n=new Y0(r);return x0(e,t._query).then(e=>new yd(r,n,t,e))}:"server"===e?.source?t=>{t=y(t,Z1);let r=y(t.firestore,G0),e=j0(r),n=new Y0(r);return N0(e,t._query,{source:"server"}).then(e=>new yd(r,n,t,e))}:t=>{t=y(t,Z1);let r=y(t.firestore,G0),e=j0(r),n=new Y0(r);return ed(t._query),N0(e,t._query).then(e=>new yd(r,n,t,e))})(this._delegate)).then(e=>new Wd(this.firestore,new yd(this.firestore._delegate,this._userDataWriter,this._delegate,e._snapshot)))}onSnapshot(...e){var t=zd(e),r=Hd(e,e=>new Wd(this.firestore,new yd(this.firestore._delegate,this._userDataWriter,this._delegate,e._snapshot)));return Ad(this._delegate,t,r)}withConverter(e){return new Qd(this.firestore,e?this._delegate.withConverter(qd.getInstance(this.firestore,e)):this._delegate.withConverter(null))}}class Yd{constructor(e,t){this._firestore=e,this._delegate=t}get type(){return this._delegate.type}get doc(){return new $d(this._firestore,this._delegate.doc)}get oldIndex(){return this._delegate.oldIndex}get newIndex(){return this._delegate.newIndex}}class Wd{constructor(e,t){this._firestore=e,this._delegate=t}get query(){return new Qd(this._firestore,this._delegate.query)}get metadata(){return this._delegate.metadata}get size(){return this._delegate.size}get empty(){return this._delegate.empty}get docs(){return this._delegate.docs.map(e=>new $d(this._firestore,e))}docChanges(e){return this._delegate.docChanges(e).map(e=>new Yd(this._firestore,e))}forEach(t,r){this._delegate.forEach(e=>{t.call(r,new $d(this._firestore,e))})}isEqual(e){return wd(this._delegate,e._delegate)}}class Xd extends Qd{constructor(e,t){super(e,t),this.firestore=e,this._delegate=t}get id(){return this._delegate.id}get path(){return this._delegate.path}get parent(){var e=this._delegate.parent;return e?new Gd(this.firestore,e):null}doc(e){try{return void 0===e?new Gd(this.firestore,ro(this._delegate)):new Gd(this.firestore,ro(this._delegate,e))}catch(e){throw jd(e,"doc()","CollectionReference.doc()")}}add(e){return((e,t)=>{let r=y(e.firestore,G0),n=ro(e),i=pd(e.converter,t),s=po(e.firestore);return Cd(r,[fo(s,"addDoc",n._key,i,null!==e.converter,{}).toMutation(n._key,ss.exists(!1))]).then(()=>n)})(this._delegate,e).then(e=>new Gd(this.firestore,e))}isEqual(e){return no(this._delegate,e._delegate)}withConverter(e){return new Xd(this.firestore,e?this._delegate.withConverter(qd.getInstance(this.firestore,e)):this._delegate.withConverter(null))}}function Jd(e){return y(e,F)}class Zd{static serverTimestamp(){var e=new vo("serverTimestamp");return e._methodName="FieldValue.serverTimestamp",new Zd(e)}static delete(){var e=new go("deleteField");return e._methodName="FieldValue.delete",new Zd(e)}static arrayUnion(...e){[...e]=[...e];var t=new yo("arrayUnion",e);return t._methodName="FieldValue.arrayUnion",new Zd(t)}static arrayRemove(...e){[...e]=[...e];var t=new wo("arrayRemove",e);return t._methodName="FieldValue.arrayRemove",new Zd(t)}static increment(e){e=e;var t=new _o("increment",e);return t._methodName="FieldValue.increment",new Zd(t)}constructor(e){this._delegate=e}isEqual(e){return this._delegate.isEqual(e._delegate)}}let e7={Firestore:Vd,GeoPoint:E1,Timestamp:w,Blob:Ld,Transaction:Ud,WriteBatch:Bd,DocumentReference:Gd,DocumentSnapshot:Kd,Query:Qd,QueryDocumentSnapshot:$d,QuerySnapshot:Wd,CollectionReference:Xd,FieldPath:class t7{constructor(...e){this._delegate=new w1(...e)}static documentId(){return new t7(h.keyField().canonicalString())}isEqual(e){return(e=se(e))instanceof w1&&this._delegate._internalPath.isEqual(e._internalPath)}},FieldValue:Zd,setLogLevel:function(e){e=e,ot.setLogLevel(e)},CACHE_SIZE_UNLIMITED:-1};B0=a.default,q0=(e,t)=>new Vd(e,t,new Md),B0.INTERNAL.registerComponent(new oe("firestore-compat",e=>{var t=e.getProvider("app-compat").getImmediate(),r=e.getProvider("firestore").getImmediate();return q0(t,r)},"PUBLIC").setServiceProps({...e7})),B0.registerVersion(Nd,Dd)}).apply(this,arguments)}catch(e){throw console.error(e),new Error("Cannot instantiate firebase-firestore-compat.js - be sure to load firebase-app.js first.")}});
//# sourceMappingURL=firebase-firestore-compat.js.map