New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

immy

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immy - npm Package Compare versions

Comparing version 1.0.0-alpha.25 to 1.0.0-alpha.26

2

dist/immy.min.js

@@ -1,1 +0,1 @@

module.exports=function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:s})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var s={};r.d(s,"map",function(){return ce}),r.d(s,"filter",function(){return ue}),r.d(s,"reduce",function(){return pe}),r.d(s,"asType",function(){return fe});var i={};r.d(i,"withList",function(){return ge});var n={};function l(e){return"string"==typeof e?'"'+e+'"':JSON.stringify(e)}function a(e){const{name:t,apply:r,applyWrapper:s,invertName:i,invert:n,invertWrapper:l}=e;return r._name=t,r.inverse=n,n._name=i,n.inverse=r,r.callWrapper=s,n.callWrapper=l,r}function o(e,t){if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||t.length!==e.length)throw new Error("when using array keys, both args must be arrays and both must have the same length");for(let r=0;r<e.length;++r){if(e[r]<t[r])return-1;if(t[r]<e[r])return 1;if(e[r]!==t[r])return-1}return 0}return e<t?-1:t<e?1:e!==t?-1:0}function h(e){return!1!==e}r.d(n,"fromList",function(){return Pe}),r.d(n,"fromMap",function(){return Ee}),r.d(n,"from",function(){return Oe});class c{constructor(e){if(this.observer=e,this.active=!0,!e.insert)throw new Error("observer must implement an insert method");if(!e.delete)throw new Error("observer must implement a delete method")}push(e,t){this.active&&(this.observer.push?this.active=h(this.observer.push(t,e)):this.active=h(this.observer.insert(e,t)))}pop(e,t){this.active&&(this.observer.pop?this.active=h(this.observer.pop(t,e)):this.active=h(this.observer.delete(e,t)))}unshift(e){this.active&&(this.observer.unshift?this.active=h(this.observer.unshift(e,index)):this.active=h(this.observer.insert(0,e)))}shift(e){this.active&&(this.observer.shift?this.active=h(this.observer.shift(e,index)):this.active=h(this.observer.delete(0,e)))}insert(e,t){this.active&&(this.active=h(this.observer.insert(e,t)))}delete(e,t){this.active&&(this.active=h(this.observer.delete(e,t)))}clear(e){if(this.active)if(this.observer.clear)this.active=h(this.observer.clear());else for(let t=e.length-1;t>=0&&this.active;--t)this.pop(t,e[t])}pushMany(e,t){if(this.active)if(this.observer.pushMany)this.active=h(this.observer.pushMany(t));else for(let r=0;r<t.length&&this.active;++r)this.push(e+r,t[r])}set(e,t,r){this.active&&(this.observer.set?this.active=h(this.observer.set(e,t,r)):(this.active=h(this.observer.delete(e,t)),this.active&&(this.active=h(this.observer.insert(e,r)))))}}class u{constructor(){this._buffer=new Array(8),this.size=0}clear(){for(let e=0;e<this.size;++e)this._buffer[e]=void 0;this.size=0}push(e){this.size===this._buffer.length&&(this._buffer.length*=2),this._buffer[this.size]=e,++this.size}pop(){if(0!==this.size)return--this.size,this._buffer[this.size]}}class p{constructor(e,t){this._factory=e,this._stack=new u}clear(){this._stack.clear()}remove(){return 0===this._stack.size?this._factory():this._stack.pop()}add(e){this._stack.push(e)}}var f=a({name:"setOne (apply)",apply:(e,t,r,s)=>e[t]=s,applyWrapper:(e,t,r,s)=>s.set(e,t,r),invertName:"setOne (invert)",invert:(e,t,r,s)=>e[t]=r,invertWrapper:(e,t,r,s)=>s.set(e,r,t)});var d=a({name:"setMany (apply)",apply:(e,t,r,s)=>{for(let r=0;r<s.length;++r)e[t+r]=s[r]},applyWrapper:(e,t,r,s)=>{for(let i=0;i<r.length;++i)s.set(e+i,t[i],r[i])},invertName:"setMany (invert)",invert:(e,t,r,s)=>{for(let s=0;s<r.length;++s)e[t+s]=r[s]},invertWrapper:(e,t,r,s)=>{for(let i=0;i<t.length;++i)s.set(e+i,r[i],t[i])}});var g=a({name:"delete",apply:(e,t,r,s)=>e.splice(t,1),applyWrapper:(e,t,r,s)=>s.delete(e,t),invertName:"insert",invert:(e,t,r,s)=>e.splice(t,0,r),invertWrapper:(e,t,r,s)=>s.insert(e,t)});var _=a({name:"insert",apply:(e,t,r,s)=>e.splice(t,0,r),applyWrapper:(e,t,r,s)=>s.insert(e,t),invertName:"delete",invert:(e,t,r,s)=>e.splice(t,1),invertWrapper:(e,t,r,s)=>s.delete(e,t)});var w=a({name:"pushOne",apply:(e,t,r,s)=>e.push(r),applyWrapper:(e,t,r,s)=>s.push(e,t),invertName:"popOne",invert:(e,t,r,s)=>e.pop(),invertWrapper:(e,t,r,s)=>s.pop(e,t)});var y=a({name:"pushMany",apply:(e,t,r,s)=>e.push.apply(e,r),applyWrapper:(e,t,r,s)=>s.pushMany(e,t),invertName:"popMany",invert:(e,t,r,s)=>e.length-=r.length,invertWrapper:(e,t,r,s)=>{for(let r=t.length-1;r>=0;--r)s.pop(e+r,t[r])}});var v=a({name:"popOne",apply:(e,t,r,s)=>e.pop(),applyWrapper:(e,t,r,s)=>s.pop(e,t),invertName:"pushOne",invert:(e,t,r,s)=>e.push(r),invertWrapper:(e,t,r,s)=>s.push(e,t)});var m=a({name:"popMany",apply:(e,t,r,s)=>e.length-=r.length,applyWrapper:(e,t,r,s)=>{for(let r=t.length-1;r>=0;--r)s.pop(e+r,t[r])},invertName:"pushMany",invert:(e,t,r,s)=>e.push.apply(e,r),invertWrapper:(e,t,r,s)=>s.pushMany(e,t)});var b=a({name:"shiftOne",apply:(e,t,r,s)=>e.unshift(r),applyWrapper:(e,t,r,s)=>s.unshift(t),invertName:"unshiftOne",invert:(e,t,r,s)=>e.shift(),invertWrapper:(e,t,r,s)=>s.shift(t)});var k=a({name:"unshiftMany",apply:(e,t,r,s)=>e.unshift.apply(e,r),applyWrapper:(e,t,r,s)=>{for(let e=t.length-1;e>=0;--e)s.unshift(t[e])},invertName:"shiftMany",invert:(e,t,r,s)=>e.splice(0,r.length),invertWrapper:(e,t,r,s)=>{for(let e=0;e<t.length;++e)s.shift(t[e])}});var z=a({name:"shiftOne",apply:(e,t,r,s)=>e.shift(),applyWrapper:(e,t,r,s)=>s.shift(t),invertName:"unshiftOne",invert:(e,t,r,s)=>e.unshift(r),invertWrapper:(e,t,r,s)=>s.unshift(t)});var M=a({name:"shiftMany",apply:(e,t,r,s)=>e.splice(0,r.length),applyWrapper:(e,t,r,s)=>{for(let e=0;e<t.length;++e)s.shift(t[e])},invertName:"unshiftMany",invert:(e,t,r,s)=>e.unshift.apply(e,r),invertWrapper:(e,t,r,s)=>{for(let e=t.length-1;e>=0;--e)s.unshift(t[e])}});var S=a({name:"grow",apply:(e,t,r,s)=>e.length=r,applyWrapper:(e,t,r,s)=>{for(let r=e;r<t;++r)s.push(r,void 0)},invertName:"shrink",invert:(e,t,r,s)=>e.length=t,invertWrapper:(e,t,r,s)=>{for(let r=t-1;r>=e;--r)s.pop(r,void 0)}});var L=a({name:"splice (apply)",apply:(e,t,r,s)=>e.splice.apply(e,r),applyWrapper:(e,t,r,s)=>{for(let t=2;t<r.length;++t)s.delete(e,r[t]);for(let r=2;r<t.length;++r)s.insert(e+(r-2),t[r])},invertName:"splice (invert)",invert:(e,t,r,s)=>e.splice.apply(e,s),invertWrapper:(e,t,r,s)=>{for(let r=2;r<t.length;++r)s.delete(e,t[r]);for(let t=2;t<r.length;++t)s.insert(e+(t-2),r[t])}});var B=a({name:"delete many sparse",apply:(e,t,r,s)=>{if(0===r.length)return;let i=r[0],n=i,l=0;for(;n<e.length;){for(;n===r[l]&&n<e.length;)++n,++l;n<e.length&&(e[i++]=e[n++])}e.length-=r.length},applyWrapper:(e,t,r,s)=>{for(let e=t.length-1;e>=0;--e)s.delete(t[e],r[e])},invertName:"insert many sparse",invert:(e,t,r,s)=>{if(0===r.length)return;e.length+=r.length;let i=e.length-1,n=i-r.length,l=r.length-1;for(;i>=r[0];){for(;i===r[l]&&i>=0;)e[i]=s[l],--l,--i;i>=0&&(e[i--]=e[n--])}},invertWrapper:(e,t,r,s)=>{for(let e=0;e<t.length;++e)s.insert(t[e],r[e])}});function F(e){return!1!==e}class x{constructor(e){if(this.observer=e,this.active=!0,!e.insert)throw new Error("observer must implement an insert method");if(!e.delete)throw new Error("observer must implement a delete method")}insert(e){this.active&&(this.active=F(this.observer.insert(e)))}delete(e){this.active&&(this.active=F(this.observer.delete(e)))}clear(e){if(this.active)if(this.observer.clear)this.active=F(this.observer.clear());else for(let t of e){if(!this.active)break;this.delete(t)}}insertMany(e){if(this.active)if(this.observer.insertMany)this.active=F(this.observer.insertMany(e));else for(let t of e){if(!this.active)break;this.insert(t)}}}var I=a({name:"delete",apply:(e,t)=>e.delete(t),applyWrapper:(e,t)=>t.delete(e),invertName:"insert",invert:(e,t)=>e.add(t),invertWrapper:(e,t)=>t.insert(e)});var W=a({name:"insert",apply:(e,t)=>e.add(t),applyWrapper:(e,t)=>t.insert(e),invertName:"delete",invert:(e,t)=>e.delete(t),invertWrapper:(e,t)=>t.delete(e)});let C=new p(()=>new u);class A{constructor(){this.lockCount=0}lock(){this.lockCount++}unlock(){if(0===this.lockCount)throw new Error("attempting to unlock an already unlocked root");this.lockCount--}isLocked(){return this.lockCount>0}}class P{constructor(e,t){this._backing=e,this.size=e.size,this.root=t||new A,this._i=null,this._patchFunc=null,this._patchTarget=null}_ensureUnlocked(){if(this.root.isLocked())throw new Error("unable to create new versions of a locked set")}count(){return this.size}first(){const e=this._getBacking();for(let t of e)return t}clear(){return E}add(e){return this.has(e)?this:this._withPatch(W,e)}delete(e){return this.has(e)?1===this.size?E:this._withPatch(I,e):this}has(e){return this._getBacking().has(e)}toArray(){const e=this._getBacking();return Array.from(e)}toList(){return Z(this.toArray(),!0)}toSet(){return this}toJS(){return new Set(this._getBacking())}*[Symbol.iterator](){const e=this._getBacking();this.root.lock();try{yield*e}finally{this.root.unlock()}}forEach(e,t){let r=0;for(let s of this){if(!1===e.call(t,s,s,this))return r;++r}return this.size}observeChangesFor(e,t){if(this===e)return!0;const r=new x(t);if(e===E)return r.clear(this._getBacking()),r.active;if(this.root===e.root){e._getBacking();let t=this;for(;t!==e&&r.active;)t._patchFunc.inverse.callWrapper(t._i,r),e._getBacking(),t=t._patchTarget}else r.clear(this._getBacking()),r.active&&r.insertMany(e._getBacking());return r.active}toString(){let e="ImmySet { ",t=!0;for(let r of this._getBacking())t||(e+=", "),e+=`${l(r)}`,t=!1;return e+=" }"}inspect(){return this.toString()}_withPatch(e,t){this._ensureUnlocked(),e(this._getBacking(),t),this._i=t,this._patchFunc=e.inverse;const r=new P(this._backing,this.root);return this._patchTarget=r,this._backing=null,r}_getBacking(){if(null!=this._backing)return this._backing;if(this.root.isLocked())throw new Error("unable to get backing - the set root is locked");let e=C.remove(),t=this;for(;null!=t;)e.push(t),t=t._patchTarget;let r=e.pop();for(;e.size>0;){let t=e.pop();t._patchFunc(r._backing,t._i),t._backing=r._backing,r._patchTarget=t,r._patchFunc=t._patchFunc.inverse,r._i=t._i,r._backing=null,t._patchTarget=null,t._patchFunc=null,t._i=null,r=t}return C.add(e),this._backing}}let E=null;function O(e,t){if(0===arguments.length||null==e)return E;if(e instanceof Set)return 0===e.size?E:new P(!0===t?e:new Set(e));if(e instanceof P)return new P(new Set(e._getBacking()));if(Array.isArray(e))return 0===e.length?E:new P(new Set(e));if(null!=e){let t=new Set(e);return 0===t.size?E:new P(t)}}function T(e){return!1!==e}E=new class{constructor(){this.size=0,this.root={}}count(){return 0}first(){}add(e){return new P(new Set).add(e)}clear(){return this}delete(e){return this}has(e){return!1}toArray(){return[]}toSet(){return this}toList(){return Y}toJS(){return new Set}forEach(e){return 0}*[Symbol.iterator](){}observeChangesFor(e,t){e!==this&&new x(t).insertMany(e._getBacking())}toString(){return"ImmySet {}"}inspect(){return this.toString()}};class N{constructor(e){if(this.observer=e,this.active=!0,!e.insert)throw new Error("observer must implement an insert method");if(!e.delete)throw new Error("observer must implement a delete method")}insert(e,t){this.active&&(this.active=T(this.observer.insert(e,t)))}delete(e,t){this.active&&(this.active=T(this.observer.delete(e,t)))}clear(e){if(this.active)if(this.observer.clear)this.active=T(this.observer.clear());else for(let[t,r]of e){if(!this.active)break;this.delete(t,r)}}insertMany(e){if(this.active)if(this.observer.insertMany)this.active=T(this.observer.insertMany(e));else for(let[t,r]of e){if(!this.active)break;this.insert(t,r)}}set(e,t,r){this.active&&(this.observer.set?this.active=T(this.observer.set(e,t,r)):(this.active=T(this.observer.delete(e,t)),this.active&&(this.active=T(this.observer.insert(e,r)))))}}var K=a({name:"delete",apply:(e,t,r,s)=>e.delete(t),applyWrapper:(e,t,r,s)=>s.delete(e,t),invertName:"insert",invert:(e,t,r,s)=>e.set(t,r),invertWrapper:(e,t,r,s)=>s.insert(e,t)});var $=a({name:"insert",apply:(e,t,r,s)=>e.set(t,r),applyWrapper:(e,t,r,s)=>s.insert(e,t),invertName:"delete",invert:(e,t,r,s)=>e.delete(t),invertWrapper:(e,t,r,s)=>s.delete(e)});var V=a({name:"update",apply:(e,t,r,s)=>e.set(t,s),applyWrapper:(e,t,r,s)=>s.set(e,t,r),invertName:"update (inverse)",invert:(e,t,r,s)=>e.set(t,r),invertWrapper:(e,t,r,s)=>s.set(e,r,t)});let J=new p(()=>new u);class j{constructor(){this.lockCount=0}lock(){this.lockCount++}unlock(){if(0===this.lockCount)throw new Error("attempting to unlock an already unlocked root");this.lockCount--}isLocked(){return this.lockCount>0}}class U{constructor(e,t){this._backing=e,this.size=e.size,this.root=t||new j,this._i=null,this._x=null,this._y=null,this._patchFunc=null,this._patchTarget=null}_ensureUnlocked(){if(this.root.isLocked())throw new Error("unable to create new versions of a locked map")}clear(){return G}set(e,t){const r=this.get(e);return void 0===r?void 0===t?this:this.has(e)?this._withPatch(V,e,r,t):this._withPatch($,e,t,null):r===t?this:this._withPatch(V,e,r,t)}get(e){return this._getBacking().get(e)}has(e){return this._getBacking().has(e)}delete(e){const t=this.get(e);return void 0!==t||this.has(e)?1===this.size?G:this._withPatch(K,e,t,null):this}update(e,t){return this.set(e,t(this.get(e)))}toArray(){throw new Error("not done yet")}map(e,t){let r=new Map;for(let[s,i]of this)r.set(s,e.call(t,i,s,this));return new U(r)}forEach(e,t){let r=0;for(let[s,i]of this){if(!1===e.call(t,i,s,this))return r;++r}return this.size}filter(e,t){let r=new Map;for(let[s,i]of this)e.call(t,i,s,this)&&r.set(s,i);return new U(r)}toList(){let e=[];for(let[t,r]of this)e.push(r);return Z(e,!0)}toSet(){let e=[];for(let[t,r]of this)e.push(r);return O(e)}toMap(){return this}toJS(){return new Map(this._getBacking())}*[Symbol.iterator](){const e=this._getBacking();this.root.lock();try{yield*e}finally{this.root.unlock()}}observeChangesFor(e,t){if(this===e)return!0;const r=new N(t);if(e===G)return r.clear(this._getBacking()),r.active;if(this.root===e.root){e._getBacking();let t=this;for(;t!==e&&r.active;)t._patchFunc.inverse.callWrapper(t._i,t._x,t._y,r),e._getBacking(),t=t._patchTarget}else r.clear(this._getBacking()),r.active&&r.insertMany(e._getBacking());return r.active}toString(){let e="ImmyMap { ",t=!0;for(let[r,s]of this._getBacking())t||(e+=", "),e+=`${l(r)}: ${l(s)}`,t=!1;return e+=" }"}inspect(){return this.toString()}_withPatch(e,t,r,s){this._ensureUnlocked(),e(this._getBacking(),t,r,s),this._i=t,this._x=r,this._y=s,this._patchFunc=e.inverse;const i=new U(this._backing,this.root);return this._patchTarget=i,this._backing=null,i}_getBacking(){if(null!=this._backing)return this._backing;if(this.root.isLocked())throw new Error("unable to get backing - the map root is locked");let e=J.remove(),t=this;for(;null!=t;)e.push(t),t=t._patchTarget;let r=e.pop();for(;e.size>0;){let t=e.pop();t._patchFunc(r._backing,t._i,t._x,t._y),t._backing=r._backing,r._patchTarget=t,r._patchFunc=t._patchFunc.inverse,r._i=t._i,r._x=t._x,r._y=t._y,r._backing=null,t._patchTarget=null,t._patchFunc=null,t._i=null,t._x=null,t._y=null,r=t}return J.add(e),this._backing}}let G=null;function R(e,t){if(0===arguments.length||null==e)return G;if(e instanceof Map)return 0===e.size?G:new U(!0===t?e:new Map(e));if(e instanceof U)return new U(new Map(e._getBacking()));if(null!=e){let t=new Map(e);return 0===t.size?G:new U(t)}}G=new class{constructor(){this.size=0,this.root={}}clear(){return this}set(e,t){return new U(new Map).set(e,t)}get(e){}has(e){return!1}delete(e){return this}map(e,t){return this}forEach(e,t){return 0}filter(e,t){return this}toList(){return Y}toSet(){return E}toArray(){return[]}toMap(){return this}toJS(){return new Map}*[Symbol.iterator](){}observeChangesFor(e,t){e!==this&&new N(t).insertMany(e._getBacking())}toString(){return"ImmyMap {}"}inspect(){return this.toString()}};const q=e=>e;let D=new p(()=>new u),H=new p(()=>new class{constructor(){this._buffer=new Array(8),this._begin=0,this._end=0,this.size=0}clear(){for(let e=this._begin;e<this._end;++e)this._buffer[e]=void 0;this._begin=0,this._end=0,this.size=0}push(e){++this.size,this._buffer[this._end++]=e}shift(){if(0===this.size)return;const e=this._buffer[this._begin];return this._buffer[this._begin++]=void 0,--this.size,0===this.size&&(this._begin=0,this._end=0),e}}),Q=new p(()=>({index:-1,value:null}));class X{constructor(e,t){this._backing=e,this.size=e.length,this.root=t||{},this._i=-1,this._x=null,this._y=null,this._patchFunc=null,this._patchTarget=null}count(){return this.size}first(){return this.get(0)}isEmpty(){return 0===this.size}last(){return this.get(this.size-1)}set(e,t){if(e<0&&(e=this.size+e),e<0){let r=new Array(Math.abs(e));return r[0]=t,this._withPatch(k,0,r,null)}return e===this.size?this.push(t):e<this.size?this.get(e)===t?this:this._withPatch(f,e,this._getBacking()[e],t):this.setSize(e+1).set(e,t)}get(e){if(e<0&&(e=this.size+e),!(e<0||e>=this.size))return this._getBacking()[e]}delete(e){return e<0&&(e=this.size+e),e<=0?this.shift():e>=this.size?this.pop():this._withPatch(g,e,this._getBacking()[e],null)}insert(e,t){return e<0&&(e=this.size+e),e<=0?this.unshift(t):e>=this.size?this.push(t):this._withPatch(_,e,t,null)}insertSorted(e,t){void 0===t&&(t=q);const r=t(e),s=this.binaryFindInsertionIndexByKey(r,t);return this.insert(s,e)}updateSorted(e,t){void 0===t&&(t=q);const r=this.indexOfSorted(e,t);if(r<0)throw new Error("unable to update the given value - it is not in the list");return this.set(r,e)}deleteSorted(e,t){void 0===t&&(t=q);const r=this.indexOfSorted(e,t);if(r<0)throw new Error("unable to delete the given value - it is not in the list");return this.delete(r)}indexOfSorted(e,t){void 0===t&&(t=q);const r=t(e);return this.binaryFindIndexByKey(r,t)}indexOf(e){const t=this._getBacking();for(let r=0;r<t.length;++r)if(t[r]===e)return r;return-1}binaryFindByKey(e,t,r){const s=this.binaryFindIndexByKey(e,t);return s<0?r:this.get(s)}binaryFindIndex(e,t){let r,s,i=0,n=this.size-1;if(0===this.size)return-1;for(;i<=n;){r=(i+n)/2|0;let l=t(e,s=this.get(r));if(l>0)i=r+1;else{if(!(l<0)){for(;r<this.size-1&&0===t(e,this.get(r+1));)++r;return r}n=r-1}}return n>=0&&n<this.size&&0===t(e,this.get(n))?n:i>=0&&i<this.size&&0===t(e,this.get(i))?i:-1}binaryFindIndexByKey(e,t){return void 0===t&&(t=q),this.binaryFindIndex(e,(e,r)=>o(e,t(r)))}binaryFindInsertionIndex(e,t){if(0===this.size)return 0;let r,s,i=0,n=this.size-1;for(;i<=n;){r=(i+n)/2|0;let l=t(e,s=this.get(r));if(l>0)i=r+1;else{if(!(l<0)){for(;r<this.size-1&&0==t(e,this.get(r+1));)++r;return r+1}n=r-1}}return t(e,this.get(r))<0?r:r+1}binaryFindInsertionIndexByKey(e,t){return void 0===t&&(t=q),this.binaryFindInsertionIndex(e,(e,r)=>o(e,t(r)))}clear(){return Y}push(){if(0===arguments.length)return this;if(1===arguments.length)return this._withPatch(w,this.size,arguments[0],null);{const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return this._withPatch(y,this.size,e,null)}}pop(){if(this.size<=1)return Y;{const e=this.size-1;return this._withPatch(v,e,this._getBacking()[e],null)}}popMany(e){if(0===e)return this;if(this.size-e<=0)return Y;if(1===e)return this.pop();{const t=this._getBacking(),r=new Array(e),s=t.length-e;for(let i=0;i<e;++i)r[i]=t[s+i];return this._withPatch(m,s,r,null)}}unshift(){if(0===arguments.length)return this;if(1===arguments.length)return this._withPatch(b,0,arguments[0],null);{const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return this._withPatch(k,0,e,null)}}shift(){return this.size<=1?Y:this._withPatch(z,0,this._getBacking()[0],null)}shiftMany(e){if(0===e)return this;if(this.size-e<=0)return Y;if(1===e)return this.shift();{const t=this._getBacking(),r=new Array(e);for(let s=0;s<e;++s)r[s]=t[s];return this._withPatch(M,0,r,null)}}setSize(e){return 0===e?Y:e===this.size?this:e<this.size?this.splice(this.size-e+1):this._withPatch(S,this.size,e,null)}splice(){if(0===arguments.length)return this;let e=arguments[0];e<0?(e=Math.max(this.size+e,0),arguments[0]=e):e>=this.size&&(e=this.size,arguments[0]=e);let t=this.size-e;if(arguments.length>=2&&(t=Math.min(arguments[1],this.size-e),arguments[1]=t),arguments.length<=2&&0===t)return this;if(arguments.length<=2&&t>0)return 0===e&&t===this.size?Y:e+t===this.size?this.popMany(t):0===e?this.shiftMany(t):this._spliceImpl.apply(this,arguments);if(arguments.length>2&&0===t){if(3===arguments.length)return e>=this.size?this.push(arguments[2]):e<=0?this.unshift(arguments[2]):this.insert(e,arguments[2]);if(e<=0||e>=this.size){const t=new Array(arguments.length-2);for(let e=2;e<arguments.length;++e)t[e-2]=arguments[e];return e<=0?this._withPatch(k,0,t,null):this._withPatch(y,this.size,t,null)}return this._spliceImpl.apply(this,arguments)}if(arguments.length>2&&arguments.length-2===t){if(1===t)return this.set(e,arguments[2]);{const r=this._getBacking(),s=new Array(t);for(let i=0;i<t;++i)s[i]=r[e+i];let i=!0;const n=new Array(arguments.length-2);for(let e=0;e<arguments.length-2;++e)n[e]=arguments[e+2],s[e]!==n[e]&&(i=!1);return i?this:this._withPatch(d,e,s,n)}}return this._spliceImpl.apply(this,arguments)}toList(){return this}toSet(){return O(new Set(this._getBacking()),!0)}toArray(){return this._getBacking().slice()}toJS(){return this.toArray()}indexOf(e){return this._getBacking().indexOf(e)}find(e,t,r){for(let r=0;r<this.size;++r){const s=this.get(r);if(e.call(t,s,r,this))return s}return r}findIndex(e,t){for(let r=0;r<this.size;++r)if(e.call(t,this.get(r),r,this))return r;return-1}*[Symbol.iterator](){for(let e=0;e<this.size;++e)yield this.get(e)}forEach(e,t){for(let r=0;r<this.size;++r)if(!1===e.call(t,this.get(r),r,this))return r;return this.size}map(e,t){let r=new Array(this.size);for(let s=0;s<this.size;++s){const i=this.get(s);r[s]=e.call(t,i,s,this)}return new X(r)}pureMap(e){let t=new Array(this.size);for(let r=0;r<this.size;++r)t[r]=e(this.get(r));return new X(t)}mapInPlace(e,t){let r=H.remove();for(let s=0;s<this.size;++s){const i=this.get(s),n=e.call(t,i,s,this);if(n!==i){let e=Q.remove();e.index=s,e.value=n,r.push(e)}}let s=this;for(;r.size>0;){const e=r.shift();s=s.set(e.index,e.value),e.index=-1,e.value=null,Q.add(e)}return H.add(r),s}filter(e,t){let r=new Array(this.size),s=0;for(let i=0;i<this.size;++i){const n=this.get(i);e.call(t,n,i,this)&&(r[s++]=n)}return r.length=s,0===r.length?Y:r.length===this.size?this:new X(r)}filterInPlace(e,t){let r=null,s=null,i=0;for(;i<this.size;++i){const n=this.get(i);if(!e.call(t,n,i,this)){r=[i],s=[n],++i;break}}for(;i<this.size;++i){const n=this.get(i);e.call(t,n,i,this)||(r.push(i),s.push(n))}return null==r?this:r.length===this.size?Y:this._withPatch(B,-1,r,s)}sort(e){return this.sortBy(q,e)}sortBy(e,t){null==e&&(e=q),null==t&&(t=o);let r=this.toArray();return r.sort((r,s)=>{const i=e(r),n=e(s);return t(i,n)}),new X(r)}flatMap(e,t){let r=[];for(let s=0;s<this.size;++s){const i=this.get(s),n=e.call(t,i,s,this);for(let e of n)r.push(e)}return new X(r)}groupBy(e,t){let r=new Map;for(let s=0;s<this.size;++s){const i=this.get(s),n=e.call(t,i,s,this);r.set(n,(r.get(n)||Z()).push(i))}return R(r,!0)}reduce(e,t,r){let s=t,i=0;for(1===arguments.length&&(s=this.get(0),i=1);i<this.size;++i)s=e.call(r,s,this.get(i),i,this);return s}observeChangesFor(e,t){if(this===e)return!0;const r=new c(t);if(e===Y)return r.clear(this._getBacking()),r.active;if(this.root===e.root){e._getBacking();let t=this;for(;t!==e&&r.active;)t._patchFunc.inverse.callWrapper(t._i,t._x,t._y,r),e._getBacking(),t=t._patchTarget}else r.clear(this._getBacking()),r.active&&r.pushMany(0,e._getBacking());return r.active}toString(){if(this.size<13)return`ImmyList(${this.size}) [ `+this._getBacking().map(e=>l(e)).join(", ")+" ]";{let e=`ImmyList(${this.size}) [ `;for(let t=0;t<10;++t)t>0&&(e+=", "),e+=l(this.get(t));return e+=`, ... , ${l(this.get(-2))}, ${l(this.get(-1))} ]`}}inspect(){return this.toString()}_withPatch(e,t,r,s){return e(this._getBacking(),t,r,s),this._afterPatch(e,t,r,s)}_afterPatch(e,t,r,s){this._i=t,this._x=r,this._y=s,this._patchFunc=e.inverse;const i=new X(this._backing,this.root);return this._patchTarget=i,this._backing=null,i}_getBacking(){if(null!=this._backing)return this._backing;let e=D.remove(),t=this;for(;null!=t;)e.push(t),t=t._patchTarget;let r=e.pop();for(;e.size>0;){let t=e.pop();t._patchFunc(r._backing,t._i,t._x,t._y),t._backing=r._backing,r._patchTarget=t,r._patchFunc=t._patchFunc.inverse,r._i=t._i,r._x=t._x,r._y=t._y,r._backing=null,t._patchTarget=null,t._patchFunc=null,t._i=-1,t._x=null,t._y=null,r=t}return D.add(e),this._backing}_spliceImpl(){const e=this._getBacking();let t=e.splice.apply(e,arguments);t.unshift(arguments[0],arguments.length-2);let r=new Array(arguments.length);for(let e=0;e<arguments.length;++e)r[e]=arguments[e];return this._afterPatch(L,arguments[0],r,t)}}let Y=null;function Z(e,t){if(0===arguments.length)return Y;if(Array.isArray(e))return 0===e.length?Y:new X(!0===t?e:e.slice());if(e instanceof X)return new X(e._getBacking().slice());{let t=[];for(let r of e)t.push(r);return 0===t.length?Y:new X(t)}}function ee(e){return null!=e&&(e===Y||e instanceof X)}Y=new class{constructor(){this.size=0,this.root={}}count(){return 0}first(){}last(){}set(e,t){return new X([]).set(e,t)}get(e){}delete(e){return this}insert(e,t){return new X([]).insert(e,t)}insertSorted(e,t){return new X([]).insertSorted(e,t)}indexOfSorted(e,t){return-1}binaryFindByKey(e,t,r){return r}binaryFindIndexByKey(e,t){return-1}binaryFindInsertionIndex(e,t){return 0}binaryFindInsertionIndexByKey(e,t){return 0}clear(){return this}push(){const e=new X([]);return e.push.apply(e,arguments)}pop(){return this}popMany(){return this}unshift(){const e=new X([]);return e.unshift.apply(e,arguments)}shift(){return this}shiftMany(){return this}setSize(e){return 0===e?this:new X(new Array(e))}splice(){const e=new X([]);return e.splice.apply(e,arguments)}isEmpty(){return!0}toList(){return this}toArray(){return[]}toJS(){return this.toArray()}toSet(){return E}indexOf(){return-1}find(e,t,r){return r}findIndex(e,t){return-1}*[Symbol.iterator](){}forEach(e){return 0}map(e){return this}pureMap(e){return this}mapInPlace(e){return this}filter(e){return this}filterInPlace(e){return this}sort(e){return this}sortBy(e,t){return this}flatMap(e,t){return this}groupBy(e,t){return G}reduce(e,t){return t}observeChangesFor(e,t){e!==this&&new c(t).pushMany(0,e._getBacking().slice())}toString(){return"ImmyList(0) []"}inspect(){return this.toString()}};class te{constructor(e=8){this._maxSize=e,this._weakMaps=[]}clear(){this._weakMaps=[]}swap(e,t){let r=null,s=void 0;for(let t=0;t<this._weakMaps.length;++t)if(void 0!==(s=this._weakMaps[t].get(e))){r=this._weakMaps[t],this._weakMaps.splice(t,1);break}return null==r&&(r=new WeakMap),r.set(e,t),this._weakMaps.unshift(r),this._weakMaps.length>=this._maxSize&&(this._weakMaps.length=this._maxSize),s}}const re=Z();class se{constructor(e){this.mapper=e,this._cache=new te(2)}select(e){if(e===re)return re;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.mappedList;return t=null,r.observeChangesFor(e,{insert:(e,t)=>s=s.insert(e,this.mapper(t)),delete:(e,t)=>s=s.delete(e),set:(e,t)=>s=s.set(e,this.mapper(t))}),t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}let r=new Array(e.size-1);for(let t=0;t<e.size-1;++t)r[t]=this.mapper(e.get(t));r.push(this.mapper(e.get(e.size-1)));let s=Z(r,!0);return t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}}const ie=Z();class ne{constructor(e){this.predicate=e,this._cache=new te(2)}select(e){if(e===ie)return ie;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.filteredList,i=t.translation;return t=null,r.observeChangesFor(e,{insert:(e,t)=>{let r=!1,n=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r||(n=t,r=!0),i[t]+=1);this.predicate(t)&&(i.splice(n,0,e),s=s.insert(n,t))},delete:(e,t)=>{let r=!1,n=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r||(n=t,r=!0),i[t]-=1);this.predicate(t)&&(i.splice(n,1),s=s.delete(n))},push:e=>{this.predicate(e)&&(i.push(s.size),s=s.push(e))}}),t={srcList:e,filteredList:s,translation:i},this._cache.swap(e.root,t),s}let r=[],s=[];for(let t=0;t<e.size;++t){const i=e.get(t);this.predicate(i)&&(r.push(i),s.push(t))}let i=Z(r,!0);return t={srcList:e,filteredList:i,translation:s},this._cache.swap(e.root,t),i}}class le{constructor(e,t){this.reducer=e,this.initialValue=t}select(e){return e.reduce(this.reducer,this.initialValue)}}class ae{constructor(e){this.reducer=e,this._cache=new te(2)}select(e){if(0===e.size)return;if(1===e.size)return e.get(0);let t=this._cache.swap(e.root,null);if(null!=t){console.log("cache hit");let r=t.srcList,s=t.reductionCache;return t=null,r.observeChangesFor(e,{insert:(e,t)=>{console.log("+",e,t)},delete:(e,t)=>{console.log("-",e,t)}}),t={srcList:e,reductionCache:s},this._cache.swap(e.root,t),null}console.log("cache miss");let r=e.get(0),s=Math.floor(e.size/2),i=[];for(let t=1;t<e.size;++t)r=this.reducer(r,e.get(t)),t>=s&&(i.push({index:t,reduction:r}),s=Math.floor(t+(e.size-t)/2));return t={srcList:e,reductionCache:i},this._cache.swap(e.root,t),r}}function oe(e,t){if(e instanceof se&&t instanceof se){const r=e.mapper,s=t.mapper;return new se(e=>s(r(e)))}if(e instanceof ne&&t instanceof ne){const r=e.predicate,s=t.predicate;return new ne(e=>r(e)&&s(e))}return null}function he(e){const t=t=>{for(let r of e)t=r.select(t);return t};return(e=function(e){let t=[];for(let r of e)if(t.length>0){const e=oe(t[t.length-1],r);null==e?t.push(r):(t.pop(),t.push(e))}else t.push(r);return t}(e))[e.length-1]instanceof le||e[e.length-1]instanceof ae?(t.map=(()=>{throw new Error("unable to use list selection operations after a reduction")}),t.filter=(()=>{throw new Error("unable to use list selection operations after a reduction")}),t.reduce=(()=>{throw new Error("unable to use list selection operations after a reduction")}),t.asType=(()=>{throw new Error("unable to use list selection operations after a reduction")})):(t.map=(t=>he([...e,new se(t)])),t.filter=(t=>he([...e,new ne(t)])),t.reduce=function(t,r){return arguments.length>1?he([...e,new le(t,r)]):he([...e,new ae(t)])},t.asType=(()=>t)),t}function ce(e){return he([new se(e)])}function ue(e){return he([new ne(e)])}function pe(e,t){return arguments.length>1?he([new le(e,t)]):he([new ae(e)])}function fe(){return he([])}class de{constructor(e,t){this.getSecondaryKey=e,this.combiner=t,this._cache=new te(2)}combine(e,t){let r=new Set;const s=e=>{const s=t.find(t=>this.getSecondaryKey(t)===e);return r.add(e),s};let i=this._cache.swap(e.root,null);if(null!=i&&i.secondaryRoot===t.root){const n=i.primaryList,l=i.secondaryList;let a=i.combined,o=i.primaryToSecondaries,h=i.secondaryToPrimaries;i=null;const c=e=>{const t=this.combiner(e,s);o.set(e,r);for(let t of r)h.has(t)?h.get(t).add(e):h.set(t,new Set([e]));return r=new Set,t};let u=null;if(l!==t&&(u=new Set,l.observeChangesFor(t,{insert:(e,t)=>{const r=this.getSecondaryKey(t),s=h.get(r);if(s)for(let e of s)o.delete(e),u.add(e);h.delete(r)},delete:(e,t)=>{const r=this.getSecondaryKey(t),s=h.get(r);if(s)for(let e of s)o.delete(e),u.add(e);h.delete(r)}})),n!==e&&n.observeChangesFor(e,{insert:(e,t)=>{a=a.insert(e,c(t))},delete:(e,t)=>{const r=o.get(t);if(r)for(let e of r)h.get(e).delete(t);o.delete(t),a=a.delete(e)},set:(e,t,r)=>{const s=o.get(t);if(s)for(let e of s)h.get(e).delete(t);o.delete(t),a=a.set(e,c(r))}}),null!=u&&u.size>0)for(let t=0;t<e.size;++t){const r=e.get(t);u.has(r)&&(a=a.set(t,c(r)))}return i={secondaryRoot:t.root,primaryList:e,secondaryList:t,combined:a,primaryToSecondaries:o,secondaryToPrimaries:h},this._cache.swap(e.root,i),a}i=null;let n=Z(),l=new Map,a=new Map;for(let t=0;t<e.size;++t){const i=e.get(t),o=this.combiner(i,s);l.set(i,r);for(let e of r)a.has(e)?a.get(e).add(i):a.set(e,new Set([i]));r=new Set,n=n.push(o)}return i={secondaryRoot:t.root,primaryList:e,secondaryList:t,combined:n,primaryToSecondaries:l,secondaryToPrimaries:a},this._cache.swap(e.root,i),n}}function ge(e,t){const r=new de(e,t);return(e,t)=>r.combine(e,t)}class _e{constructor(){this.cache=new WeakMap}swap(e,t,r){const s=this.cache.get(e);return null==t?this.cache.delete(e):this.cache.set(e,t),null==s&&null!=r?r():s}}class we{constructor(e){this.predicate=e,this._cache=new _e}select(e){if(0===e.size)return e;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.filteredList,i=t.translation;return t=null,r.observeChangesFor(e,{insert:(e,t)=>{let r=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r<0&&(r=t),i[t]+=1);r<0&&(r=i.length),this.predicate(t)&&(i.splice(r,0,e),s=s.insert(r,t))},delete:(e,t)=>{let r=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r<0&&(r=t),i[t]-=1);if(this.predicate(t)){if(r<0)throw new Error("trying to delete from filtered list but could not find item to delete");i.splice(r,1),s=s.delete(r)}},push:(e,t)=>{this.predicate(e)&&(i.push(t),s=s.push(e))}}),t={srcList:e,filteredList:s,translation:i},this._cache.swap(e.root,t),s}let r=[],s=[];for(let t=0;t<e.size;++t){const i=e.get(t);this.predicate(i)&&(r.push(i),s.push(t))}let i=Z(r,!0);return t={srcList:e,filteredList:i,translation:s},this._cache.swap(e.root,t),i}}class ye{constructor(e){this.mapper=e,this._cache=new _e(2)}select(e){if(0===e.size)return e;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.mappedList;return t=null,r.observeChangesFor(e,{insert:(e,t)=>s=s.insert(e,this.mapper(t)),delete:(e,t)=>s=s.delete(e),set:(e,t,r)=>s=s.set(e,this.mapper(r))}),t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}let r=new Array(e.size-1);for(let t=0;t<e.size-1;++t)r[t]=this.mapper(e.get(t));r.push(this.mapper(e.get(e.size-1)));let s=Z(r,!0);return t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}}class ve{constructor(e){this.mapper=e,this._cache=new _e(2)}select(e){if(0===e.size)return e;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcMap,s=t.mappedMap;return t=null,r.observeChangesFor(e,{insert:(e,t)=>s=s.set(e,this.mapper(t)),delete:(e,t)=>s=s.delete(e),set:(e,t,r)=>s=s.set(e,this.mapper(r))}),t={srcMap:e,mappedMap:s},this._cache.swap(e.root,t),s}let r=new Map;for(let[t,s]of e)r.set(t,this.mapper(s));let s=R(r,!0);return t={srcMap:e,mappedMap:s},this._cache.swap(e.root,t),s}}class me{constructor(e,t){null==t&&(t=(e=>e)),this.grouper=e,this.valueSelector=t,this._cache=new _e}select(e){let{oldSrcList:t,oldGrouped:r}=this._cache.swap(e.root,null,()=>({oldSrcList:Z(),oldGrouped:R()}));return t.observeChangesFor(e,{insert:(e,t)=>{const s=this.grouper(t);r=r.has(s)?r.set(s,r.get(s).push(this.valueSelector(t))):r.set(s,Z([this.valueSelector(t)]))},delete:(e,t)=>{const s=this.grouper(t);let i=r.get(s);if(null==i)throw new Error("expected to find a group");let n=i.indexOf(this.valueSelector(t));i=i.delete(n),r=0===i.size?r.delete(s):r.set(s,i)}}),this._cache.swap(e.root,{oldSrcList:e,oldGrouped:r}),r}}class be{constructor(){this._cache=new _e}select(e){if(0===e.size)return R();if(!Array.isArray(e.get(0))||2!=e.get(0).length)throw new Error("toMap() expects a list of [key, value] pairs as its input");let{oldSrcList:t,oldMap:r}=this._cache.swap(e.root,null,()=>({oldSrcList:Z(),oldMap:R()}));return t.observeChangesFor(e,{insert:(e,t)=>{r=r.set(t[0],t[1])},delete:(e,t)=>{r=r.delete(t[0])}}),this._cache.swap(e.root,{oldSrcList:e,oldMap:r}),r}}class ke{constructor(e){this.orderSelector=e,this._cache=new _e}select(e){if(0===e.size)return e;let{oldSrcList:t,oldOrderedList:r}=this._cache.swap(e.root,null,()=>({oldSrcList:null,oldOrderedList:null}));if(null==t){let t=e.toArray();t.sort((e,t)=>{return o(this.orderSelector(e),this.orderSelector(t))}),r=Z(t,!0)}else t.observeChangesFor(e,{insert:(e,t)=>{const s=r.binaryFindInsertionIndexByKey(this.orderSelector(t),this.orderSelector);r=r.insert(s,t)},delete:(e,t)=>{const s=r.binaryFindIndexByKey(this.orderSelector(t),this.orderSelector);r=r.delete(s)}});return this._cache.swap(e.root,{oldSrcList:e,oldOrderedList:r}),r}}class ze{constructor(e){null==e&&(e=(e=>e)),this.ungrouper=e,this._cache=new _e}select(e){let{oldSrcMap:t,oldUngroupedList:r,oldIndexOffsetMap:s}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldUngroupedList:Z(),oldIndexOffsetMap:new Map}));return t.observeChangesFor(e,{insert:(e,t)=>{let i=r.size;s.set(e,i);for(let s of t)r=r.push(this.ungrouper(s,e))},delete:(e,t)=>{let i=s.get(e),n=-t.size;r=r.splice(i,t.size),s.delete(e);for(let[e,t]of s)t>i&&s.set(e,t+n)},set:(e,t,i)=>{const n=s.get(e);t.observeChangesFor(i,{insert:(t,s)=>{r=r.insert(n+t,this.ungrouper(s,e))},delete:(e,t)=>{r=r.delete(n+e)},set:(t,s,i)=>{r=r.set(n+t,this.ungrouper(i,e))}}),0===i.size&&s.delete(e);let l=i.size-t.size;for(let[e,t]of s)t>n&&s.set(e,t+l)}}),this._cache.swap(e.root,{oldSrcMap:e,oldUngroupedList:r,oldIndexOffsetMap:s}),r}}class Me{constructor(){this._cache=new _e}select(e){let{oldSrcMap:t,oldKeysList:r}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldKeysList:Z()}));return t.observeChangesFor(e,{insert:(e,t)=>{r=r.push(e)},delete:(e,t)=>{const s=r.indexOf(e);if(s<0)throw new Error("unable to find index of key");r=r.delete(s)},set:(e,t,r)=>{}}),this._cache.swap(e.root,{oldSrcMap:e,oldKeysList:r}),r}}class Se{constructor(){this._cache=new _e}select(e){let{oldSrcMap:t,oldValuesList:r,oldIndexOffsetMap:s}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldValuesList:Z(),oldIndexOffsetMap:new Map}));return t.observeChangesFor(e,{insert:(e,t)=>{let i=r.size;s.set(e,i),r=r.push(t)},delete:(e,t)=>{let i=s.get(e);r=r.splice(i,1),s.delete(e);for(let[e,t]of s)t>i&&s.set(e,t+-1)},set:(e,t,i)=>{const n=s.get(e);r=r.set(n,i)}}),this._cache.swap(e.root,{oldSrcMap:e,oldValuesList:r,oldIndexOffsetMap:s}),r}}class Le{constructor(){this._root=new WeakMap}swap(e,t,r){if(0===e.length)throw new Error("must have at least one key");return this.__swap(this._root,0,e,t,r)}__swap(e,t,r,s,i){const n=r[t];if(t===r.length-1){const t=e.get(n);return null==s?e.delete(n):e.set(n,s),null==t&&null!=i?i():t}{let l=e.get(n);return null==l&&(l=new WeakMap,e.set(n,l)),this.__swap(l,t+1,r,s,i)}}}class Be{constructor(e,t){this.secondarySelector=e,this.joiner=t,this.needsOriginalInput=!0,this._cache=new Le,this._resolveManyCache=new _e}select(e,t){const r=this.secondarySelector(t);if(0===e.size)return R();let{oldSrcMap:s,oldSecondaryMap:i,oldJoinedMap:n,secondariesByPrimary:l,primaryBySecondary:a}=this._cache.swap([e.root,r.root],null,()=>({oldSrcMap:R(),oldSecondaryMap:R(),oldJoinedMap:R(),secondariesByPrimary:new Map,primaryBySecondary:new Map})),o=new Set,h=e=>{let t=a.get(e);if(null!=t){for(let e of l.get(t))a.delete(e);l.delete(t),o.add(t)}};i.observeChangesFor(r,{insert:h,delete:h}),s.observeChangesFor(e,{insert:(e,t)=>{o.add(e)},delete:(e,t)=>{o.delete(e);let r=l.get(e);if(null!=r)for(let e of r)a.delete(e);l.delete(e)}});for(let t of o){let s=new Set,i=e=>null==e?null:(s.add(e),r.get(e)),o=e=>{if(null==e||0===e.size)return Z();let{oldSecondaryKeys:t,oldSecondaryValues:r}=this._resolveManyCache.swap(e.root,null,()=>({oldSecondaryKeys:Z(),oldSecondaryValues:Z()}));t.observeChangesFor(e,{insert:(e,t)=>{r=r.insert(e,i(t))},delete:(e,t)=>{r=r.delete(e)},set:(e,t,s)=>{r=r.set(e,i(s))}});for(let t=0;t<e.size;++t)r=r.set(t,i(e.get(t)));return this._resolveManyCache.swap(e.root,{oldSecondaryKeys:e,oldSecondaryValues:r}),r},h=this.joiner(t,e.get(t),i,o);n=n.set(t,h);for(let e of s)a.set(e,t);l.set(t,s)}return this._cache.swap([e.root,r.root],{oldSrcMap:e,oldSecondaryMap:r,oldJoinedMap:n,secondariesByPrimary:l,primaryBySecondary:a}),n}}class Fe{constructor(e){null==e&&(e="ListTracer"),this.name=e,this._cache=new _e}select(e){let t=this._cache.swap(e.root,null);return null==t&&(console.log(`[${this.name}] (cache miss)`),t=Z()),t.observeChangesFor(e,{insert:(e,t)=>console.log(`[${this.name}] insert`,e,t),delete:(e,t)=>console.log(`[${this.name}] delete`,e,t),set:(e,t,r)=>console.log(`[${this.name}] set`,e,t,r)}),this._cache.swap(e.root,t),e}}class xe{constructor(e){null==e&&(e="MapTracer"),this.name=e,this._cache=new _e}select(e){let t=this._cache.swap(e.root,null);return null==t&&(console.log(`[${this.name}] (cache miss)`),t=R()),t.observeChangesFor(e,{insert:(e,t)=>console.log(`[${this.name}] insert`,e,t),delete:(e,t)=>console.log(`[${this.name}] delete`,e,t),set:(e,t,r)=>console.log(`[${this.name}] set`,e,t,r)}),this._cache.swap(e.root,e),e}}class Ie{constructor(e){null==e&&(e=o),this.comparator=e,this._cache=new _e}select(e){if(0===e.size)return e;let{oldSrcList:t,oldOrderedList:r}=this._cache.swap(e.root,null,()=>({oldSrcList:null,oldOrderedList:null}));if(null==t){let t=e.toArray();t.sort(this.comparator),r=Z(t,!0)}else t.observeChangesFor(e,{insert:(e,t)=>{const s=r.binaryFindInsertionIndex(t,this.comparator);r=r.insert(s,t)},delete:(e,t)=>{const s=r.binaryFindIndex(t,this.comparator);r=r.delete(s)}});return this._cache.swap(e.root,{oldSrcList:e,oldOrderedList:r}),r}}class We{constructor(e){this.predicate=e,this._cache=new _e}select(e){let{oldSrcMap:t,oldFilteredMap:r}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldFilteredMap:R()}));return t.observeChangesFor(e,{insert:(e,t)=>{this.predicate(t)&&(r=r.set(e,t))},delete:(e,t)=>{this.predicate(t)&&(r=r.delete(e))},set:(e,t,s)=>{const i=this.predicate(t),n=this.predicate(s);i&&!n?r=r.delete(e):n&&(r=r.set(e,s))}}),this._cache.swap(e.root,{oldSrcMap:e,oldFilteredMap:r}),r}}class Ce{constructor(e){this.mapper=e,this._cache=new _e}select(e){if(0===e.size)return Z();let{prevList:t,flatMappedList:r,offsets:s,mappedValues:i}=this._cache.swap(e.root,null,()=>({prevList:Z(),flatMappedList:Z(),offsets:[],mappedValues:[]}));const n=(e,t)=>{let n=0;n=e>=s.length?r.size:s[e];let l=0;for(let e of t)r=r.insert(n+l,e),++l;for(let t=e;t<s.length;++t)s[t]+=l;s.splice(e,0,n),i.splice(e,0,t)},l=e=>{let t=s[e],n=0,l=(n=e+1>=s.length?r.size:s[e+1])-t;for(let e=n-1;e>=t;--e)r=r.delete(e);for(let t=e;t<s.length;++t)s[t]-=l;s.splice(e,1),i.splice(e,1)};return t.observeChangesFor(e,{insert:(e,t)=>n(e,this.mapper(t)),delete:(e,t)=>l(e),set:(e,t,a)=>{const o=i[e],h=this.mapper(a);if(!ee(o)||!ee(h))return l(e),void n(e,h);const c=s[e];o.observeChangesFor(h,{insert:(e,t)=>{r=r.insert(c+e,t)},delete:(e,t)=>{r=r.delete(c+e)},set:(e,t,s)=>{r=r.set(c+e,s)}});const u=a.size-t.size;for(let t=e+1;t<s.length;++t)s[t]+=u;i[e]=h}}),this._cache.swap(e.root,{prevList:e,flatMappedList:r,offsets:s,mappedValues:i}),r}}class Ae{constructor(e,t,r){this.selectors=e,this.accepts=t,this.emits=r}func(){const e=this,t=function(t){if(!function(e,t){if("list"===t)return e instanceof X||e===Y;if("map"===t)return e instanceof U||e===G;throw new Error("unknown typeName: "+t)}(t,e.accepts))throw new Error("incorrect argument type for the selector - expected "+e.accepts);let r=arguments[0];for(let t of e.selectors)r=t.needsOriginalInput?t.select(r,arguments[0]):t.select(r);return r};return"list"===this.emits&&(t.filter=(e=>new Ae([...this.selectors,new we(e)],this.accepts,"list").func()),t.map=(e=>new Ae([...this.selectors,new ye(e)],this.accepts,"list").func()),t.flatMap=(e=>new Ae([...this.selectors,new Ce(e)],this.accepts,"list").func()),t.flatten=(()=>new Ae([...this.selectors,new Ce(e=>e)],this.accepts,"list").func()),t.orderBy=(e=>new Ae([...this.selectors,new ke(e)],this.accepts,"list").func()),t.sort=(e=>new Ae([...this.selectors,new Ie(e)],this.accepts,"list").func()),t.groupBy=((e,t)=>new Ae([...this.selectors,new me(e,t)],this.accepts,"map").func()),t.toMap=(()=>new Ae([...this.selectors,new be],this.accepts,"map").func()),t.trace=(e=>new Ae([...this.selectors,new Fe(e)],this.accepts,this.emits).func())),"map"===this.emits&&(t.ungroup=(e=>new Ae([...this.selectors,new ze(e)],this.accepts,"list").func()),t.map=(e=>new Ae([...this.selectors,new ve(e)],this.accepts,"map").func()),t.keys=(()=>new Ae([...this.selectors,new Me],this.accepts,"list").func()),t.values=(()=>new Ae([...this.selectors,new Se],this.accepts,"list").func()),t.join=((e,t)=>{if(null==e.__pipeline)throw new Error(".join() expects a secondary selector created by select()");if("map"!==e.__pipeline.emits)throw new Error("the secondary selector must emit a map");if(e.__pipeline.accepts!==this.accepts)throw new Error("the secondary selector must accept the same input");return new Ae([...this.selectors,new Be(e,t)],this.accepts,"map").func()}),t.trace=(e=>new Ae([...this.selectors,new xe(e)],this.accepts,this.emits).func()),t.filterByValue=(e=>new Ae([...this.selectors,new We(e)],this.accepts,"map").func())),t.__pipeline=this,t}}function Pe(){return new Ae([],"list","list").func()}function Ee(){return new Ae([],"map","map").func()}function Oe(e){if(null==e.__pipeline)throw new Error("select.from() expects another selector created by select as its argument");return e}r.d(t,"ImmyList",function(){return Z}),r.d(t,"List",function(){return Z}),r.d(t,"listSelect",function(){return s}),r.d(t,"listCombine",function(){return i}),r.d(t,"select",function(){return n}),r.d(t,"ImmyMap",function(){return R}),r.d(t,"Map",function(){return R}),r.d(t,"ImmySet",function(){return O}),r.d(t,"Set",function(){return O});t.default={ImmyList:Z,List:Z,listSelect:s,listCombine:i,select:n,ImmyMap:R,Map:R,ImmySet:O,Set:O}}]);
module.exports=function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:s})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var s={};r.d(s,"map",function(){return ce}),r.d(s,"filter",function(){return ue}),r.d(s,"reduce",function(){return pe}),r.d(s,"asType",function(){return fe});var i={};r.d(i,"withList",function(){return ge});var n={};function l(e){return"string"==typeof e?'"'+e+'"':JSON.stringify(e)}function a(e){const{name:t,apply:r,applyWrapper:s,invertName:i,invert:n,invertWrapper:l}=e;return r._name=t,r.inverse=n,n._name=i,n.inverse=r,r.callWrapper=s,n.callWrapper=l,r}function o(e,t){if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||t.length!==e.length)throw new Error("when using array keys, both args must be arrays and both must have the same length");for(let r=0;r<e.length;++r){if(e[r]<t[r])return-1;if(t[r]<e[r])return 1;if(e[r]!==t[r])return-1}return 0}return e<t?-1:t<e?1:e!==t?-1:0}function h(e){return!1!==e}r.d(n,"fromList",function(){return Pe}),r.d(n,"fromMap",function(){return Ee}),r.d(n,"from",function(){return Oe});class c{constructor(e){if(this.observer=e,this.active=!0,!e.insert)throw new Error("observer must implement an insert method");if(!e.delete)throw new Error("observer must implement a delete method")}push(e,t){this.active&&(this.observer.push?this.active=h(this.observer.push(t,e)):this.active=h(this.observer.insert(e,t)))}pop(e,t){this.active&&(this.observer.pop?this.active=h(this.observer.pop(t,e)):this.active=h(this.observer.delete(e,t)))}unshift(e){this.active&&(this.observer.unshift?this.active=h(this.observer.unshift(e,index)):this.active=h(this.observer.insert(0,e)))}shift(e){this.active&&(this.observer.shift?this.active=h(this.observer.shift(e,index)):this.active=h(this.observer.delete(0,e)))}insert(e,t){this.active&&(this.active=h(this.observer.insert(e,t)))}delete(e,t){this.active&&(this.active=h(this.observer.delete(e,t)))}clear(e){if(this.active)if(this.observer.clear)this.active=h(this.observer.clear());else for(let t=e.length-1;t>=0&&this.active;--t)this.pop(t,e[t])}pushMany(e,t){if(this.active)if(this.observer.pushMany)this.active=h(this.observer.pushMany(t));else for(let r=0;r<t.length&&this.active;++r)this.push(e+r,t[r])}set(e,t,r){this.active&&(this.observer.set?this.active=h(this.observer.set(e,t,r)):(this.active=h(this.observer.delete(e,t)),this.active&&(this.active=h(this.observer.insert(e,r)))))}}class u{constructor(){this._buffer=new Array(8),this.size=0}clear(){for(let e=0;e<this.size;++e)this._buffer[e]=void 0;this.size=0}push(e){this.size===this._buffer.length&&(this._buffer.length*=2),this._buffer[this.size]=e,++this.size}pop(){if(0===this.size)return;--this.size;const e=this._buffer[this.size];return this._buffer[this.size]=void 0,e}}class p{constructor(e,t){this._factory=e,this._stack=new u}clear(){this._stack.clear()}remove(){return 0===this._stack.size?this._factory():this._stack.pop()}add(e){this._stack.push(e)}}var f=a({name:"setOne (apply)",apply:(e,t,r,s)=>e[t]=s,applyWrapper:(e,t,r,s)=>s.set(e,t,r),invertName:"setOne (invert)",invert:(e,t,r,s)=>e[t]=r,invertWrapper:(e,t,r,s)=>s.set(e,r,t)});var d=a({name:"setMany (apply)",apply:(e,t,r,s)=>{for(let r=0;r<s.length;++r)e[t+r]=s[r]},applyWrapper:(e,t,r,s)=>{for(let i=0;i<r.length;++i)s.set(e+i,t[i],r[i])},invertName:"setMany (invert)",invert:(e,t,r,s)=>{for(let s=0;s<r.length;++s)e[t+s]=r[s]},invertWrapper:(e,t,r,s)=>{for(let i=0;i<t.length;++i)s.set(e+i,r[i],t[i])}});var g=a({name:"delete",apply:(e,t,r,s)=>e.splice(t,1),applyWrapper:(e,t,r,s)=>s.delete(e,t),invertName:"insert",invert:(e,t,r,s)=>e.splice(t,0,r),invertWrapper:(e,t,r,s)=>s.insert(e,t)});var _=a({name:"insert",apply:(e,t,r,s)=>e.splice(t,0,r),applyWrapper:(e,t,r,s)=>s.insert(e,t),invertName:"delete",invert:(e,t,r,s)=>e.splice(t,1),invertWrapper:(e,t,r,s)=>s.delete(e,t)});var w=a({name:"pushOne",apply:(e,t,r,s)=>e.push(r),applyWrapper:(e,t,r,s)=>s.push(e,t),invertName:"popOne",invert:(e,t,r,s)=>e.pop(),invertWrapper:(e,t,r,s)=>s.pop(e,t)});var y=a({name:"pushMany",apply:(e,t,r,s)=>e.push.apply(e,r),applyWrapper:(e,t,r,s)=>s.pushMany(e,t),invertName:"popMany",invert:(e,t,r,s)=>e.length-=r.length,invertWrapper:(e,t,r,s)=>{for(let r=t.length-1;r>=0;--r)s.pop(e+r,t[r])}});var v=a({name:"popOne",apply:(e,t,r,s)=>e.pop(),applyWrapper:(e,t,r,s)=>s.pop(e,t),invertName:"pushOne",invert:(e,t,r,s)=>e.push(r),invertWrapper:(e,t,r,s)=>s.push(e,t)});var m=a({name:"popMany",apply:(e,t,r,s)=>e.length-=r.length,applyWrapper:(e,t,r,s)=>{for(let r=t.length-1;r>=0;--r)s.pop(e+r,t[r])},invertName:"pushMany",invert:(e,t,r,s)=>e.push.apply(e,r),invertWrapper:(e,t,r,s)=>s.pushMany(e,t)});var b=a({name:"shiftOne",apply:(e,t,r,s)=>e.unshift(r),applyWrapper:(e,t,r,s)=>s.unshift(t),invertName:"unshiftOne",invert:(e,t,r,s)=>e.shift(),invertWrapper:(e,t,r,s)=>s.shift(t)});var k=a({name:"unshiftMany",apply:(e,t,r,s)=>e.unshift.apply(e,r),applyWrapper:(e,t,r,s)=>{for(let e=t.length-1;e>=0;--e)s.unshift(t[e])},invertName:"shiftMany",invert:(e,t,r,s)=>e.splice(0,r.length),invertWrapper:(e,t,r,s)=>{for(let e=0;e<t.length;++e)s.shift(t[e])}});var z=a({name:"shiftOne",apply:(e,t,r,s)=>e.shift(),applyWrapper:(e,t,r,s)=>s.shift(t),invertName:"unshiftOne",invert:(e,t,r,s)=>e.unshift(r),invertWrapper:(e,t,r,s)=>s.unshift(t)});var M=a({name:"shiftMany",apply:(e,t,r,s)=>e.splice(0,r.length),applyWrapper:(e,t,r,s)=>{for(let e=0;e<t.length;++e)s.shift(t[e])},invertName:"unshiftMany",invert:(e,t,r,s)=>e.unshift.apply(e,r),invertWrapper:(e,t,r,s)=>{for(let e=t.length-1;e>=0;--e)s.unshift(t[e])}});var S=a({name:"grow",apply:(e,t,r,s)=>e.length=r,applyWrapper:(e,t,r,s)=>{for(let r=e;r<t;++r)s.push(r,void 0)},invertName:"shrink",invert:(e,t,r,s)=>e.length=t,invertWrapper:(e,t,r,s)=>{for(let r=t-1;r>=e;--r)s.pop(r,void 0)}});var L=a({name:"splice (apply)",apply:(e,t,r,s)=>e.splice.apply(e,r),applyWrapper:(e,t,r,s)=>{for(let t=2;t<r.length;++t)s.delete(e,r[t]);for(let r=2;r<t.length;++r)s.insert(e+(r-2),t[r])},invertName:"splice (invert)",invert:(e,t,r,s)=>e.splice.apply(e,s),invertWrapper:(e,t,r,s)=>{for(let r=2;r<t.length;++r)s.delete(e,t[r]);for(let t=2;t<r.length;++t)s.insert(e+(t-2),r[t])}});var B=a({name:"delete many sparse",apply:(e,t,r,s)=>{if(0===r.length)return;let i=r[0],n=i,l=0;for(;n<e.length;){for(;n===r[l]&&n<e.length;)++n,++l;n<e.length&&(e[i++]=e[n++])}e.length-=r.length},applyWrapper:(e,t,r,s)=>{for(let e=t.length-1;e>=0;--e)s.delete(t[e],r[e])},invertName:"insert many sparse",invert:(e,t,r,s)=>{if(0===r.length)return;e.length+=r.length;let i=e.length-1,n=i-r.length,l=r.length-1;for(;i>=r[0];){for(;i===r[l]&&i>=0;)e[i]=s[l],--l,--i;i>=0&&(e[i--]=e[n--])}},invertWrapper:(e,t,r,s)=>{for(let e=0;e<t.length;++e)s.insert(t[e],r[e])}});function F(e){return!1!==e}class x{constructor(e){if(this.observer=e,this.active=!0,!e.insert)throw new Error("observer must implement an insert method");if(!e.delete)throw new Error("observer must implement a delete method")}insert(e){this.active&&(this.active=F(this.observer.insert(e)))}delete(e){this.active&&(this.active=F(this.observer.delete(e)))}clear(e){if(this.active)if(this.observer.clear)this.active=F(this.observer.clear());else for(let t of e){if(!this.active)break;this.delete(t)}}insertMany(e){if(this.active)if(this.observer.insertMany)this.active=F(this.observer.insertMany(e));else for(let t of e){if(!this.active)break;this.insert(t)}}}var I=a({name:"delete",apply:(e,t)=>e.delete(t),applyWrapper:(e,t)=>t.delete(e),invertName:"insert",invert:(e,t)=>e.add(t),invertWrapper:(e,t)=>t.insert(e)});var W=a({name:"insert",apply:(e,t)=>e.add(t),applyWrapper:(e,t)=>t.insert(e),invertName:"delete",invert:(e,t)=>e.delete(t),invertWrapper:(e,t)=>t.delete(e)});let C=new p(()=>new u);class A{constructor(){this.lockCount=0}lock(){this.lockCount++}unlock(){if(0===this.lockCount)throw new Error("attempting to unlock an already unlocked root");this.lockCount--}isLocked(){return this.lockCount>0}}class P{constructor(e,t){this._backing=e,this.size=e.size,this.root=t||new A,this._i=null,this._patchFunc=null,this._patchTarget=null}_ensureUnlocked(){if(this.root.isLocked())throw new Error("unable to create new versions of a locked set")}count(){return this.size}first(){const e=this._getBacking();for(let t of e)return t}clear(){return E}add(e){return this.has(e)?this:this._withPatch(W,e)}delete(e){return this.has(e)?1===this.size?E:this._withPatch(I,e):this}has(e){return this._getBacking().has(e)}toArray(){const e=this._getBacking();return Array.from(e)}toList(){return Z(this.toArray(),!0)}toSet(){return this}toJS(){return new Set(this._getBacking())}*[Symbol.iterator](){const e=this._getBacking();this.root.lock();try{yield*e}finally{this.root.unlock()}}forEach(e,t){let r=0;for(let s of this){if(!1===e.call(t,s,s,this))return r;++r}return this.size}observeChangesFor(e,t){if(this===e)return!0;const r=new x(t);if(e===E)return r.clear(this._getBacking()),r.active;if(this.root===e.root){e._getBacking();let t=this;for(;t!==e&&r.active;)t._patchFunc.inverse.callWrapper(t._i,r),e._getBacking(),t=t._patchTarget}else r.clear(this._getBacking()),r.active&&r.insertMany(e._getBacking());return r.active}toString(){let e="ImmySet { ",t=!0;for(let r of this._getBacking())t||(e+=", "),e+=`${l(r)}`,t=!1;return e+=" }"}inspect(){return this.toString()}_withPatch(e,t){this._ensureUnlocked(),e(this._getBacking(),t),this._i=t,this._patchFunc=e.inverse;const r=new P(this._backing,this.root);return this._patchTarget=r,this._backing=null,r}_getBacking(){if(null!=this._backing)return this._backing;if(this.root.isLocked())throw new Error("unable to get backing - the set root is locked");let e=C.remove(),t=this;for(;null!=t;)e.push(t),t=t._patchTarget;let r=e.pop();for(;e.size>0;){let t=e.pop();t._patchFunc(r._backing,t._i),t._backing=r._backing,r._patchTarget=t,r._patchFunc=t._patchFunc.inverse,r._i=t._i,r._backing=null,t._patchTarget=null,t._patchFunc=null,t._i=null,r=t}return C.add(e),this._backing}}let E=null;function O(e,t){if(0===arguments.length||null==e)return E;if(e instanceof Set)return 0===e.size?E:new P(!0===t?e:new Set(e));if(e instanceof P)return new P(new Set(e._getBacking()));if(Array.isArray(e))return 0===e.length?E:new P(new Set(e));if(null!=e){let t=new Set(e);return 0===t.size?E:new P(t)}}function T(e){return!1!==e}E=new class{constructor(){this.size=0,this.root={}}count(){return 0}first(){}add(e){return new P(new Set).add(e)}clear(){return this}delete(e){return this}has(e){return!1}toArray(){return[]}toSet(){return this}toList(){return Y}toJS(){return new Set}forEach(e){return 0}*[Symbol.iterator](){}observeChangesFor(e,t){e!==this&&new x(t).insertMany(e._getBacking())}toString(){return"ImmySet {}"}inspect(){return this.toString()}};class N{constructor(e){if(this.observer=e,this.active=!0,!e.insert)throw new Error("observer must implement an insert method");if(!e.delete)throw new Error("observer must implement a delete method")}insert(e,t){this.active&&(this.active=T(this.observer.insert(e,t)))}delete(e,t){this.active&&(this.active=T(this.observer.delete(e,t)))}clear(e){if(this.active)if(this.observer.clear)this.active=T(this.observer.clear());else for(let[t,r]of e){if(!this.active)break;this.delete(t,r)}}insertMany(e){if(this.active)if(this.observer.insertMany)this.active=T(this.observer.insertMany(e));else for(let[t,r]of e){if(!this.active)break;this.insert(t,r)}}set(e,t,r){this.active&&(this.observer.set?this.active=T(this.observer.set(e,t,r)):(this.active=T(this.observer.delete(e,t)),this.active&&(this.active=T(this.observer.insert(e,r)))))}}var K=a({name:"delete",apply:(e,t,r,s)=>e.delete(t),applyWrapper:(e,t,r,s)=>s.delete(e,t),invertName:"insert",invert:(e,t,r,s)=>e.set(t,r),invertWrapper:(e,t,r,s)=>s.insert(e,t)});var $=a({name:"insert",apply:(e,t,r,s)=>e.set(t,r),applyWrapper:(e,t,r,s)=>s.insert(e,t),invertName:"delete",invert:(e,t,r,s)=>e.delete(t),invertWrapper:(e,t,r,s)=>s.delete(e)});var V=a({name:"update",apply:(e,t,r,s)=>e.set(t,s),applyWrapper:(e,t,r,s)=>s.set(e,t,r),invertName:"update (inverse)",invert:(e,t,r,s)=>e.set(t,r),invertWrapper:(e,t,r,s)=>s.set(e,r,t)});let J=new p(()=>new u);class j{constructor(){this.lockCount=0}lock(){this.lockCount++}unlock(){if(0===this.lockCount)throw new Error("attempting to unlock an already unlocked root");this.lockCount--}isLocked(){return this.lockCount>0}}class U{constructor(e,t){this._backing=e,this.size=e.size,this.root=t||new j,this._i=null,this._x=null,this._y=null,this._patchFunc=null,this._patchTarget=null}_ensureUnlocked(){if(this.root.isLocked())throw new Error("unable to create new versions of a locked map")}clear(){return G}set(e,t){const r=this.get(e);return void 0===r?void 0===t?this:this.has(e)?this._withPatch(V,e,r,t):this._withPatch($,e,t,null):r===t?this:this._withPatch(V,e,r,t)}get(e){return this._getBacking().get(e)}has(e){return this._getBacking().has(e)}delete(e){const t=this.get(e);return void 0!==t||this.has(e)?1===this.size?G:this._withPatch(K,e,t,null):this}update(e,t){return this.set(e,t(this.get(e)))}toArray(){throw new Error("not done yet")}map(e,t){let r=new Map;for(let[s,i]of this)r.set(s,e.call(t,i,s,this));return new U(r)}forEach(e,t){let r=0;for(let[s,i]of this){if(!1===e.call(t,i,s,this))return r;++r}return this.size}filter(e,t){let r=new Map;for(let[s,i]of this)e.call(t,i,s,this)&&r.set(s,i);return new U(r)}toList(){let e=[];for(let[t,r]of this)e.push(r);return Z(e,!0)}toSet(){let e=[];for(let[t,r]of this)e.push(r);return O(e)}toMap(){return this}toJS(){return new Map(this._getBacking())}*[Symbol.iterator](){const e=this._getBacking();this.root.lock();try{yield*e}finally{this.root.unlock()}}observeChangesFor(e,t){if(this===e)return!0;const r=new N(t);if(e===G)return r.clear(this._getBacking()),r.active;if(this.root===e.root){e._getBacking();let t=this;for(;t!==e&&r.active;)t._patchFunc.inverse.callWrapper(t._i,t._x,t._y,r),e._getBacking(),t=t._patchTarget}else r.clear(this._getBacking()),r.active&&r.insertMany(e._getBacking());return r.active}toString(){let e="ImmyMap { ",t=!0;for(let[r,s]of this._getBacking())t||(e+=", "),e+=`${l(r)}: ${l(s)}`,t=!1;return e+=" }"}inspect(){return this.toString()}_withPatch(e,t,r,s){this._ensureUnlocked(),e(this._getBacking(),t,r,s),this._i=t,this._x=r,this._y=s,this._patchFunc=e.inverse;const i=new U(this._backing,this.root);return this._patchTarget=i,this._backing=null,i}_getBacking(){if(null!=this._backing)return this._backing;if(this.root.isLocked())throw new Error("unable to get backing - the map root is locked");let e=J.remove(),t=this;for(;null!=t;)e.push(t),t=t._patchTarget;let r=e.pop();for(;e.size>0;){let t=e.pop();t._patchFunc(r._backing,t._i,t._x,t._y),t._backing=r._backing,r._patchTarget=t,r._patchFunc=t._patchFunc.inverse,r._i=t._i,r._x=t._x,r._y=t._y,r._backing=null,t._patchTarget=null,t._patchFunc=null,t._i=null,t._x=null,t._y=null,r=t}return J.add(e),this._backing}}let G=null;function R(e,t){if(0===arguments.length||null==e)return G;if(e instanceof Map)return 0===e.size?G:new U(!0===t?e:new Map(e));if(e instanceof U)return new U(new Map(e._getBacking()));if(null!=e){let t=new Map(e);return 0===t.size?G:new U(t)}}G=new class{constructor(){this.size=0,this.root={}}clear(){return this}set(e,t){return new U(new Map).set(e,t)}get(e){}has(e){return!1}delete(e){return this}map(e,t){return this}forEach(e,t){return 0}filter(e,t){return this}toList(){return Y}toSet(){return E}toArray(){return[]}toMap(){return this}toJS(){return new Map}*[Symbol.iterator](){}observeChangesFor(e,t){e!==this&&new N(t).insertMany(e._getBacking())}toString(){return"ImmyMap {}"}inspect(){return this.toString()}};const q=e=>e;let D=new p(()=>new u),H=new p(()=>new class{constructor(){this._buffer=new Array(8),this._begin=0,this._end=0,this.size=0}clear(){for(let e=this._begin;e<this._end;++e)this._buffer[e]=void 0;this._begin=0,this._end=0,this.size=0}push(e){++this.size,this._buffer[this._end++]=e}shift(){if(0===this.size)return;const e=this._buffer[this._begin];return this._buffer[this._begin++]=void 0,--this.size,0===this.size&&(this._begin=0,this._end=0),e}}),Q=new p(()=>({index:-1,value:null}));class X{constructor(e,t){this._backing=e,this.size=e.length,this.root=t||{},this._i=-1,this._x=null,this._y=null,this._patchFunc=null,this._patchTarget=null}count(){return this.size}first(){return this.get(0)}isEmpty(){return 0===this.size}last(){return this.get(this.size-1)}set(e,t){if(e<0&&(e=this.size+e),e<0){let r=new Array(Math.abs(e));return r[0]=t,this._withPatch(k,0,r,null)}return e===this.size?this.push(t):e<this.size?this.get(e)===t?this:this._withPatch(f,e,this._getBacking()[e],t):this.setSize(e+1).set(e,t)}get(e){if(e<0&&(e=this.size+e),!(e<0||e>=this.size))return this._getBacking()[e]}delete(e){return e<0&&(e=this.size+e),e<=0?this.shift():e>=this.size?this.pop():this._withPatch(g,e,this._getBacking()[e],null)}insert(e,t){return e<0&&(e=this.size+e),e<=0?this.unshift(t):e>=this.size?this.push(t):this._withPatch(_,e,t,null)}insertSorted(e,t){void 0===t&&(t=q);const r=t(e),s=this.binaryFindInsertionIndexByKey(r,t);return this.insert(s,e)}updateSorted(e,t){void 0===t&&(t=q);const r=this.indexOfSorted(e,t);if(r<0)throw new Error("unable to update the given value - it is not in the list");return this.set(r,e)}deleteSorted(e,t){void 0===t&&(t=q);const r=this.indexOfSorted(e,t);if(r<0)throw new Error("unable to delete the given value - it is not in the list");return this.delete(r)}indexOfSorted(e,t){void 0===t&&(t=q);const r=t(e);return this.binaryFindIndexByKey(r,t)}indexOf(e){const t=this._getBacking();for(let r=0;r<t.length;++r)if(t[r]===e)return r;return-1}binaryFindByKey(e,t,r){const s=this.binaryFindIndexByKey(e,t);return s<0?r:this.get(s)}binaryFindIndex(e,t){let r,s,i=0,n=this.size-1;if(0===this.size)return-1;for(;i<=n;){r=(i+n)/2|0;let l=t(e,s=this.get(r));if(l>0)i=r+1;else{if(!(l<0)){for(;r<this.size-1&&0===t(e,this.get(r+1));)++r;return r}n=r-1}}return n>=0&&n<this.size&&0===t(e,this.get(n))?n:i>=0&&i<this.size&&0===t(e,this.get(i))?i:-1}binaryFindIndexByKey(e,t){return void 0===t&&(t=q),this.binaryFindIndex(e,(e,r)=>o(e,t(r)))}binaryFindInsertionIndex(e,t){if(0===this.size)return 0;let r,s,i=0,n=this.size-1;for(;i<=n;){r=(i+n)/2|0;let l=t(e,s=this.get(r));if(l>0)i=r+1;else{if(!(l<0)){for(;r<this.size-1&&0==t(e,this.get(r+1));)++r;return r+1}n=r-1}}return t(e,this.get(r))<0?r:r+1}binaryFindInsertionIndexByKey(e,t){return void 0===t&&(t=q),this.binaryFindInsertionIndex(e,(e,r)=>o(e,t(r)))}clear(){return Y}push(){if(0===arguments.length)return this;if(1===arguments.length)return this._withPatch(w,this.size,arguments[0],null);{const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return this._withPatch(y,this.size,e,null)}}pop(){if(this.size<=1)return Y;{const e=this.size-1;return this._withPatch(v,e,this._getBacking()[e],null)}}popMany(e){if(0===e)return this;if(this.size-e<=0)return Y;if(1===e)return this.pop();{const t=this._getBacking(),r=new Array(e),s=t.length-e;for(let i=0;i<e;++i)r[i]=t[s+i];return this._withPatch(m,s,r,null)}}unshift(){if(0===arguments.length)return this;if(1===arguments.length)return this._withPatch(b,0,arguments[0],null);{const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return this._withPatch(k,0,e,null)}}shift(){return this.size<=1?Y:this._withPatch(z,0,this._getBacking()[0],null)}shiftMany(e){if(0===e)return this;if(this.size-e<=0)return Y;if(1===e)return this.shift();{const t=this._getBacking(),r=new Array(e);for(let s=0;s<e;++s)r[s]=t[s];return this._withPatch(M,0,r,null)}}setSize(e){return 0===e?Y:e===this.size?this:e<this.size?this.splice(this.size-e+1):this._withPatch(S,this.size,e,null)}splice(){if(0===arguments.length)return this;let e=arguments[0];e<0?(e=Math.max(this.size+e,0),arguments[0]=e):e>=this.size&&(e=this.size,arguments[0]=e);let t=this.size-e;if(arguments.length>=2&&(t=Math.min(arguments[1],this.size-e),arguments[1]=t),arguments.length<=2&&0===t)return this;if(arguments.length<=2&&t>0)return 0===e&&t===this.size?Y:e+t===this.size?this.popMany(t):0===e?this.shiftMany(t):this._spliceImpl.apply(this,arguments);if(arguments.length>2&&0===t){if(3===arguments.length)return e>=this.size?this.push(arguments[2]):e<=0?this.unshift(arguments[2]):this.insert(e,arguments[2]);if(e<=0||e>=this.size){const t=new Array(arguments.length-2);for(let e=2;e<arguments.length;++e)t[e-2]=arguments[e];return e<=0?this._withPatch(k,0,t,null):this._withPatch(y,this.size,t,null)}return this._spliceImpl.apply(this,arguments)}if(arguments.length>2&&arguments.length-2===t){if(1===t)return this.set(e,arguments[2]);{const r=this._getBacking(),s=new Array(t);for(let i=0;i<t;++i)s[i]=r[e+i];let i=!0;const n=new Array(arguments.length-2);for(let e=0;e<arguments.length-2;++e)n[e]=arguments[e+2],s[e]!==n[e]&&(i=!1);return i?this:this._withPatch(d,e,s,n)}}return this._spliceImpl.apply(this,arguments)}toList(){return this}toSet(){return O(new Set(this._getBacking()),!0)}toArray(){return this._getBacking().slice()}toJS(){return this.toArray()}indexOf(e){return this._getBacking().indexOf(e)}find(e,t,r){for(let r=0;r<this.size;++r){const s=this.get(r);if(e.call(t,s,r,this))return s}return r}findIndex(e,t){for(let r=0;r<this.size;++r)if(e.call(t,this.get(r),r,this))return r;return-1}*[Symbol.iterator](){for(let e=0;e<this.size;++e)yield this.get(e)}forEach(e,t){for(let r=0;r<this.size;++r)if(!1===e.call(t,this.get(r),r,this))return r;return this.size}map(e,t){let r=new Array(this.size);for(let s=0;s<this.size;++s){const i=this.get(s);r[s]=e.call(t,i,s,this)}return new X(r)}pureMap(e){let t=new Array(this.size);for(let r=0;r<this.size;++r)t[r]=e(this.get(r));return new X(t)}mapInPlace(e,t){let r=H.remove();for(let s=0;s<this.size;++s){const i=this.get(s),n=e.call(t,i,s,this);if(n!==i){let e=Q.remove();e.index=s,e.value=n,r.push(e)}}let s=this;for(;r.size>0;){const e=r.shift();s=s.set(e.index,e.value),e.index=-1,e.value=null,Q.add(e)}return H.add(r),s}filter(e,t){let r=new Array(this.size),s=0;for(let i=0;i<this.size;++i){const n=this.get(i);e.call(t,n,i,this)&&(r[s++]=n)}return r.length=s,0===r.length?Y:r.length===this.size?this:new X(r)}filterInPlace(e,t){let r=null,s=null,i=0;for(;i<this.size;++i){const n=this.get(i);if(!e.call(t,n,i,this)){r=[i],s=[n],++i;break}}for(;i<this.size;++i){const n=this.get(i);e.call(t,n,i,this)||(r.push(i),s.push(n))}return null==r?this:r.length===this.size?Y:this._withPatch(B,-1,r,s)}sort(e){return this.sortBy(q,e)}sortBy(e,t){null==e&&(e=q),null==t&&(t=o);let r=this.toArray();return r.sort((r,s)=>{const i=e(r),n=e(s);return t(i,n)}),new X(r)}flatMap(e,t){let r=[];for(let s=0;s<this.size;++s){const i=this.get(s),n=e.call(t,i,s,this);for(let e of n)r.push(e)}return new X(r)}groupBy(e,t){let r=new Map;for(let s=0;s<this.size;++s){const i=this.get(s),n=e.call(t,i,s,this);r.set(n,(r.get(n)||Z()).push(i))}return R(r,!0)}reduce(e,t,r){let s=t,i=0;for(1===arguments.length&&(s=this.get(0),i=1);i<this.size;++i)s=e.call(r,s,this.get(i),i,this);return s}observeChangesFor(e,t){if(this===e)return!0;const r=new c(t);if(e===Y)return r.clear(this._getBacking()),r.active;if(this.root===e.root){e._getBacking();let t=this;for(;t!==e&&r.active;)t._patchFunc.inverse.callWrapper(t._i,t._x,t._y,r),e._getBacking(),t=t._patchTarget}else r.clear(this._getBacking()),r.active&&r.pushMany(0,e._getBacking());return r.active}toString(){if(this.size<13)return`ImmyList(${this.size}) [ `+this._getBacking().map(e=>l(e)).join(", ")+" ]";{let e=`ImmyList(${this.size}) [ `;for(let t=0;t<10;++t)t>0&&(e+=", "),e+=l(this.get(t));return e+=`, ... , ${l(this.get(-2))}, ${l(this.get(-1))} ]`}}inspect(){return this.toString()}_withPatch(e,t,r,s){return e(this._getBacking(),t,r,s),this._afterPatch(e,t,r,s)}_afterPatch(e,t,r,s){this._i=t,this._x=r,this._y=s,this._patchFunc=e.inverse;const i=new X(this._backing,this.root);return this._patchTarget=i,this._backing=null,i}_getBacking(){if(null!=this._backing)return this._backing;let e=D.remove(),t=this;for(;null!=t;)e.push(t),t=t._patchTarget;let r=e.pop();for(;e.size>0;){let t=e.pop();t._patchFunc(r._backing,t._i,t._x,t._y),t._backing=r._backing,r._patchTarget=t,r._patchFunc=t._patchFunc.inverse,r._i=t._i,r._x=t._x,r._y=t._y,r._backing=null,t._patchTarget=null,t._patchFunc=null,t._i=-1,t._x=null,t._y=null,r=t}return D.add(e),this._backing}_spliceImpl(){const e=this._getBacking();let t=e.splice.apply(e,arguments);t.unshift(arguments[0],arguments.length-2);let r=new Array(arguments.length);for(let e=0;e<arguments.length;++e)r[e]=arguments[e];return this._afterPatch(L,arguments[0],r,t)}}let Y=null;function Z(e,t){if(0===arguments.length)return Y;if(Array.isArray(e))return 0===e.length?Y:new X(!0===t?e:e.slice());if(e instanceof X)return new X(e._getBacking().slice());{let t=[];for(let r of e)t.push(r);return 0===t.length?Y:new X(t)}}function ee(e){return null!=e&&(e===Y||e instanceof X)}Y=new class{constructor(){this.size=0,this.root={}}count(){return 0}first(){}last(){}set(e,t){return new X([]).set(e,t)}get(e){}delete(e){return this}insert(e,t){return new X([]).insert(e,t)}insertSorted(e,t){return new X([]).insertSorted(e,t)}indexOfSorted(e,t){return-1}binaryFindByKey(e,t,r){return r}binaryFindIndexByKey(e,t){return-1}binaryFindInsertionIndex(e,t){return 0}binaryFindInsertionIndexByKey(e,t){return 0}clear(){return this}push(){const e=new X([]);return e.push.apply(e,arguments)}pop(){return this}popMany(){return this}unshift(){const e=new X([]);return e.unshift.apply(e,arguments)}shift(){return this}shiftMany(){return this}setSize(e){return 0===e?this:new X(new Array(e))}splice(){const e=new X([]);return e.splice.apply(e,arguments)}isEmpty(){return!0}toList(){return this}toArray(){return[]}toJS(){return this.toArray()}toSet(){return E}indexOf(){return-1}find(e,t,r){return r}findIndex(e,t){return-1}*[Symbol.iterator](){}forEach(e){return 0}map(e){return this}pureMap(e){return this}mapInPlace(e){return this}filter(e){return this}filterInPlace(e){return this}sort(e){return this}sortBy(e,t){return this}flatMap(e,t){return this}groupBy(e,t){return G}reduce(e,t){return t}observeChangesFor(e,t){e!==this&&new c(t).pushMany(0,e._getBacking().slice())}toString(){return"ImmyList(0) []"}inspect(){return this.toString()}};class te{constructor(e=8){this._maxSize=e,this._weakMaps=[]}clear(){this._weakMaps=[]}swap(e,t){let r=null,s=void 0;for(let t=0;t<this._weakMaps.length;++t)if(void 0!==(s=this._weakMaps[t].get(e))){r=this._weakMaps[t],this._weakMaps.splice(t,1);break}return null==r&&(r=new WeakMap),r.set(e,t),this._weakMaps.unshift(r),this._weakMaps.length>=this._maxSize&&(this._weakMaps.length=this._maxSize),s}}const re=Z();class se{constructor(e){this.mapper=e,this._cache=new te(2)}select(e){if(e===re)return re;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.mappedList;return t=null,r.observeChangesFor(e,{insert:(e,t)=>s=s.insert(e,this.mapper(t)),delete:(e,t)=>s=s.delete(e),set:(e,t)=>s=s.set(e,this.mapper(t))}),t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}let r=new Array(e.size-1);for(let t=0;t<e.size-1;++t)r[t]=this.mapper(e.get(t));r.push(this.mapper(e.get(e.size-1)));let s=Z(r,!0);return t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}}const ie=Z();class ne{constructor(e){this.predicate=e,this._cache=new te(2)}select(e){if(e===ie)return ie;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.filteredList,i=t.translation;return t=null,r.observeChangesFor(e,{insert:(e,t)=>{let r=!1,n=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r||(n=t,r=!0),i[t]+=1);this.predicate(t)&&(i.splice(n,0,e),s=s.insert(n,t))},delete:(e,t)=>{let r=!1,n=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r||(n=t,r=!0),i[t]-=1);this.predicate(t)&&(i.splice(n,1),s=s.delete(n))},push:e=>{this.predicate(e)&&(i.push(s.size),s=s.push(e))}}),t={srcList:e,filteredList:s,translation:i},this._cache.swap(e.root,t),s}let r=[],s=[];for(let t=0;t<e.size;++t){const i=e.get(t);this.predicate(i)&&(r.push(i),s.push(t))}let i=Z(r,!0);return t={srcList:e,filteredList:i,translation:s},this._cache.swap(e.root,t),i}}class le{constructor(e,t){this.reducer=e,this.initialValue=t}select(e){return e.reduce(this.reducer,this.initialValue)}}class ae{constructor(e){this.reducer=e,this._cache=new te(2)}select(e){if(0===e.size)return;if(1===e.size)return e.get(0);let t=this._cache.swap(e.root,null);if(null!=t){console.log("cache hit");let r=t.srcList,s=t.reductionCache;return t=null,r.observeChangesFor(e,{insert:(e,t)=>{console.log("+",e,t)},delete:(e,t)=>{console.log("-",e,t)}}),t={srcList:e,reductionCache:s},this._cache.swap(e.root,t),null}console.log("cache miss");let r=e.get(0),s=Math.floor(e.size/2),i=[];for(let t=1;t<e.size;++t)r=this.reducer(r,e.get(t)),t>=s&&(i.push({index:t,reduction:r}),s=Math.floor(t+(e.size-t)/2));return t={srcList:e,reductionCache:i},this._cache.swap(e.root,t),r}}function oe(e,t){if(e instanceof se&&t instanceof se){const r=e.mapper,s=t.mapper;return new se(e=>s(r(e)))}if(e instanceof ne&&t instanceof ne){const r=e.predicate,s=t.predicate;return new ne(e=>r(e)&&s(e))}return null}function he(e){const t=t=>{for(let r of e)t=r.select(t);return t};return(e=function(e){let t=[];for(let r of e)if(t.length>0){const e=oe(t[t.length-1],r);null==e?t.push(r):(t.pop(),t.push(e))}else t.push(r);return t}(e))[e.length-1]instanceof le||e[e.length-1]instanceof ae?(t.map=(()=>{throw new Error("unable to use list selection operations after a reduction")}),t.filter=(()=>{throw new Error("unable to use list selection operations after a reduction")}),t.reduce=(()=>{throw new Error("unable to use list selection operations after a reduction")}),t.asType=(()=>{throw new Error("unable to use list selection operations after a reduction")})):(t.map=(t=>he([...e,new se(t)])),t.filter=(t=>he([...e,new ne(t)])),t.reduce=function(t,r){return arguments.length>1?he([...e,new le(t,r)]):he([...e,new ae(t)])},t.asType=(()=>t)),t}function ce(e){return he([new se(e)])}function ue(e){return he([new ne(e)])}function pe(e,t){return arguments.length>1?he([new le(e,t)]):he([new ae(e)])}function fe(){return he([])}class de{constructor(e,t){this.getSecondaryKey=e,this.combiner=t,this._cache=new te(2)}combine(e,t){let r=new Set;const s=e=>{const s=t.find(t=>this.getSecondaryKey(t)===e);return r.add(e),s};let i=this._cache.swap(e.root,null);if(null!=i&&i.secondaryRoot===t.root){const n=i.primaryList,l=i.secondaryList;let a=i.combined,o=i.primaryToSecondaries,h=i.secondaryToPrimaries;i=null;const c=e=>{const t=this.combiner(e,s);o.set(e,r);for(let t of r)h.has(t)?h.get(t).add(e):h.set(t,new Set([e]));return r=new Set,t};let u=null;if(l!==t&&(u=new Set,l.observeChangesFor(t,{insert:(e,t)=>{const r=this.getSecondaryKey(t),s=h.get(r);if(s)for(let e of s)o.delete(e),u.add(e);h.delete(r)},delete:(e,t)=>{const r=this.getSecondaryKey(t),s=h.get(r);if(s)for(let e of s)o.delete(e),u.add(e);h.delete(r)}})),n!==e&&n.observeChangesFor(e,{insert:(e,t)=>{a=a.insert(e,c(t))},delete:(e,t)=>{const r=o.get(t);if(r)for(let e of r)h.get(e).delete(t);o.delete(t),a=a.delete(e)},set:(e,t,r)=>{const s=o.get(t);if(s)for(let e of s)h.get(e).delete(t);o.delete(t),a=a.set(e,c(r))}}),null!=u&&u.size>0)for(let t=0;t<e.size;++t){const r=e.get(t);u.has(r)&&(a=a.set(t,c(r)))}return i={secondaryRoot:t.root,primaryList:e,secondaryList:t,combined:a,primaryToSecondaries:o,secondaryToPrimaries:h},this._cache.swap(e.root,i),a}i=null;let n=Z(),l=new Map,a=new Map;for(let t=0;t<e.size;++t){const i=e.get(t),o=this.combiner(i,s);l.set(i,r);for(let e of r)a.has(e)?a.get(e).add(i):a.set(e,new Set([i]));r=new Set,n=n.push(o)}return i={secondaryRoot:t.root,primaryList:e,secondaryList:t,combined:n,primaryToSecondaries:l,secondaryToPrimaries:a},this._cache.swap(e.root,i),n}}function ge(e,t){const r=new de(e,t);return(e,t)=>r.combine(e,t)}class _e{constructor(){this.cache=new WeakMap}swap(e,t,r){const s=this.cache.get(e);return null==t?this.cache.delete(e):this.cache.set(e,t),null==s&&null!=r?r():s}}class we{constructor(e){this.predicate=e,this._cache=new _e}select(e){if(0===e.size)return e;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.filteredList,i=t.translation;return t=null,r.observeChangesFor(e,{insert:(e,t)=>{let r=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r<0&&(r=t),i[t]+=1);r<0&&(r=i.length),this.predicate(t)&&(i.splice(r,0,e),s=s.insert(r,t))},delete:(e,t)=>{let r=-1;for(let t=0;t<i.length;++t)i[t]>=e&&(r<0&&(r=t),i[t]-=1);if(this.predicate(t)){if(r<0)throw new Error("trying to delete from filtered list but could not find item to delete");i.splice(r,1),s=s.delete(r)}},push:(e,t)=>{this.predicate(e)&&(i.push(t),s=s.push(e))}}),t={srcList:e,filteredList:s,translation:i},this._cache.swap(e.root,t),s}let r=[],s=[];for(let t=0;t<e.size;++t){const i=e.get(t);this.predicate(i)&&(r.push(i),s.push(t))}let i=Z(r,!0);return t={srcList:e,filteredList:i,translation:s},this._cache.swap(e.root,t),i}}class ye{constructor(e){this.mapper=e,this._cache=new _e(2)}select(e){if(0===e.size)return e;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcList,s=t.mappedList;return t=null,r.observeChangesFor(e,{insert:(e,t)=>s=s.insert(e,this.mapper(t)),delete:(e,t)=>s=s.delete(e),set:(e,t,r)=>s=s.set(e,this.mapper(r))}),t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}let r=new Array(e.size-1);for(let t=0;t<e.size-1;++t)r[t]=this.mapper(e.get(t));r.push(this.mapper(e.get(e.size-1)));let s=Z(r,!0);return t={srcList:e,mappedList:s},this._cache.swap(e.root,t),s}}class ve{constructor(e){this.mapper=e,this._cache=new _e(2)}select(e){if(0===e.size)return e;let t=this._cache.swap(e.root,null);if(null!=t){let r=t.srcMap,s=t.mappedMap;return t=null,r.observeChangesFor(e,{insert:(e,t)=>s=s.set(e,this.mapper(t)),delete:(e,t)=>s=s.delete(e),set:(e,t,r)=>s=s.set(e,this.mapper(r))}),t={srcMap:e,mappedMap:s},this._cache.swap(e.root,t),s}let r=new Map;for(let[t,s]of e)r.set(t,this.mapper(s));let s=R(r,!0);return t={srcMap:e,mappedMap:s},this._cache.swap(e.root,t),s}}class me{constructor(e,t){null==t&&(t=(e=>e)),this.grouper=e,this.valueSelector=t,this._cache=new _e}select(e){let{oldSrcList:t,oldGrouped:r}=this._cache.swap(e.root,null,()=>({oldSrcList:Z(),oldGrouped:R()}));return t.observeChangesFor(e,{insert:(e,t)=>{const s=this.grouper(t);r=r.has(s)?r.set(s,r.get(s).push(this.valueSelector(t))):r.set(s,Z([this.valueSelector(t)]))},delete:(e,t)=>{const s=this.grouper(t);let i=r.get(s);if(null==i)throw new Error("expected to find a group");let n=i.indexOf(this.valueSelector(t));i=i.delete(n),r=0===i.size?r.delete(s):r.set(s,i)}}),this._cache.swap(e.root,{oldSrcList:e,oldGrouped:r}),r}}class be{constructor(){this._cache=new _e}select(e){if(0===e.size)return R();if(!Array.isArray(e.get(0))||2!=e.get(0).length)throw new Error("toMap() expects a list of [key, value] pairs as its input");let{oldSrcList:t,oldMap:r}=this._cache.swap(e.root,null,()=>({oldSrcList:Z(),oldMap:R()}));return t.observeChangesFor(e,{insert:(e,t)=>{r=r.set(t[0],t[1])},delete:(e,t)=>{r=r.delete(t[0])}}),this._cache.swap(e.root,{oldSrcList:e,oldMap:r}),r}}class ke{constructor(e){this.orderSelector=e,this._cache=new _e}select(e){if(0===e.size)return e;let{oldSrcList:t,oldOrderedList:r}=this._cache.swap(e.root,null,()=>({oldSrcList:null,oldOrderedList:null}));if(null==t){let t=e.toArray();t.sort((e,t)=>{return o(this.orderSelector(e),this.orderSelector(t))}),r=Z(t,!0)}else t.observeChangesFor(e,{insert:(e,t)=>{const s=r.binaryFindInsertionIndexByKey(this.orderSelector(t),this.orderSelector);r=r.insert(s,t)},delete:(e,t)=>{const s=r.binaryFindIndexByKey(this.orderSelector(t),this.orderSelector);r=r.delete(s)}});return this._cache.swap(e.root,{oldSrcList:e,oldOrderedList:r}),r}}class ze{constructor(e){null==e&&(e=(e=>e)),this.ungrouper=e,this._cache=new _e}select(e){let{oldSrcMap:t,oldUngroupedList:r,oldIndexOffsetMap:s}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldUngroupedList:Z(),oldIndexOffsetMap:new Map}));return t.observeChangesFor(e,{insert:(e,t)=>{let i=r.size;s.set(e,i);for(let s of t)r=r.push(this.ungrouper(s,e))},delete:(e,t)=>{let i=s.get(e),n=-t.size;r=r.splice(i,t.size),s.delete(e);for(let[e,t]of s)t>i&&s.set(e,t+n)},set:(e,t,i)=>{const n=s.get(e);t.observeChangesFor(i,{insert:(t,s)=>{r=r.insert(n+t,this.ungrouper(s,e))},delete:(e,t)=>{r=r.delete(n+e)},set:(t,s,i)=>{r=r.set(n+t,this.ungrouper(i,e))}}),0===i.size&&s.delete(e);let l=i.size-t.size;for(let[e,t]of s)t>n&&s.set(e,t+l)}}),this._cache.swap(e.root,{oldSrcMap:e,oldUngroupedList:r,oldIndexOffsetMap:s}),r}}class Me{constructor(){this._cache=new _e}select(e){let{oldSrcMap:t,oldKeysList:r}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldKeysList:Z()}));return t.observeChangesFor(e,{insert:(e,t)=>{r=r.push(e)},delete:(e,t)=>{const s=r.indexOf(e);if(s<0)throw new Error("unable to find index of key");r=r.delete(s)},set:(e,t,r)=>{}}),this._cache.swap(e.root,{oldSrcMap:e,oldKeysList:r}),r}}class Se{constructor(){this._cache=new _e}select(e){let{oldSrcMap:t,oldValuesList:r,oldIndexOffsetMap:s}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldValuesList:Z(),oldIndexOffsetMap:new Map}));return t.observeChangesFor(e,{insert:(e,t)=>{let i=r.size;s.set(e,i),r=r.push(t)},delete:(e,t)=>{let i=s.get(e);r=r.splice(i,1),s.delete(e);for(let[e,t]of s)t>i&&s.set(e,t+-1)},set:(e,t,i)=>{const n=s.get(e);r=r.set(n,i)}}),this._cache.swap(e.root,{oldSrcMap:e,oldValuesList:r,oldIndexOffsetMap:s}),r}}class Le{constructor(){this._root=new WeakMap}swap(e,t,r){if(0===e.length)throw new Error("must have at least one key");return this.__swap(this._root,0,e,t,r)}__swap(e,t,r,s,i){const n=r[t];if(t===r.length-1){const t=e.get(n);return null==s?e.delete(n):e.set(n,s),null==t&&null!=i?i():t}{let l=e.get(n);return null==l&&(l=new WeakMap,e.set(n,l)),this.__swap(l,t+1,r,s,i)}}}class Be{constructor(e,t){this.secondarySelector=e,this.joiner=t,this.needsOriginalInput=!0,this._cache=new Le,this._resolveManyCache=new _e}select(e,t){const r=this.secondarySelector(t);if(0===e.size)return R();let{oldSrcMap:s,oldSecondaryMap:i,oldJoinedMap:n,secondariesByPrimary:l,primaryBySecondary:a}=this._cache.swap([e.root,r.root],null,()=>({oldSrcMap:R(),oldSecondaryMap:R(),oldJoinedMap:R(),secondariesByPrimary:new Map,primaryBySecondary:new Map})),o=new Set,h=e=>{let t=a.get(e);if(null!=t){for(let e of l.get(t))a.delete(e);l.delete(t),o.add(t)}};i.observeChangesFor(r,{insert:h,delete:h}),s.observeChangesFor(e,{insert:(e,t)=>{o.add(e)},delete:(e,t)=>{o.delete(e);let r=l.get(e);if(null!=r)for(let e of r)a.delete(e);l.delete(e)}});for(let t of o){let s=new Set,i=e=>null==e?null:(s.add(e),r.get(e)),o=e=>{if(null==e||0===e.size)return Z();let{oldSecondaryKeys:t,oldSecondaryValues:r}=this._resolveManyCache.swap(e.root,null,()=>({oldSecondaryKeys:Z(),oldSecondaryValues:Z()}));t.observeChangesFor(e,{insert:(e,t)=>{r=r.insert(e,i(t))},delete:(e,t)=>{r=r.delete(e)},set:(e,t,s)=>{r=r.set(e,i(s))}});for(let t=0;t<e.size;++t)r=r.set(t,i(e.get(t)));return this._resolveManyCache.swap(e.root,{oldSecondaryKeys:e,oldSecondaryValues:r}),r},h=this.joiner(t,e.get(t),i,o);n=n.set(t,h);for(let e of s)a.set(e,t);l.set(t,s)}return this._cache.swap([e.root,r.root],{oldSrcMap:e,oldSecondaryMap:r,oldJoinedMap:n,secondariesByPrimary:l,primaryBySecondary:a}),n}}class Fe{constructor(e){null==e&&(e="ListTracer"),this.name=e,this._cache=new _e}select(e){let t=this._cache.swap(e.root,null);return null==t&&(console.log(`[${this.name}] (cache miss)`),t=Z()),t.observeChangesFor(e,{insert:(e,t)=>console.log(`[${this.name}] insert`,e,t),delete:(e,t)=>console.log(`[${this.name}] delete`,e,t),set:(e,t,r)=>console.log(`[${this.name}] set`,e,t,r)}),this._cache.swap(e.root,t),e}}class xe{constructor(e){null==e&&(e="MapTracer"),this.name=e,this._cache=new _e}select(e){let t=this._cache.swap(e.root,null);return null==t&&(console.log(`[${this.name}] (cache miss)`),t=R()),t.observeChangesFor(e,{insert:(e,t)=>console.log(`[${this.name}] insert`,e,t),delete:(e,t)=>console.log(`[${this.name}] delete`,e,t),set:(e,t,r)=>console.log(`[${this.name}] set`,e,t,r)}),this._cache.swap(e.root,e),e}}class Ie{constructor(e){null==e&&(e=o),this.comparator=e,this._cache=new _e}select(e){if(0===e.size)return e;let{oldSrcList:t,oldOrderedList:r}=this._cache.swap(e.root,null,()=>({oldSrcList:null,oldOrderedList:null}));if(null==t){let t=e.toArray();t.sort(this.comparator),r=Z(t,!0)}else t.observeChangesFor(e,{insert:(e,t)=>{const s=r.binaryFindInsertionIndex(t,this.comparator);r=r.insert(s,t)},delete:(e,t)=>{const s=r.binaryFindIndex(t,this.comparator);r=r.delete(s)}});return this._cache.swap(e.root,{oldSrcList:e,oldOrderedList:r}),r}}class We{constructor(e){this.predicate=e,this._cache=new _e}select(e){let{oldSrcMap:t,oldFilteredMap:r}=this._cache.swap(e.root,null,()=>({oldSrcMap:R(),oldFilteredMap:R()}));return t.observeChangesFor(e,{insert:(e,t)=>{this.predicate(t)&&(r=r.set(e,t))},delete:(e,t)=>{this.predicate(t)&&(r=r.delete(e))},set:(e,t,s)=>{const i=this.predicate(t),n=this.predicate(s);i&&!n?r=r.delete(e):n&&(r=r.set(e,s))}}),this._cache.swap(e.root,{oldSrcMap:e,oldFilteredMap:r}),r}}class Ce{constructor(e){this.mapper=e,this._cache=new _e}select(e){if(0===e.size)return Z();let{prevList:t,flatMappedList:r,offsets:s,mappedValues:i}=this._cache.swap(e.root,null,()=>({prevList:Z(),flatMappedList:Z(),offsets:[],mappedValues:[]}));const n=(e,t)=>{let n=0;n=e>=s.length?r.size:s[e];let l=0;for(let e of t)r=r.insert(n+l,e),++l;for(let t=e;t<s.length;++t)s[t]+=l;s.splice(e,0,n),i.splice(e,0,t)},l=e=>{let t=s[e],n=0,l=(n=e+1>=s.length?r.size:s[e+1])-t;for(let e=n-1;e>=t;--e)r=r.delete(e);for(let t=e;t<s.length;++t)s[t]-=l;s.splice(e,1),i.splice(e,1)};return t.observeChangesFor(e,{insert:(e,t)=>n(e,this.mapper(t)),delete:(e,t)=>l(e),set:(e,t,a)=>{const o=i[e],h=this.mapper(a);if(!ee(o)||!ee(h))return l(e),void n(e,h);const c=s[e];o.observeChangesFor(h,{insert:(e,t)=>{r=r.insert(c+e,t)},delete:(e,t)=>{r=r.delete(c+e)},set:(e,t,s)=>{r=r.set(c+e,s)}});const u=a.size-t.size;for(let t=e+1;t<s.length;++t)s[t]+=u;i[e]=h}}),this._cache.swap(e.root,{prevList:e,flatMappedList:r,offsets:s,mappedValues:i}),r}}class Ae{constructor(e,t,r){this.selectors=e,this.accepts=t,this.emits=r}func(){const e=this,t=function(t){if(!function(e,t){if("list"===t)return e instanceof X||e===Y;if("map"===t)return e instanceof U||e===G;throw new Error("unknown typeName: "+t)}(t,e.accepts))throw new Error("incorrect argument type for the selector - expected "+e.accepts);let r=arguments[0];for(let t of e.selectors)r=t.needsOriginalInput?t.select(r,arguments[0]):t.select(r);return r};return"list"===this.emits&&(t.filter=(e=>new Ae([...this.selectors,new we(e)],this.accepts,"list").func()),t.map=(e=>new Ae([...this.selectors,new ye(e)],this.accepts,"list").func()),t.flatMap=(e=>new Ae([...this.selectors,new Ce(e)],this.accepts,"list").func()),t.flatten=(()=>new Ae([...this.selectors,new Ce(e=>e)],this.accepts,"list").func()),t.orderBy=(e=>new Ae([...this.selectors,new ke(e)],this.accepts,"list").func()),t.sort=(e=>new Ae([...this.selectors,new Ie(e)],this.accepts,"list").func()),t.groupBy=((e,t)=>new Ae([...this.selectors,new me(e,t)],this.accepts,"map").func()),t.toMap=(()=>new Ae([...this.selectors,new be],this.accepts,"map").func()),t.trace=(e=>new Ae([...this.selectors,new Fe(e)],this.accepts,this.emits).func())),"map"===this.emits&&(t.ungroup=(e=>new Ae([...this.selectors,new ze(e)],this.accepts,"list").func()),t.map=(e=>new Ae([...this.selectors,new ve(e)],this.accepts,"map").func()),t.keys=(()=>new Ae([...this.selectors,new Me],this.accepts,"list").func()),t.values=(()=>new Ae([...this.selectors,new Se],this.accepts,"list").func()),t.join=((e,t)=>{if(null==e.__pipeline)throw new Error(".join() expects a secondary selector created by select()");if("map"!==e.__pipeline.emits)throw new Error("the secondary selector must emit a map");if(e.__pipeline.accepts!==this.accepts)throw new Error("the secondary selector must accept the same input");return new Ae([...this.selectors,new Be(e,t)],this.accepts,"map").func()}),t.trace=(e=>new Ae([...this.selectors,new xe(e)],this.accepts,this.emits).func()),t.filterByValue=(e=>new Ae([...this.selectors,new We(e)],this.accepts,"map").func())),t.__pipeline=this,t}}function Pe(){return new Ae([],"list","list").func()}function Ee(){return new Ae([],"map","map").func()}function Oe(e){if(null==e.__pipeline)throw new Error("select.from() expects another selector created by select as its argument");return e}r.d(t,"ImmyList",function(){return Z}),r.d(t,"List",function(){return Z}),r.d(t,"listSelect",function(){return s}),r.d(t,"listCombine",function(){return i}),r.d(t,"select",function(){return n}),r.d(t,"ImmyMap",function(){return R}),r.d(t,"Map",function(){return R}),r.d(t,"ImmySet",function(){return O}),r.d(t,"Set",function(){return O});t.default={ImmyList:Z,List:Z,listSelect:s,listCombine:i,select:n,ImmyMap:R,Map:R,ImmySet:O,Set:O}}]);
{
"name": "immy",
"version": "1.0.0-alpha.25",
"version": "1.0.0-alpha.26",
"description": "Fast immutable data structures that use change-tracking",

@@ -5,0 +5,0 @@ "main": "dist/immy.js",

@@ -33,4 +33,6 @@

--this.size
return this._buffer[this.size]
const r = this._buffer[this.size]
this._buffer[this.size] = undefined // don't leak references
return r
}
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc