@apoorvdwi/excalidraw-collab
Version:
Excalidraw as a React component
2 lines • 2.5 MB
JavaScript
/*! For license information please see excalidraw.development.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports.ExcalidrawLib=t(require("react"),require("react-dom")):e.ExcalidrawLib=t(e.React,e.ReactDOM)}(globalThis,((e,t)=>(()=>{var n,r,i={"../../../node_modules/@dwelle/tunnel-rat/dist/index.js":(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>a});var r=n("react"),i=n.n(r),o=n("../../../node_modules/zustand/esm/index.mjs");function a(){const e=(0,o.create)((e=>({current:new Array,version:0,set:e})));return{In:({children:t})=>{const n=e((e=>e.set)),i=e((e=>e.version));return(0,r.useLayoutEffect)((()=>{n((e=>({version:e.version+1})))}),[]),(0,r.useLayoutEffect)((()=>(n((({current:e})=>({current:[...e,t]}))),()=>n((({current:e})=>({current:e.filter((e=>e!==t))}))))),[t,i]),null},Out:()=>{const t=e((e=>e.current));return i().createElement(i().Fragment,null,t)}}}},"../../../node_modules/@firebase/app/dist/index.esm.js":(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>x,firebase:()=>w});var r,i,o=n("../../../node_modules/tslib/tslib.es6.js"),a=n("../../../node_modules/@firebase/util/dist/index.esm.js"),s=n("../../../node_modules/@firebase/component/dist/index.esm.js"),l=n("../../../node_modules/@firebase/logger/dist/index.esm.js"),c=((r={})["no-app"]="No Firebase App '{$appName}' has been created - call Firebase App.initializeApp()",r["bad-app-name"]="Illegal App name: '{$appName}",r["duplicate-app"]="Firebase App named '{$appName}' already exists",r["app-deleted"]="Firebase App named '{$appName}' already deleted",r["invalid-app-argument"]="firebase.{$appName}() takes either no argument or a Firebase App instance.",r["invalid-log-argument"]="First argument to `onLog` must be null or a function.",r),d=new a.ErrorFactory("app","Firebase",c),u="@firebase/app",p="[DEFAULT]",h=((i={})[u]="fire-core",i["@firebase/analytics"]="fire-analytics",i["@firebase/auth"]="fire-auth",i["@firebase/database"]="fire-rtdb",i["@firebase/functions"]="fire-fn",i["@firebase/installations"]="fire-iid",i["@firebase/messaging"]="fire-fcm",i["@firebase/performance"]="fire-perf",i["@firebase/remote-config"]="fire-rc",i["@firebase/storage"]="fire-gcs",i["@firebase/firestore"]="fire-fst",i["fire-js"]="fire-js",i["firebase-wrapper"]="fire-js-all",i),m=new l.Logger("@firebase/app"),g=function(){function e(e,t,n){var r=this;this.firebase_=n,this.isDeleted_=!1,this.name_=t.name,this.automaticDataCollectionEnabled_=t.automaticDataCollectionEnabled||!1,this.options_=(0,a.deepCopy)(e),this.container=new s.ComponentContainer(t.name),this._addComponent(new s.Component("app",(function(){return r}),"PUBLIC")),this.firebase_.INTERNAL.components.forEach((function(e){return r._addComponent(e)}))}return Object.defineProperty(e.prototype,"automaticDataCollectionEnabled",{get:function(){return this.checkDestroyed_(),this.automaticDataCollectionEnabled_},set:function(e){this.checkDestroyed_(),this.automaticDataCollectionEnabled_=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this.checkDestroyed_(),this.name_},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this.checkDestroyed_(),this.options_},enumerable:!1,configurable:!0}),e.prototype.delete=function(){var e=this;return new Promise((function(t){e.checkDestroyed_(),t()})).then((function(){return e.firebase_.INTERNAL.removeApp(e.name_),Promise.all(e.container.getProviders().map((function(e){return e.delete()})))})).then((function(){e.isDeleted_=!0}))},e.prototype._getService=function(e,t){return void 0===t&&(t=p),this.checkDestroyed_(),this.container.getProvider(e).getImmediate({identifier:t})},e.prototype._removeServiceInstance=function(e,t){void 0===t&&(t=p),this.container.getProvider(e).clearInstance(t)},e.prototype._addComponent=function(e){try{this.container.addComponent(e)}catch(t){m.debug("Component "+e.name+" failed to register with FirebaseApp "+this.name,t)}},e.prototype._addOrOverwriteComponent=function(e){this.container.addOrOverwriteComponent(e)},e.prototype.toJSON=function(){return{name:this.name,automaticDataCollectionEnabled:this.automaticDataCollectionEnabled,options:this.options}},e.prototype.checkDestroyed_=function(){if(this.isDeleted_)throw d.create("app-deleted",{appName:this.name_})},e}();g.prototype.name&&g.prototype.options||g.prototype.delete||console.log("dc");var f="8.3.3";var b=function e(){var t=function(e){var t={},n=new Map,r={__esModule:!0,initializeApp:function(n,i){void 0===i&&(i={}),"object"==typeof i&&null!==i||(i={name:i});var o=i;void 0===o.name&&(o.name=p);var s=o.name;if("string"!=typeof s||!s)throw d.create("bad-app-name",{appName:String(s)});if((0,a.contains)(t,s))throw d.create("duplicate-app",{appName:s});var l=new e(n,o,r);return t[s]=l,l},app:i,registerVersion:function(e,t,n){var r,i=null!==(r=h[e])&&void 0!==r?r:e;n&&(i+="-"+n);var a=i.match(/\s|\//),l=t.match(/\s|\//);if(a||l){var c=['Unable to register library "'+i+'" with version "'+t+'":'];return a&&c.push('library name "'+i+'" contains illegal characters (whitespace or "/")'),a&&l&&c.push("and"),l&&c.push('version name "'+t+'" contains illegal characters (whitespace or "/")'),void m.warn(c.join(" "))}o(new s.Component(i+"-version",(function(){return{library:i,version:t}}),"VERSION"))},setLogLevel:l.setLogLevel,onLog:function(e,t){if(null!==e&&"function"!=typeof e)throw d.create("invalid-log-argument");(0,l.setUserLogHandler)(e,t)},apps:null,SDK_VERSION:f,INTERNAL:{registerComponent:o,removeApp:function(e){delete t[e]},components:n,useAsService:function(e,t){return"serverAuth"===t?null:t}}};function i(e){if(e=e||p,!(0,a.contains)(t,e))throw d.create("no-app",{appName:e});return t[e]}function o(o){var s=o.name;if(n.has(s))return m.debug("There were multiple attempts to register component "+s+"."),"PUBLIC"===o.type?r[s]:null;if(n.set(s,o),"PUBLIC"===o.type){var l=function(e){if(void 0===e&&(e=i()),"function"!=typeof e[s])throw d.create("invalid-app-argument",{appName:s});return e[s]()};void 0!==o.serviceProps&&(0,a.deepExtend)(l,o.serviceProps),r[s]=l,e.prototype[s]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._getService.bind(this,s).apply(this,o.multipleInstances?e:[])}}for(var c=0,u=Object.keys(t);c<u.length;c++){var p=u[c];t[p]._addComponent(o)}return"PUBLIC"===o.type?r[s]:null}return r.default=r,Object.defineProperty(r,"apps",{get:function(){return Object.keys(t).map((function(e){return t[e]}))}}),i.App=e,r}(g);return t.INTERNAL=(0,o.__assign)((0,o.__assign)({},t.INTERNAL),{createFirebaseNamespace:e,extendNamespace:function(e){(0,a.deepExtend)(t,e)},createSubscribe:a.createSubscribe,ErrorFactory:a.ErrorFactory,deepExtend:a.deepExtend}),t}(),v=function(){function e(e){this.container=e}return e.prototype.getPlatformInfoString=function(){return this.container.getProviders().map((function(e){if(function(e){var t=e.getComponent();return"VERSION"===(null==t?void 0:t.type)}(e)){var t=e.getImmediate();return t.library+"/"+t.version}return null})).filter((function(e){return e})).join(" ")},e}();if((0,a.isBrowser)()&&void 0!==self.firebase){m.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n ");var y=self.firebase.SDK_VERSION;y&&y.indexOf("LITE")>=0&&m.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n ")}var k=b.initializeApp;b.initializeApp=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(0,a.isNode)()&&m.warn('\n Warning: This is a browser-targeted Firebase bundle but it appears it is being\n run in a Node environment. If running in a Node environment, make sure you\n are using the bundle specified by the "main" field in package.json.\n \n If you are using Webpack, you can specify "main" as the first item in\n "resolve.mainFields":\n https://webpack.js.org/configuration/resolve/#resolvemainfields\n \n If using Rollup, use the @rollup/plugin-node-resolve plugin and specify "main"\n as the first item in "mainFields", e.g. [\'main\', \'module\'].\n https://github.com/rollup/@rollup/plugin-node-resolve\n '),k.apply(void 0,e)};var w=b;!function(e,t){e.INTERNAL.registerComponent(new s.Component("platform-logger",(function(e){return new v(e)}),"PRIVATE")),e.registerVersion(u,"0.6.19",t),e.registerVersion("fire-js","")}(w);const x=w},"../../../node_modules/@firebase/component/dist/index.esm.js":(e,t,n)=>{"use strict";n.r(t),n.d(t,{Component:()=>o,ComponentContainer:()=>l,Provider:()=>s});var r=n("../../../node_modules/tslib/tslib.es6.js"),i=n("../../../node_modules/@firebase/util/dist/index.esm.js"),o=function(){function e(e,t,n){this.name=e,this.instanceFactory=t,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}return e.prototype.setInstantiationMode=function(e){return this.instantiationMode=e,this},e.prototype.setMultipleInstances=function(e){return this.multipleInstances=e,this},e.prototype.setServiceProps=function(e){return this.serviceProps=e,this},e.prototype.setInstanceCreatedCallback=function(e){return this.onInstanceCreated=e,this},e}(),a="[DEFAULT]",s=function(){function e(e,t){this.name=e,this.container=t,this.component=null,this.instances=new Map,this.instancesDeferred=new Map}return e.prototype.get=function(e){void 0===e&&(e=a);var t=this.normalizeInstanceIdentifier(e);if(!this.instancesDeferred.has(t)){var n=new i.Deferred;if(this.instancesDeferred.set(t,n),this.isInitialized(t)||this.shouldAutoInitialize())try{var r=this.getOrInitializeService({instanceIdentifier:t});r&&n.resolve(r)}catch(e){}}return this.instancesDeferred.get(t).promise},e.prototype.getImmediate=function(e){var t=(0,r.__assign)({identifier:a,optional:!1},e),n=t.identifier,i=t.optional,o=this.normalizeInstanceIdentifier(n);if(!this.isInitialized(o)&&!this.shouldAutoInitialize()){if(i)return null;throw Error("Service "+this.name+" is not available")}try{return this.getOrInitializeService({instanceIdentifier:o})}catch(e){if(i)return null;throw e}},e.prototype.getComponent=function(){return this.component},e.prototype.setComponent=function(e){var t,n;if(e.name!==this.name)throw Error("Mismatching Component "+e.name+" for Provider "+this.name+".");if(this.component)throw Error("Component for "+this.name+" has already been provided");if(this.component=e,this.shouldAutoInitialize()){if(function(e){return"EAGER"===e.instantiationMode}(e))try{this.getOrInitializeService({instanceIdentifier:a})}catch(e){}try{for(var i=(0,r.__values)(this.instancesDeferred.entries()),o=i.next();!o.done;o=i.next()){var s=(0,r.__read)(o.value,2),l=s[0],c=s[1],d=this.normalizeInstanceIdentifier(l);try{var u=this.getOrInitializeService({instanceIdentifier:d});c.resolve(u)}catch(e){}}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}}},e.prototype.clearInstance=function(e){void 0===e&&(e=a),this.instancesDeferred.delete(e),this.instances.delete(e)},e.prototype.delete=function(){return(0,r.__awaiter)(this,void 0,void 0,(function(){var e;return(0,r.__generator)(this,(function(t){switch(t.label){case 0:return e=Array.from(this.instances.values()),[4,Promise.all((0,r.__spreadArray)((0,r.__spreadArray)([],(0,r.__read)(e.filter((function(e){return"INTERNAL"in e})).map((function(e){return e.INTERNAL.delete()})))),(0,r.__read)(e.filter((function(e){return"_delete"in e})).map((function(e){return e._delete()})))))];case 1:return t.sent(),[2]}}))}))},e.prototype.isComponentSet=function(){return null!=this.component},e.prototype.isInitialized=function(e){return void 0===e&&(e=a),this.instances.has(e)},e.prototype.initialize=function(e){var t,n;void 0===e&&(e={});var i=e.instanceIdentifier,o=void 0===i?a:i,s=e.options,l=void 0===s?{}:s,c=this.normalizeInstanceIdentifier(o);if(this.isInitialized(c))throw Error(this.name+"("+c+") has already been initialized");if(!this.isComponentSet())throw Error("Component "+this.name+" has not been registered yet");var d=this.getOrInitializeService({instanceIdentifier:c,options:l});try{for(var u=(0,r.__values)(this.instancesDeferred.entries()),p=u.next();!p.done;p=u.next()){var h=(0,r.__read)(p.value,2),m=h[0],g=h[1];c===this.normalizeInstanceIdentifier(m)&&g.resolve(d)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}return d},e.prototype.getOrInitializeService=function(e){var t,n=e.instanceIdentifier,r=e.options,i=void 0===r?{}:r,o=this.instances.get(n);if(!o&&this.component&&(o=this.component.instanceFactory(this.container,{instanceIdentifier:(t=n,t===a?void 0:t),options:i}),this.instances.set(n,o),this.component.onInstanceCreated))try{this.component.onInstanceCreated(this.container,n,o)}catch(e){}return o||null},e.prototype.normalizeInstanceIdentifier=function(e){return this.component?this.component.multipleInstances?e:a:e},e.prototype.shouldAutoInitialize=function(){return!!this.component&&"EXPLICIT"!==this.component.instantiationMode},e}();var l=function(){function e(e){this.name=e,this.providers=new Map}return e.prototype.addComponent=function(e){var t=this.getProvider(e.name);if(t.isComponentSet())throw new Error("Component "+e.name+" has already been registered with "+this.name);t.setComponent(e)},e.prototype.addOrOverwriteComponent=function(e){this.getProvider(e.name).isComponentSet()&&this.providers.delete(e.name),this.addComponent(e)},e.prototype.getProvider=function(e){if(this.providers.has(e))return this.providers.get(e);var t=new s(e,this);return this.providers.set(e,t),t},e.prototype.getProviders=function(){return Array.from(this.providers.values())},e}()},"../../../node_modules/@firebase/firestore/dist/esm5/index.js":(e,t,n)=>{"use strict";n.r(t),n.d(t,{registerFirestore:()=>s});var r=n("../../../node_modules/@firebase/app/dist/index.esm.js"),i=(n("../../../node_modules/@firebase/util/dist/index.esm.js"),n("../../../node_modules/@firebase/logger/dist/index.esm.js"),n("../../../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js"),n("../../../node_modules/@firebase/firestore/dist/esm5/prebuilt-4888bff0-430c65bc.js")),o=n("../../../node_modules/@firebase/component/dist/index.esm.js"),a={Firestore:i.$,GeoPoint:i.v,Timestamp:i.k,Blob:i.x,Transaction:i.B,WriteBatch:i.q,DocumentReference:i.Q,DocumentSnapshot:i.G,Query:i.H,QueryDocumentSnapshot:i.z,QuerySnapshot:i.Y,CollectionReference:i.X,FieldPath:i.t,FieldValue:i.e,setLogLevel:i.L,CACHE_SIZE_UNLIMITED:i._};function s(e){!function(e,t){e.INTERNAL.registerComponent(new o.Component("firestore",(function(e){return function(e,t){return new i.$(e,new i.m(e,t),new i.O)}(e.getProvider("app").getImmediate(),e.getProvider("auth-internal"))}),"PUBLIC").setServiceProps(Object.assign({},a)))}(e),e.registerVersion("@firebase/firestore","2.2.3")}s(r.default)},"../../../node_modules/@firebase/firestore/dist/esm5/prebuilt-4888bff0-430c65bc.js":(e,t,n)=>{"use strict";n.r(t),n.d(t,{$:()=>ic,B:()=>sc,G:()=>mc,H:()=>fc,L:()=>ac,O:()=>rc,Q:()=>dc,X:()=>yc,Y:()=>vc,_:()=>Fs,e:()=>xc,k:()=>_,m:()=>Hs,n:()=>Sc,q:()=>lc,s:()=>_c,t:()=>wc,v:()=>Zs,x:()=>nc,z:()=>gc});var r=n("../../../node_modules/@firebase/util/dist/index.esm.js"),i=n("../../../node_modules/@firebase/logger/dist/index.esm.js"),o=n("../../../node_modules/@firebase/webchannel-wrapper/dist/index.esm.js"),a=n("../../../node_modules/tslib/tslib.es6.js"),s=function(){function e(e,t){var n=this;this.previousValue=e,t&&(t.sequenceNumberHandler=function(e){return n.t(e)},this.i=function(e){return t.writeSequenceNumber(e)})}return e.prototype.t=function(e){return this.previousValue=Math.max(e,this.previousValue),this.previousValue},e.prototype.next=function(){var e=++this.previousValue;return this.i&&this.i(e),e},e}();s.o=-1;var l={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"},c=function(e){function t(t,n){var r=this;return(r=e.call(this,n)||this).code=t,r.message=n,r.name="FirebaseError",r.toString=function(){return r.name+": [code="+r.code+"]: "+r.message},r}return(0,a.__extends)(t,e),t}(Error),d=new i.Logger("@firebase/firestore");function u(){return d.logLevel}function p(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(d.logLevel<=i.LogLevel.DEBUG){var r=t.map(g);d.debug.apply(d,(0,a.__spreadArray)(["Firestore (8.3.3): "+e],r))}}function h(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(d.logLevel<=i.LogLevel.ERROR){var r=t.map(g);d.error.apply(d,(0,a.__spreadArray)(["Firestore (8.3.3): "+e],r))}}function m(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(d.logLevel<=i.LogLevel.WARN){var r=t.map(g);d.warn.apply(d,(0,a.__spreadArray)(["Firestore (8.3.3): "+e],r))}}function g(e){if("string"==typeof e)return e;try{return t=e,JSON.stringify(t)}catch(t){return e}var t}function f(e){void 0===e&&(e="Unexpected state");var t="FIRESTORE (8.3.3) INTERNAL ASSERTION FAILED: "+e;throw h(t),new Error(t)}function b(e,t){e||f()}function v(e,t){return e}function y(e){var t="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(e);if(t&&"function"==typeof t.getRandomValues)t.getRandomValues(n);else for(var r=0;r<e;r++)n[r]=Math.floor(256*Math.random());return n}var k=function(){function e(){}return e.u=function(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=62*Math.floor(256/62),n="";n.length<20;)for(var r=y(40),i=0;i<r.length;++i)n.length<20&&r[i]<t&&(n+=e.charAt(r[i]%62));return n},e}();function w(e,t){return e<t?-1:e>t?1:0}function x(e,t,n){return e.length===t.length&&e.every((function(e,r){return n(e,t[r])}))}function S(e){return e+"\0"}var _=function(){function e(e,t){if(this.seconds=e,this.nanoseconds=t,t<0)throw new c(l.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(t>=1e9)throw new c(l.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(e<-62135596800)throw new c(l.INVALID_ARGUMENT,"Timestamp seconds out of range: "+e);if(e>=253402300800)throw new c(l.INVALID_ARGUMENT,"Timestamp seconds out of range: "+e)}return e.now=function(){return e.fromMillis(Date.now())},e.fromDate=function(t){return e.fromMillis(t.getTime())},e.fromMillis=function(t){var n=Math.floor(t/1e3);return new e(n,1e6*(t-1e3*n))},e.prototype.toDate=function(){return new Date(this.toMillis())},e.prototype.toMillis=function(){return 1e3*this.seconds+this.nanoseconds/1e6},e.prototype._compareTo=function(e){return this.seconds===e.seconds?w(this.nanoseconds,e.nanoseconds):w(this.seconds,e.seconds)},e.prototype.isEqual=function(e){return e.seconds===this.seconds&&e.nanoseconds===this.nanoseconds},e.prototype.toString=function(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"},e.prototype.toJSON=function(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}},e.prototype.valueOf=function(){var e=this.seconds- -62135596800;return String(e).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")},e}(),E=function(){function e(e){this.timestamp=e}return e.fromTimestamp=function(t){return new e(t)},e.min=function(){return new e(new _(0,0))},e.prototype.compareTo=function(e){return this.timestamp._compareTo(e.timestamp)},e.prototype.isEqual=function(e){return this.timestamp.isEqual(e.timestamp)},e.prototype.toMicroseconds=function(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3},e.prototype.toString=function(){return"SnapshotVersion("+this.timestamp.toString()+")"},e.prototype.toTimestamp=function(){return this.timestamp},e}();function A(e){var t=0;for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t++;return t}function T(e,t){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t(n,e[n])}function I(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}var C=function(){function e(e,t,n){void 0===t?t=0:t>e.length&&f(),void 0===n?n=e.length-t:n>e.length-t&&f(),this.segments=e,this.offset=t,this.len=n}return Object.defineProperty(e.prototype,"length",{get:function(){return this.len},enumerable:!1,configurable:!0}),e.prototype.isEqual=function(t){return 0===e.comparator(this,t)},e.prototype.child=function(t){var n=this.segments.slice(this.offset,this.limit());return t instanceof e?t.forEach((function(e){n.push(e)})):n.push(t),this.construct(n)},e.prototype.limit=function(){return this.offset+this.length},e.prototype.popFirst=function(e){return e=void 0===e?1:e,this.construct(this.segments,this.offset+e,this.length-e)},e.prototype.popLast=function(){return this.construct(this.segments,this.offset,this.length-1)},e.prototype.firstSegment=function(){return this.segments[this.offset]},e.prototype.lastSegment=function(){return this.get(this.length-1)},e.prototype.get=function(e){return this.segments[this.offset+e]},e.prototype.isEmpty=function(){return 0===this.length},e.prototype.isPrefixOf=function(e){if(e.length<this.length)return!1;for(var t=0;t<this.length;t++)if(this.get(t)!==e.get(t))return!1;return!0},e.prototype.isImmediateParentOf=function(e){if(this.length+1!==e.length)return!1;for(var t=0;t<this.length;t++)if(this.get(t)!==e.get(t))return!1;return!0},e.prototype.forEach=function(e){for(var t=this.offset,n=this.limit();t<n;t++)e(this.segments[t])},e.prototype.toArray=function(){return this.segments.slice(this.offset,this.limit())},e.comparator=function(e,t){for(var n=Math.min(e.length,t.length),r=0;r<n;r++){var i=e.get(r),o=t.get(r);if(i<o)return-1;if(i>o)return 1}return e.length<t.length?-1:e.length>t.length?1:0},e}(),j=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,a.__extends)(t,e),t.prototype.construct=function(e,n,r){return new t(e,n,r)},t.prototype.canonicalString=function(){return this.toArray().join("/")},t.prototype.toString=function(){return this.canonicalString()},t.fromString=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];for(var r=[],i=0,o=e;i<o.length;i++){var a=o[i];if(a.indexOf("//")>=0)throw new c(l.INVALID_ARGUMENT,"Invalid segment ("+a+"). Paths must not contain // in them.");r.push.apply(r,a.split("/").filter((function(e){return e.length>0})))}return new t(r)},t.emptyPath=function(){return new t([])},t}(C),L=/^[_a-zA-Z][_a-zA-Z0-9]*$/,z=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,a.__extends)(t,e),t.prototype.construct=function(e,n,r){return new t(e,n,r)},t.isValidIdentifier=function(e){return L.test(e)},t.prototype.canonicalString=function(){return this.toArray().map((function(e){return e=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),t.isValidIdentifier(e)||(e="`"+e+"`"),e})).join(".")},t.prototype.toString=function(){return this.canonicalString()},t.prototype.isKeyField=function(){return 1===this.length&&"__name__"===this.get(0)},t.keyField=function(){return new t(["__name__"])},t.fromServerFormat=function(e){for(var n=[],r="",i=0,o=function(){if(0===r.length)throw new c(l.INVALID_ARGUMENT,"Invalid field path ("+e+"). Paths must not be empty, begin with '.', end with '.', or contain '..'");n.push(r),r=""},a=!1;i<e.length;){var s=e[i];if("\\"===s){if(i+1===e.length)throw new c(l.INVALID_ARGUMENT,"Path has trailing escape character: "+e);var d=e[i+1];if("\\"!==d&&"."!==d&&"`"!==d)throw new c(l.INVALID_ARGUMENT,"Path has invalid escape sequence: "+e);r+=d,i+=2}else"`"===s?(a=!a,i++):"."!==s||a?(r+=s,i++):(o(),i++)}if(o(),a)throw new c(l.INVALID_ARGUMENT,"Unterminated ` in path: "+e);return new t(n)},t.emptyPath=function(){return new t([])},t}(C),P=function(){function e(e){this.fields=e,e.sort(z.comparator)}return e.prototype.covers=function(e){for(var t=0,n=this.fields;t<n.length;t++)if(n[t].isPrefixOf(e))return!0;return!1},e.prototype.isEqual=function(e){return x(this.fields,e.fields,(function(e,t){return e.isEqual(t)}))},e}(),M=function(){function e(e){this.binaryString=e}return e.fromBase64String=function(t){return new e(atob(t))},e.fromUint8Array=function(t){return new e(function(e){for(var t="",n=0;n<e.length;++n)t+=String.fromCharCode(e[n]);return t}(t))},e.prototype.toBase64=function(){return e=this.binaryString,btoa(e);var e},e.prototype.toUint8Array=function(){return function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}(this.binaryString)},e.prototype.approximateByteSize=function(){return 2*this.binaryString.length},e.prototype.compareTo=function(e){return w(this.binaryString,e.binaryString)},e.prototype.isEqual=function(e){return this.binaryString===e.binaryString},e}();M.EMPTY_BYTE_STRING=new M("");var D=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function O(e){if(b(!!e),"string"==typeof e){var t=0,n=D.exec(e);if(b(!!n),n[1]){var r=n[1];r=(r+"000000000").substr(0,9),t=Number(r)}var i=new Date(e);return{seconds:Math.floor(i.getTime()/1e3),nanos:t}}return{seconds:N(e.seconds),nanos:N(e.nanos)}}function N(e){return"number"==typeof e?e:"string"==typeof e?Number(e):0}function B(e){return"string"==typeof e?M.fromBase64String(e):M.fromUint8Array(e)}function R(e){var t,n;return"server_timestamp"===(null===(n=((null===(t=null==e?void 0:e.mapValue)||void 0===t?void 0:t.fields)||{}).__type__)||void 0===n?void 0:n.stringValue)}function F(e){var t=e.mapValue.fields.__previous_value__;return R(t)?F(t):t}function H(e){var t=O(e.mapValue.fields.__local_write_time__.timestampValue);return new _(t.seconds,t.nanos)}function G(e){return null==e}function U(e){return 0===e&&1/e==-1/0}function V(e){return"number"==typeof e&&Number.isInteger(e)&&!U(e)&&e<=Number.MAX_SAFE_INTEGER&&e>=Number.MIN_SAFE_INTEGER}var K=function(){function e(e){this.path=e}return e.fromPath=function(t){return new e(j.fromString(t))},e.fromName=function(t){return new e(j.fromString(t).popFirst(5))},e.prototype.hasCollectionId=function(e){return this.path.length>=2&&this.path.get(this.path.length-2)===e},e.prototype.isEqual=function(e){return null!==e&&0===j.comparator(this.path,e.path)},e.prototype.toString=function(){return this.path.toString()},e.comparator=function(e,t){return j.comparator(e.path,t.path)},e.isDocumentKey=function(e){return e.length%2==0},e.fromSegments=function(t){return new e(new j(t.slice()))},e}();function W(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?R(e)?4:10:f()}function q(e,t){var n=W(e);if(n!==W(t))return!1;switch(n){case 0:return!0;case 1:return e.booleanValue===t.booleanValue;case 4:return H(e).isEqual(H(t));case 3:return function(e,t){if("string"==typeof e.timestampValue&&"string"==typeof t.timestampValue&&e.timestampValue.length===t.timestampValue.length)return e.timestampValue===t.timestampValue;var n=O(e.timestampValue),r=O(t.timestampValue);return n.seconds===r.seconds&&n.nanos===r.nanos}(e,t);case 5:return e.stringValue===t.stringValue;case 6:return function(e,t){return B(e.bytesValue).isEqual(B(t.bytesValue))}(e,t);case 7:return e.referenceValue===t.referenceValue;case 8:return function(e,t){return N(e.geoPointValue.latitude)===N(t.geoPointValue.latitude)&&N(e.geoPointValue.longitude)===N(t.geoPointValue.longitude)}(e,t);case 2:return function(e,t){if("integerValue"in e&&"integerValue"in t)return N(e.integerValue)===N(t.integerValue);if("doubleValue"in e&&"doubleValue"in t){var n=N(e.doubleValue),r=N(t.doubleValue);return n===r?U(n)===U(r):isNaN(n)&&isNaN(r)}return!1}(e,t);case 9:return x(e.arrayValue.values||[],t.arrayValue.values||[],q);case 10:return function(e,t){var n=e.mapValue.fields||{},r=t.mapValue.fields||{};if(A(n)!==A(r))return!1;for(var i in n)if(n.hasOwnProperty(i)&&(void 0===r[i]||!q(n[i],r[i])))return!1;return!0}(e,t);default:return f()}}function Y(e,t){return void 0!==(e.values||[]).find((function(e){return q(e,t)}))}function Z(e,t){var n=W(e),r=W(t);if(n!==r)return w(n,r);switch(n){case 0:return 0;case 1:return w(e.booleanValue,t.booleanValue);case 2:return function(e,t){var n=N(e.integerValue||e.doubleValue),r=N(t.integerValue||t.doubleValue);return n<r?-1:n>r?1:n===r?0:isNaN(n)?isNaN(r)?0:-1:1}(e,t);case 3:return Q(e.timestampValue,t.timestampValue);case 4:return Q(H(e),H(t));case 5:return w(e.stringValue,t.stringValue);case 6:return function(e,t){var n=B(e),r=B(t);return n.compareTo(r)}(e.bytesValue,t.bytesValue);case 7:return function(e,t){for(var n=e.split("/"),r=t.split("/"),i=0;i<n.length&&i<r.length;i++){var o=w(n[i],r[i]);if(0!==o)return o}return w(n.length,r.length)}(e.referenceValue,t.referenceValue);case 8:return function(e,t){var n=w(N(e.latitude),N(t.latitude));return 0!==n?n:w(N(e.longitude),N(t.longitude))}(e.geoPointValue,t.geoPointValue);case 9:return function(e,t){for(var n=e.values||[],r=t.values||[],i=0;i<n.length&&i<r.length;++i){var o=Z(n[i],r[i]);if(o)return o}return w(n.length,r.length)}(e.arrayValue,t.arrayValue);case 10:return function(e,t){var n=e.fields||{},r=Object.keys(n),i=t.fields||{},o=Object.keys(i);r.sort(),o.sort();for(var a=0;a<r.length&&a<o.length;++a){var s=w(r[a],o[a]);if(0!==s)return s;var l=Z(n[r[a]],i[o[a]]);if(0!==l)return l}return w(r.length,o.length)}(e.mapValue,t.mapValue);default:throw f()}}function Q(e,t){if("string"==typeof e&&"string"==typeof t&&e.length===t.length)return w(e,t);var n=O(e),r=O(t),i=w(n.seconds,r.seconds);return 0!==i?i:w(n.nanos,r.nanos)}function $(e){return X(e)}function X(e){return"nullValue"in e?"null":"booleanValue"in e?""+e.booleanValue:"integerValue"in e?""+e.integerValue:"doubleValue"in e?""+e.doubleValue:"timestampValue"in e?function(e){var t=O(e);return"time("+t.seconds+","+t.nanos+")"}(e.timestampValue):"stringValue"in e?e.stringValue:"bytesValue"in e?B(e.bytesValue).toBase64():"referenceValue"in e?(n=e.referenceValue,K.fromName(n).toString()):"geoPointValue"in e?"geo("+(t=e.geoPointValue).latitude+","+t.longitude+")":"arrayValue"in e?function(e){for(var t="[",n=!0,r=0,i=e.values||[];r<i.length;r++)n?n=!1:t+=",",t+=X(i[r]);return t+"]"}(e.arrayValue):"mapValue"in e?function(e){for(var t="{",n=!0,r=0,i=Object.keys(e.fields||{}).sort();r<i.length;r++){var o=i[r];n?n=!1:t+=",",t+=o+":"+X(e.fields[o])}return t+"}"}(e.mapValue):f();var t,n}function J(e,t){return{referenceValue:"projects/"+e.projectId+"/databases/"+e.database+"/documents/"+t.path.canonicalString()}}function ee(e){return!!e&&"integerValue"in e}function te(e){return!!e&&"arrayValue"in e}function ne(e){return!!e&&"nullValue"in e}function re(e){return!!e&&"doubleValue"in e&&isNaN(Number(e.doubleValue))}function ie(e){return!!e&&"mapValue"in e}var oe=function(){function e(e){this.overlayMap=new Map,this.partialValue=e}return e.empty=function(){return new e({mapValue:{}})},e.prototype.field=function(t){return e.extractNestedValue(this.buildProto(),t)},e.prototype.toProto=function(){return this.field(z.emptyPath())},e.prototype.set=function(e,t){this.setOverlay(e,t)},e.prototype.setAll=function(e){var t=this;e.forEach((function(e,n){e?t.set(n,e):t.delete(n)}))},e.prototype.delete=function(e){this.setOverlay(e,null)},e.prototype.isEqual=function(e){return q(this.buildProto(),e.buildProto())},e.prototype.setOverlay=function(e,t){for(var n=this.overlayMap,r=0;r<e.length-1;++r){var i=e.get(r),o=n.get(i);o instanceof Map?n=o:o&&10===W(o)?(o=new Map(Object.entries(o.mapValue.fields||{})),n.set(i,o),n=o):(o=new Map,n.set(i,o),n=o)}n.set(e.lastSegment(),t)},e.prototype.applyOverlay=function(t,n){var r=this,i=!1,o=e.extractNestedValue(this.partialValue,t),a=ie(o)?Object.assign({},o.mapValue.fields):{};return n.forEach((function(e,n){if(e instanceof Map){var o=r.applyOverlay(t.child(n),e);null!=o&&(a[n]=o,i=!0)}else null!==e?(a[n]=e,i=!0):a.hasOwnProperty(n)&&(delete a[n],i=!0)})),i?{mapValue:{fields:a}}:null},e.prototype.buildProto=function(){var e=this.applyOverlay(z.emptyPath(),this.overlayMap);return null!=e&&(this.partialValue=e,this.overlayMap.clear()),this.partialValue},e.extractNestedValue=function(e,t){if(t.isEmpty())return e;for(var n=e,r=0;r<t.length-1;++r){if(!n.mapValue.fields)return null;if(!ie(n=n.mapValue.fields[t.get(r)]))return null}return(n=(n.mapValue.fields||{})[t.lastSegment()])||null},e.prototype.clone=function(){return new e(this.buildProto())},e}();function ae(e){var t=[];return T(e.fields||{},(function(e,n){var r=new z([e]);if(ie(n)){var i=ae(n.mapValue).fields;if(0===i.length)t.push(r);else for(var o=0,a=i;o<a.length;o++){var s=a[o];t.push(r.child(s))}}else t.push(r)})),new P(t)}var se=function(){function e(e,t,n,r,i){this.key=e,this.documentType=t,this.version=n,this.data=r,this.documentState=i}return e.newInvalidDocument=function(t){return new e(t,0,E.min(),oe.empty(),0)},e.newFoundDocument=function(t,n,r){return new e(t,1,n,r,0)},e.newNoDocument=function(t,n){return new e(t,2,n,oe.empty(),0)},e.newUnknownDocument=function(t,n){return new e(t,3,n,oe.empty(),2)},e.prototype.convertToFoundDocument=function(e,t){return this.version=e,this.documentType=1,this.data=t,this.documentState=0,this},e.prototype.convertToNoDocument=function(e){return this.version=e,this.documentType=2,this.data=oe.empty(),this.documentState=0,this},e.prototype.convertToUnknownDocument=function(e){return this.version=e,this.documentType=3,this.data=oe.empty(),this.documentState=2,this},e.prototype.setHasCommittedMutations=function(){return this.documentState=2,this},e.prototype.setHasLocalMutations=function(){return this.documentState=1,this},Object.defineProperty(e.prototype,"hasLocalMutations",{get:function(){return 1===this.documentState},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasCommittedMutations",{get:function(){return 2===this.documentState},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasPendingWrites",{get:function(){return this.hasLocalMutations||this.hasCommittedMutations},enumerable:!1,configurable:!0}),e.prototype.isValidDocument=function(){return 0!==this.documentType},e.prototype.isFoundDocument=function(){return 1===this.documentType},e.prototype.isNoDocument=function(){return 2===this.documentType},e.prototype.isUnknownDocument=function(){return 3===this.documentType},e.prototype.isEqual=function(t){return t instanceof e&&this.key.isEqual(t.key)&&this.version.isEqual(t.version)&&this.documentType===t.documentType&&this.documentState===t.documentState&&this.data.isEqual(t.data)},e.prototype.clone=function(){return new e(this.key,this.documentType,this.version,this.data.clone(),this.documentState)},e.prototype.toString=function(){return"Document("+this.key+", "+this.version+", "+JSON.stringify(this.data.toProto())+", {documentType: "+this.documentType+"}), {documentState: "+this.documentState+"})"},e}(),le=function(e,t,n,r,i,o,a){void 0===t&&(t=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o=null),void 0===a&&(a=null),this.path=e,this.collectionGroup=t,this.orderBy=n,this.filters=r,this.limit=i,this.startAt=o,this.endAt=a,this.h=null};function ce(e,t,n,r,i,o,a){return void 0===t&&(t=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o=null),void 0===a&&(a=null),new le(e,t,n,r,i,o,a)}function de(e){var t=v(e);if(null===t.h){var n=t.path.canonicalString();null!==t.collectionGroup&&(n+="|cg:"+t.collectionGroup),n+="|f:",n+=t.filters.map((function(e){return function(e){return e.field.canonicalString()+e.op.toString()+$(e.value)}(e)})).join(","),n+="|ob:",n+=t.orderBy.map((function(e){return function(e){return e.field.canonicalString()+e.dir}(e)})).join(","),G(t.limit)||(n+="|l:",n+=t.limit),t.startAt&&(n+="|lb:",n+=Se(t.startAt)),t.endAt&&(n+="|ub:",n+=Se(t.endAt)),t.h=n}return t.h}function ue(e,t){if(e.limit!==t.limit)return!1;if(e.orderBy.length!==t.orderBy.length)return!1;for(var n=0;n<e.orderBy.length;n++)if(!Ee(e.orderBy[n],t.orderBy[n]))return!1;if(e.filters.length!==t.filters.length)return!1;for(var r=0;r<e.filters.length;r++)if(i=e.filters[r],o=t.filters[r],i.op!==o.op||!i.field.isEqual(o.field)||!q(i.value,o.value))return!1;var i,o;return e.collectionGroup===t.collectionGroup&&!!e.path.isEqual(t.path)&&!!Te(e.startAt,t.startAt)&&Te(e.endAt,t.endAt)}function pe(e){return K.isDocumentKey(e.path)&&null===e.collectionGroup&&0===e.filters.length}var he=function(e){function t(t,n,r){var i=this;return(i=e.call(this)||this).field=t,i.op=n,i.value=r,i}return(0,a.__extends)(t,e),t.create=function(e,n,r){return e.isKeyField()?"in"===n||"not-in"===n?this.l(e,n,r):new me(e,n,r):"array-contains"===n?new ve(e,r):"in"===n?new ye(e,r):"not-in"===n?new ke(e,r):"array-contains-any"===n?new we(e,r):new t(e,n,r)},t.l=function(e,t,n){return"in"===t?new ge(e,n):new fe(e,n)},t.prototype.matches=function(e){var t=e.data.field(this.field);return"!="===this.op?null!==t&&this.m(Z(t,this.value)):null!==t&&W(this.value)===W(t)&&this.m(Z(t,this.value))},t.prototype.m=function(e){switch(this.op){case"<":return e<0;case"<=":return e<=0;case"==":return 0===e;case"!=":return 0!==e;case">":return e>0;case">=":return e>=0;default:return f()}},t.prototype.g=function(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0},t}((function(){})),me=function(e){function t(t,n,r){var i=this;return(i=e.call(this,t,n,r)||this).key=K.fromName(r.referenceValue),i}return(0,a.__extends)(t,e),t.prototype.matches=function(e){var t=K.comparator(e.key,this.key);return this.m(t)},t}(he),ge=function(e){function t(t,n){var r=this;return(r=e.call(this,t,"in",n)||this).keys=be("in",n),r}return(0,a.__extends)(t,e),t.prototype.matches=function(e){return this.keys.some((function(t){return t.isEqual(e.key)}))},t}(he),fe=function(e){function t(t,n){var r=this;return(r=e.call(this,t,"not-in",n)||this).keys=be("not-in",n),r}return(0,a.__extends)(t,e),t.prototype.matches=function(e){return!this.keys.some((function(t){return t.isEqual(e.key)}))},t}(he);function be(e,t){var n;return((null===(n=t.arrayValue)||void 0===n?void 0:n.values)||[]).map((function(e){return K.fromName(e.referenceValue)}))}var ve=function(e){function t(t,n){return e.call(this,t,"array-contains",n)||this}return(0,a.__extends)(t,e),t.prototype.matches=function(e){var t=e.data.field(this.field);return te(t)&&Y(t.arrayValue,this.value)},t}(he),ye=function(e){function t(t,n){return e.call(this,t,"in",n)||this}return(0,a.__extends)(t,e),t.prototype.matches=function(e){var t=e.data.field(this.field);return null!==t&&Y(this.value.arrayValue,t)},t}(he),ke=function(e){function t(t,n){return e.call(this,t,"not-in",n)||this}return(0,a.__extends)(t,e),t.prototype.matches=function(e){if(Y(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;var t=e.data.field(this.field);return null!==t&&!Y(this.value.arrayValue,t)},t}(he),we=function(e){function t(t,n){return e.call(this,t,"array-contains-any",n)||this}return(0,a.__extends)(t,e),t.prototype.matches=function(e){var t=this,n=e.data.field(this.field);return!(!te(n)||!n.arrayValue.values)&&n.arrayValue.values.some((function(e){return Y(t.value.arrayValue,e)}))},t}(he),xe=function(e,t){this.position=e,this.before=t};function Se(e){return(e.before?"b":"a")+":"+e.position.map((function(e){return $(e)})).join(",")}var _e=function(e,t){void 0===t&&(t="asc"),this.field=e,this.dir=t};function Ee(e,t){return e.dir===t.dir&&e.field.isEqual(t.field)}function Ae(e,t,n){for(var r=0,i=0;i<e.position.length;i++){var o=t[i],a=e.position[i];if(r=o.field.isKeyField()?K.comparator(K.fromName(a.referenceValue),n.key):Z(a,n.data.field(o.field)),"desc"===o.dir&&(r*=-1),0!==r)break}return e.before?r<=0:r<0}function Te(e,t){if(null===e)return null===t;if(null===t)return!1;if(e.before!==t.before||e.position.length!==t.position.length)return!1;for(var n=0;n<e.position.length;n++)if(!q(e.position[n],t.position[n]))return!1;return!0}var Ie=function(e,t,n,r,i,o,a,s){void 0===t&&(t=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o="F"),void 0===a&&(a=null),void 0===s&&(s=null),this.path=e,this.collectionGroup=t,this.explicitOrderBy=n,this.filters=r,this.limit=i,this.limitType=o,this.startAt=a,this.endAt=s,this.p=null,this.T=null,this.startAt,this.endAt};function Ce(e,t,n,r,i,o,a,s){return new Ie(e,t,n,r,i,o,a,s)}function je(e){return new Ie(e)}function Le(e){return!G(e.limit)&&"F"===e.limitType}function ze(e){return!G(e.limit)&&"L"===e.limitType}function Pe(e){return e.explicitOrderBy.length>0?e.explicitOrderBy[0].field:null}function Me(e){for(var t=0,n=e.filters;t<n.length;t++){var r=n[t];if(r.g())return r.field}return null}function De(e){return null!==e.collectionGroup}function Oe(e){var t=v(e);if(null===t.p){t.p=[];var n=Me(t),r=Pe(t);if(null!==n&&null===r)n.isKeyField()||t.p.push(new _e(n)),t.p.push(new _e(z.keyField(),"asc"));else{for(var i=!1,o=0,a=t.explicitOrderBy;o<a.length;o++){var s=a[o];t.p.push(s),s.field.isKeyField()&&(i=!0)}if(!i){var l=t.explicitOrderBy.length>0?t.explicitOrderBy[t.explicitOrderBy.length-1].dir:"asc";t.p.push(new _e(z.keyField(),l))}}}return t.p}function Ne(e){var t=v(e);if(!t.T)if("F"===t.limitType)t.T=ce(t.path,t.collectionGroup,Oe(t),t.filters,t.limit,t.startAt,t.endAt);else{for(var n=[],r=0,i=Oe(t);r<i.length;r++){var o=i[r],a="desc"===o.dir?"asc":"desc";n.push(new _e(o.field,a))}var s=t.endAt?new xe(t.endAt.position,!t.endAt.before):null,l=t.startAt?new xe(t.startAt.position,!t.startAt.before):null;t.T=ce(t.path,t.collectionGroup,n,t.filters,t.limit,s,l)}return t.T}function Be(e,t,n){return new Ie(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),t,n,e.startAt,e.endAt)}function Re(e,t){return ue(Ne(e),Ne(t))&&e.limitType===t.limitType}function Fe(e){return de(Ne(e))+"|lt:"+e.limitType}function He(e){return"Query(target="+function(e){var t=e.path.canonicalString();return null!==e.collectionGroup&&(t+=" collectionGroup="+e.collectionGroup),e.filters.length>0&&(t+=", filters: ["+e.filters.map((function(e){return(t=e).field.canonicalString()+" "+t.op+" "+$(t.value);var t})).join(", ")+"]"),G(e.limit)||(t+=", limit: "+e.limit),e.orderBy.length>0&&(t+=", orderBy: ["+e.orderBy.map((function(e){return function(e){return e.field.canonicalString()+" ("+e.dir+")"}(e)})).join(", ")+"]"),e.startAt&&(t+=", startAt: "+Se(e.startAt)),e.endAt&&(t+=", endAt: "+Se(e.endAt)),"Target("+t+")"}(Ne(e))+"; limitType="+e.limitType+")"}function Ge(e,t){return t.isFoundDocument()&&function(e,t){var n=t.key.path;return null!==e.collectionGroup?t.key.hasCollectionId(e.collectionGroup)&&e.path.isPrefixOf(n):K.isDocumentKey(e.path)?e.path.isEqual(n):e.path.isImmediateParentOf(n)}(e,t)&&function(e,t){for(var n=0,r=e.explicitOrderBy;n<r.length;n++){var i=r[n];if(!i.field.isKeyField()&&null===t.data.field(i.field))return!1}return!0}(e,t)&&function(e,t){for(var n=0,r=e.filters;n<r.length;n++)if(!r[n].matches(t))return!1;return!0}(e,t)&&function(e,t){return!(e.startAt&&!Ae(e.startAt,Oe(e),t)||e.endAt&&Ae(e.endAt,Oe(e),t))}(e,t)}function Ue(e){return function(t,n){for(var r=!1,i=0,o=Oe(e);i<o.length;i++){var a=o[i],s=Ve(a,t,n);if(0!==s)return s;r=r||a.field.isKeyField()}return 0}}function Ve(e,t,n){var r=e.field.isKeyField()?K.comparator(t.key,n.key):function(e,t,n){var r=t.data.field(e),i=n.data.field(e);return null!==r&&null!==i?Z(r,i):f()}(e.field,t,n);switch(e.dir){case"asc":return r;case"desc":return-1*r;default:return f()}}function Ke(e,t){if(e.I){if(isNaN(t))return{doubleValue:"NaN"};if(t===1/0)return{doubleValue:"Infinity"};if(t===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:U(t)?"-0":t}}function We(e){return{integerValue:""+e}}function qe(e,t){return V(t)?We(t):Ke(e,t)}var Ye=function(){this._=void 0};function Ze(e,t,n){return e instanceof Xe?function(e,t){var n={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:e.seconds,nanos:e.nanoseconds}}}};return t&&(n.fields.__previous_value__=t),{mapValue:n}}(n,t):e instanceof Je?et(e,t):e instanceof tt?nt(e,t):function(e,t){var n=$e(e,t),r=it(n)+it(e.A);return ee(n)&&ee(e.A)?We(r):Ke(e.R,r)}(e,t)}function Qe(e,t,n){return e instanceof Je?et(e,t):e instanceof tt?nt(e,t):n}function $e(e,t){return e instanceof rt?ee(n=t)||function(e){return!!e&&"doubleValue"in e}(n)?t:{integerValue:0}:null;var n}var Xe=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,a.__extends)(t,e),t}(Ye),Je=function(e){function t(t){var n=this;return(n=e.call(this)||this).elements=t,n}return(0,a.__extends)(t,e),t}(Ye);function et(e,t){for(var n=ot(t),r=function(e){n.some((function(t){return q(t,e)}))||n.push(e)},i=0,o=e.elements;i<o.length;i++)r(o[i]);return{arrayValue:{values:n}}}var tt=function(e){function t(t){var n=this;return(n=e.call(this)||this).elements=t,n}return(0,a.__extends)(t,e),t}(Ye);function nt(e,t){for(var n=ot(t),r=function(e){n=n.filter((function(t){return!q(t,e)}))},i=0,o=e.elements;i<o.length;i++)r(o[i]);return{arrayValue:{values:n}}}var rt=function(e){function t(t,n){var r=this;return(r=e.call(this)||this).R=t,r.A=n,r}return(0,a.__extends)(t,e),t}(Ye);function it(e){return N(e.integerValue||e.doubleValue)}function ot(e){return te(e)&&e.arrayValue.values?e.arrayValue.values.slice():[]}var at=function(e,t){this.field=e,this.transform=t},st=function(e,t){this.version=e,this.transformResults=t},lt=function(){function e(e,t){this.updateTime=e,this.exists=t}return e.none=function(){return new e},e.exists=function(t){return new e(void 0,t)},e.updateTime=function(t){return new e(t)},Object.defineProperty(e.prototype,"isNone",{get:function(){return void 0===this.updateTime&&void 0===this.exists},enumerable:!1,configurable:!0}),e.prototype.isEqual=function(e){return this.exists===e.exists&&(this.updateTime?!!e.updateTime&&this.updateTime.isEqual(e.updateTime):!e.updateTime)},e}();function ct(e,t){return void 0!==e.updateTime?t.isFoundDocument()&&t.version.isEqual(e.updateTime):void 0===e.exists||e.exists===t.isFoundDocument()}var dt=function(){};function ut(e,t,n){e instanceof ft?function(e,t,n){var r=e.value.clone(),i=yt(e.fieldTransforms,t,n.transformResults);r.setAll(i),t.convertToFoundDocument(n.version,r).setHasCommittedMutations()}(e,t,n):e instanceof bt?function(e,t,n){if(ct(e.precondition,t)){var r=yt(e.fieldTransforms,t,n.transformResults),i=t.data;i.setAll(vt(e)),i.setAll(r),t.convertToFoundDocument(n.version,i).setHasCommittedMutations()}else t.convertToUnknownDocument(n.version)}(e,t,n):function(e,t,n){t.convertToNoDocument(n.version).setHasCommittedMutations()}(0,t,n)}function pt(e,t,n){e instanceof ft?function(e,t,n){if(ct(e.precondition,t)){var r=e.value.clone(),i=kt(e.fieldTransforms,n,t);r.setAll(i),t.convertToFoundDocument(gt(t),r).setHasLocalMutations()}}(e,t,n):e instanceof bt?function(e,t,n){if(ct(e.precondition,t)){var r=kt(e.fieldTransforms,n,t),i=t.data;i.setAll(vt(e)),i.setAll(r),t.convertToFoundDocument(gt(t),i).setHasLocalMutations()}}(e,t,n):function(e,t){ct(e.precondition,t)&&t.convertToNoDocument(E.min())}(e,t)}function ht(e,t){for(var n=null,r=0,i=e.fieldTransforms;r<i.length;r++){var o=i[r],a=t.data.field(o.field),s=$e(o.transform,a||null);null!=s&&(null==n&&(n=oe.empty()),n.set(o.field,s))}return n||null}function mt(e,t){return e.type===t.type&&!!e.key.isEqual(t.key)&&!!e.precondition.isEqual(t.precondition)&&!!function(e,t){return void 0===e&&void 0===t||!(!e||!t)&&x(e,t,(function(e,t){return function(e,t){return e.field.isEqual(t.field)&&function(e,t){return e instanceof Je&&t instanceof Je||e instanceof tt&&t instanceof tt?x(e.elements,t.elements,q):e instanceof rt&&t instanceof rt?q(e.A,t.A):e instanceof Xe&&t instanceof Xe}(e.transform,t.transform)}(e,t)}))}(e.fieldTransforms,t.fieldTransforms)&&(0===e.type?e.value.isEqual(t.value):1!==e.type||e.data.isEqual(t.data)&&e.fieldMask.isEqual(t.fieldMask))}function gt(e){return e.isFoundDocument()?e.version:E.min()}var ft=function(e){function t(t,n,r,i){void 0===i&&(i=[]);var o=this;return(o=e.call(this)||this).key=t,o.value=n,o.precondition=r,o.fieldTransforms=i,o.type=0,o}return(0,a.__extends)(t,e),t}(dt),bt=function(e){function t(t,n,r,i,o){void 0===o&&(o=[]);var a=this;return(a=e.call(this)||this).key=t,a.data=n,a.fieldMask=r,a.precondition=i,a.fieldTransforms=o,a.type=1,a}return(0,a.__extends)(t,e),t}(dt);function vt(e){var t=new Map;return e.fieldMask.fields.forEach((function(n){if(!n.isEmpty()){var r=e.data.field(n);t.set(n,r)}})),t}function yt(e,t,n){var r=new Map;b(e.length===n.length);for(var i=0;i<n.length;i++){var o=e[i],a=o.transform,s=t.data.field(o.field);r.set(o.field,Qe(a,s,n[i]))}return r}function kt(e,t,n){for(var r=new Map,i=0,o=e;i<o.length;i++){var a=o[i],s=a.transform,l=n.data.field(a.field);r.set(a.field,Ze(s,l,t))}return r}var wt,xt,St=function(e){function t(t,n){var r=this;return(r=e.call(this)||this).key=t,r.precondition=n,r.type=2,r.fieldTransforms=[],r}return(0,a.__extends)(t,e),t}(dt),_t=function(e){function t(t,n){var r=this;return(r=e.call(this)||this).key=t,r.precondition=n,r.type=3,r.fieldTransforms=[],r}return(0,a.__extends)(t,e),t}(dt),Et=function(e){this.count=e};function At(e){switch(e){case l.OK:return f();case l.CANCELLED:case l.UNKNOWN:case l.DEADLINE_EXCEEDED:case l.RESOURCE_EXHAUSTED:case l.INTERNAL:case l.UNAVAILABLE:case l.UNAUTHENTICATED:return!1;case l.INVALID_ARGUMENT:case l.NOT_FOUND:case l.ALREADY_EXISTS:case l.PERMISSION_DENIED:case l.FAILED_PRECONDITION:case l.ABORTED:case l.OUT_OF_RANGE:case l.UNIMPLEMENTED:case l.DATA_LOSS:return!0;default:return f()}}function Tt(e){if(void 0===e)return h("GRPC error has no .code"),l.UNKNOWN;swit