retirement-simulator
Version:
Retirement Simulator
1 lines • 95 kB
JavaScript
import{csvParse as e,scaleOrdinal as t}from"d3";const r=Symbol.for("compare"),n=(e,t)=>{const s=typeof e,i=typeof t;if(s<i)return-1;if(i<s)return 1;switch(s){case"number":case"string":case"boolean":if(e<t)return-1;if(e>t)return 1;break;case"symbol":return n(e.description,t.description);case"object":if(!e&&t)return-1;if(!t&&e)return 1;if(t===e)return 0;if(e instanceof Date&&t instanceof Date)return n(e.getTime(),t.getTime());const s=e.constructor,i=t.constructor;if(s===i){return(s[r]??a)(e,t)}return n(s.name,i.name)}return 0},a=(e,t)=>0,s=(e,...t)=>{if(0===t.length)return e;const r=s(t[0],...t.slice(1));return(t,n)=>{const a=e(t,n);return 0===a?r(t,n):a}},i=e=>(t,r)=>n(t[e],r[e]),o=i("value"),l=i("rate"),c=i("name"),u=i("type"),h=i("start"),f=e=>(t,r)=>e(r,t),p={byValue:s(f(o),u,c),byRate:s(f(l),u,c),byName:s(c,u),byType:s(u,c),byStart:s(h,u,c),null:a,natural:n},m=(e=n)=>t=>[...t].sort(e),y=m(),d=e=>"function"==typeof e,g=e=>e&&(N(e)||$(e)),b=e=>e&&(E(e)||O(e)||$(e)),v=e=>e&&d(e.next)&&d(e.return)&&d(e.throw)&&d(e[Symbol.iterator]),_=e=>e&&d(e.next)&&d(e.return)&&d(e.throw)&&d(e[Symbol.asyncIterator]);function w(e){if(v(e))return e;if(N(e)){const t=e;return function*(){for(;;){const e=t.next();if(e.done)return e.value;yield e.value}}()}if($(e))return w(e[Symbol.iterator]());throw new Error(`Not iterable: ${e}`)}function x(e){if(_(e))return e;if(E(e)){const t=e;return async function*(){for(;;){const e=await t.next();if(e.done)return e.value;yield e.value}}()}if(O(e))return x(e[Symbol.asyncIterator]());if($(e))return x(e[Symbol.iterator]());throw new Error(`Not iterable: ${e}`)}function S(e){if(v(e))return e;if(N(e))return e;if($(e))return e[Symbol.iterator]();throw new Error(`Not iterable: ${e}`)}function T(e){if(_(e))return e;if(O(e))return e[Symbol.asyncIterator]();if($(e))return M(S(e));throw new Error(`Not iterable: ${e}`)}const M=e=>{const t=e;let r;return r=async function*(){let n,a=!1;try{for(;;){const e=await Promise.resolve(t.next());if(e.done)return a=!0,e.value;try{n=yield e.value}catch(e){throw await(t.throw?.(e)),e}}}finally{a||await(e.return?.(r.returning))}}()};function I(e){return $(e)?e:{[Symbol.iterator]:()=>e}}function A(e){return O(e)?e:$(e)?k(e):{[Symbol.asyncIterator]:()=>e}}async function*k(e){const t=e[Symbol.iterator]();let r;for(;;){const e=await t.next(r);if(e.done)return e.value;r=yield e.value}}const N=e=>e&&"function"==typeof e.next,E=e=>e&&"function"==typeof e.next,$=e=>e&&"function"==typeof e[Symbol.iterator],O=e=>e&&"function"==typeof e[Symbol.asyncIterator],C=(e,t)=>(...r)=>{try{return e(...r)}catch(e){return t?.(e)}};class U{returning;[Symbol.toStringTag];asArray(){return this._impl.asArray(this)}limit(e){return this._impl.limit(e,this)}forEach(e,t){this._impl.forEach(e,t,this)}map(e,t){return this._impl.map(e,t,this)}filter(e,t){return this._impl.filter(e,t,this)}flat(e=1){return this._impl.flat(e,this)}flatMap(e,t=1){return this._impl.flatMap(e,t,this)}slice(e=0,t=Number.POSITIVE_INFINITY){return this._impl.slice(e,t,this)}concat(...e){return this._impl.concat(this,...e)}reduce(e,t){return this._impl.reduce(e,t,this)}some(e,t){return this._impl.some(e,t,this)}every(e,t){return this._impl.every(e,t,this)}repeatLast(e=Number.POSITIVE_INFINITY){return this._impl.repeatLast(this,e)}repeat(e,t=Number.POSITIVE_INFINITY){const r=this._impl.repeat(e,t);return this._impl.concat(this,r)}zip(...e){return this._impl.zip(this,...e)}join(e){return this._impl.join(this,e)}sort(e){return this._impl.sort(e)(this)}}class j extends U{[Symbol.toStringTag]}const F=new class{of(...e){return this.enhance(e)}asArray(e){return[...I(e)]}limit(e,t){let r;function*n(t){let n,a=!1;try{for(let r=0;r<e;r++){const e=t.next(n);if(e.done)return e.value;try{n=yield e.value}catch(e){t.throw?.(e)}}a=!0;const s=new RangeError(`Generator produced excessive values > ${e}.`);throw t.throw?.(s),s}finally{a||t.return?.(r?.returning)}}return t?r=this.enhance(n(S(t))):e=>this.enhance(n(S(e)))}forEach(e,t,r){const n=(e,t,r)=>{const n=S(r);let a=0;for(;;){const r=n.next();if(r.done)return;e.call(t,r.value,a++)}};return r?n(e,t,r):g(t)?n(e,void 0,t):(r,a)=>n(e,a??t,r)}map(e,t,r){const n=(t,r)=>{const n=w(r);let a;return a=this.enhance(function*(){let r,s=0;for(;;)for(;;)try{for(;;){const a=n.next(r);if(a.done)return a.value;const i=e.call(t,a.value,s++);try{r=yield i}catch(e){n.throw(e)}}}finally{if(!n.return(a?.returning).done)break}}())};return r?n(t,r):g(t)?n(void 0,t):(e,r)=>n(r??t,e)}filter(e,t,r){const n=(t,r)=>{const n=w(r);let a;return a=this.enhance(function*(e){let r,s=0;for(;;)for(;;)try{for(;;){const a=n.next(r);if(a.done)return a.value;if(e.call(t,a.value,s++))try{r=yield a.value}catch(e){n.throw(e)}}}finally{const e=n.return?.(a?.returning);if(!e?.done)break}}(e))};return r?n(t,r):g(t)?n(void 0,t):(e,r)=>n(r??t,e)}flat(e,t){const r=(e,t)=>{let r;const n=new Set;return v(t)&&n.add(t),r=this.enhance(function*e(t,a){let s;for(;;)for(;;)try{for(;;){const r=t.next(s);if(r.done)return r.value;const i=r.value;v(i)&&n.add(i);try{a>0&&N(i)?yield*e(i,a-1):a>0&&$(i)?yield*e(S(i),a-1):s=yield r.value}catch(e){t.throw?.(e)}}}finally{const e=t.return?.(r?.returning);if(v(t)&&n.delete(t),e&&!e.done)break;for(const e of n)e.return(r?.returning)}}(S(t),e))};if("number"==typeof e){if(t){if(g(t))return r(e,t);throw new TypeError(`Invalid Genable: ${t}`)}return t=>r(e,t)}if(g(e))return r(t??1,e);throw new TypeError("Illegal arguments to flat()")}flatMap(e,t,r){const n=(t,r)=>{let n,a=0;return n=this.enhance(function*t(r,s){let i;for(;;)for(;;)try{for(;;){const n=r.next(i);if(n.done)return n.value;const o=e(n.value,a++);try{N(o)?s>1?yield*t(o,s-1):1===s?yield*w(o):yield o:$(o)?s>1?yield*t(S(o),s-1):1===s?yield*w(o):yield o:i=yield o}catch(e){r.throw?.(e)}}}finally{const e=r.return?.(n?.returning);if(e&&!e.done)break}}(S(r),t))};return g(r)?n(t??1,r):g(t)?n(1,t):(e,r)=>n(t??r??1,e)}slice(e,t,r){const n=r=>{const n=S(r);return this.enhance(function*(e,t){for(let t=0;t<e;t++){const e=n.next();if(e.done)return e.value}if(t===Number.POSITIVE_INFINITY)yield*I(n);else{let r;for(;;)try{for(let a=e;a<t;a++){const t=n.next(r);if(t.done)return t.value;try{r=yield t.value}catch(e){const t=n.throw?.(e);if(t){if(t.done)return t.value;r=yield t.value}}}}finally{const e=n.return?.();if(e&&!e.done)break}}}(e,t))};return r?n(r):n}concat(...e){let t;return t=this.enhance(function*(){let r=0;try{for(;r<e.length;r++)yield*I(e[r])}finally{for(;r<e.length;r++){const n=e[r];v(n)&&n.return(t?.returning)}}}())}reduce(e,t,r){const n=(t,r)=>{let n=t;if(void 0===n){const e=r.next();if(e.done)throw new TypeError("No initial value in reduce");n=e.value}for(;;){const t=r.next();if(t.done)return n;n=e(n,t.value)}};return g(r)?n(t,S(r)):g(t)?n(void 0,S(t)):(e,r)=>n(r??t,S(e))}some(e,t,r){const n=(t,r)=>{let n=0;for(;;){const a=r.next();if(a.done)return!1;if(e.call(t,a.value,n++))return!0}};return g(r)?n(t,S(r)):g(t)?n(void 0,S(t)):(e,r)=>n(r??t,S(e))}every(e,t,r){const n=(t,r)=>{let n=0;for(;;){const a=r.next();if(a.done)return!0;if(!e.call(t,a.value,n++))return!1}};if(g(r))return n(t,S(r));if(g(r))return(e,r)=>n(r??t,S(e));throw new Error(`Invalid argument to every: ${r??t}`)}repeatLast(e,t=Number.POSITIVE_INFINITY){const r=S(e);let n,a;return a=this.enhance(function*(){try{let e;for(;;){const t=r.next(n);if(t.done)break;try{n=yield e=t.value}catch(t){const n=r.throw?.(t);if(n){if(n.done)break;yield e=n.value}}}for(let r=0;r<t;r++)yield e}finally{r.return?.(a?.returning)}}())}repeat(e,t=Number.POSITIVE_INFINITY){return this.enhance(function*(){for(let r=0;r<t;r++)yield e}())}zip(...e){if(0===e.length)return this.enhance([]);const t=e.map(S);let r,n=!1;return r=this.enhance(function*(){try{for(;;){let r=[];for(const e of t){const t=e.next();if(t.done)return n=!0,t.value;r.push(t.value)}try{yield r}catch(t){for(const r of e)try{r.throw?.(t)}catch{}throw t}}}finally{if(!n)for(const t of e)try{t.return?.(r?.returning)}catch{}}}())}join(e,t){return"string"==typeof e?(t=e,e=>this.join(e,t)):[...I(e)].join(t)}merge(...e){let t,r=e.map(S);return t=this.enhance(function*(e){let r,n=!1,a=!0;try{for(;a;){a=!1;for(let t=0;t<e.length;t++){const n=e[t];if(n){const s=n.next(r);if(s.done)e[t]=null;else{a=!0;try{r=yield s.value}catch(t){e.forEach(C((e=>e?.throw?.(t))))}}}}}n=!0}finally{n||e.forEach(C((e=>e?.return?.(t?.returning))))}return t?.returning}(r))}sort(e){return(...t)=>this.merge(...t).asArray().sort(e)}enhance(e){const t=w(e),r=Object.getPrototypeOf(t),n=Object.create(j.prototype);return n.return=e=>(t.returning=e,r.return.call(t,e)),n[Symbol.iterator]=()=>t,Object.setPrototypeOf(t,n),t}};var P,D;(P||(P={})).Mixin=function(e){class t extends e{#e=void 0;constructor(...e){super(...e)}#t(){return F.enhance(this[Symbol.iterator]())}asArray(){return this.#t().asArray()}limit(e){return this.#t().limit(e)}forEach(e,t){return this.#t().forEach(e,t)}map(e,t){return this.#t().map(e,t)}filter(e,t){return this.#t().filter(e,t)}flat(e=1){return this.#t().flat(e)}flatMap(e,t=1){return this.#t().flatMap(e,t)}slice(e=0,t=Number.MAX_SAFE_INTEGER){return this.#t().slice(e,t)}concat(...e){return this.#t().concat(...e)}reduce(e,t){return this.#t().reduce(e,t)}some(e,t){return this.#t().some(e,t)}every(e,t){return this.#t().every(e,t)}repeatLast(e=Number.MAX_SAFE_INTEGER){return this.#t().repeatLast(e)}repeat(e,t=Number.MAX_SAFE_INTEGER){return this.#t().repeat(e,t)}join(e=""){return this.#t().join(e)}sort(e){return this.#t().sort(e)}get[Symbol.toStringTag](){try{return this.#e??(this.#e=`Sync.Mixin(${e.name})`)}catch{return`Sync.Mixin(${e.name}).prototype`}}}return t};class R{#r;constructor(e,t){this.#r=e.bind(this,...t)}[Symbol.iterator](){return F.enhance(w(this.#r()))}}class Y extends(P.Mixin(R)){constructor(e,t){super(e,t)}}(D||(D={})).wrap=(e,...t)=>new Y(e,t);const q=Object.getPrototypeOf(function*(){}());var z;Object.setPrototypeOf(j.prototype,(e=>{const t=Object.create(e);return(e=>{for(const r of Reflect.ownKeys(e))"constructor"!==r&&(t[r]=e[r])})(U.prototype),t})(q)),Object.defineProperty(j.prototype,"_impl",{value:F,writable:!1,enumerable:!1,configurable:!1}),function(e){e.asArray=F.asArray.bind(F),e.concat=F.concat.bind(F),e.every=F.every.bind(F),e.filter=F.filter.bind(F),e.flat=F.flat.bind(F),e.flatMap=F.flatMap.bind(F),e.forEach=F.forEach.bind(F),e.join=F.join.bind(F),e.limit=F.limit.bind(F),e.map=F.map.bind(F),e.merge=F.merge.bind(F),e.of=F.of.bind(F),e.reduce=F.reduce.bind(F),e.repeat=F.repeat.bind(F),e.repeatLast=F.repeatLast.bind(F),e.slice=F.slice.bind(F),e.some=F.some.bind(F),e.sort=F.sort.bind(F),e.zip=F.zip.bind(F),e.enhance=F.enhance.bind(F),e.Mixin=P.Mixin,e.wrap=D.wrap}(z||(z={}));const L=(e=0,t=Number.MAX_SAFE_INTEGER,r=1)=>z.enhance(function*(e=0,t=Number.MAX_SAFE_INTEGER,r=1){let n=e;if(r>0)for(;n<t;)yield n,n+=r;else{if(!(r<0))throw new Error("Step must not be zero.");for(;n>t;)yield n,n+=r}}(e,t,r));function G(e,t){t=t||{},this._head=0,this._tail=0,this._capacity=t.capacity,this._capacityMask=3,this._list=new Array(4),Array.isArray(e)&&this._fromArray(e)}G.prototype.peekAt=function(e){var t=e;if(t===(0|t)){var r=this.size();if(!(t>=r||t<-r))return t<0&&(t+=r),t=this._head+t&this._capacityMask,this._list[t]}},G.prototype.get=function(e){return this.peekAt(e)},G.prototype.peek=function(){if(this._head!==this._tail)return this._list[this._head]},G.prototype.peekFront=function(){return this.peek()},G.prototype.peekBack=function(){return this.peekAt(-1)},Object.defineProperty(G.prototype,"length",{get:function(){return this.size()}}),G.prototype.size=function(){return this._head===this._tail?0:this._head<this._tail?this._tail-this._head:this._capacityMask+1-(this._head-this._tail)},G.prototype.unshift=function(e){if(0===arguments.length)return this.size();var t=this._list.length;return this._head=this._head-1+t&this._capacityMask,this._list[this._head]=e,this._tail===this._head&&this._growArray(),this._capacity&&this.size()>this._capacity&&this.pop(),this._head<this._tail?this._tail-this._head:this._capacityMask+1-(this._head-this._tail)},G.prototype.shift=function(){var e=this._head;if(e!==this._tail){var t=this._list[e];return this._list[e]=void 0,this._head=e+1&this._capacityMask,e<2&&this._tail>1e4&&this._tail<=this._list.length>>>2&&this._shrinkArray(),t}},G.prototype.push=function(e){if(0===arguments.length)return this.size();var t=this._tail;return this._list[t]=e,this._tail=t+1&this._capacityMask,this._tail===this._head&&this._growArray(),this._capacity&&this.size()>this._capacity&&this.shift(),this._head<this._tail?this._tail-this._head:this._capacityMask+1-(this._head-this._tail)},G.prototype.pop=function(){var e=this._tail;if(e!==this._head){var t=this._list.length;this._tail=e-1+t&this._capacityMask;var r=this._list[this._tail];return this._list[this._tail]=void 0,this._head<2&&e>1e4&&e<=t>>>2&&this._shrinkArray(),r}},G.prototype.removeOne=function(e){var t=e;if(t===(0|t)&&this._head!==this._tail){var r=this.size(),n=this._list.length;if(!(t>=r||t<-r)){t<0&&(t+=r),t=this._head+t&this._capacityMask;var a,s=this._list[t];if(e<r/2){for(a=e;a>0;a--)this._list[t]=this._list[t=t-1+n&this._capacityMask];this._list[t]=void 0,this._head=this._head+1+n&this._capacityMask}else{for(a=r-1-e;a>0;a--)this._list[t]=this._list[t=t+1+n&this._capacityMask];this._list[t]=void 0,this._tail=this._tail-1+n&this._capacityMask}return s}}},G.prototype.remove=function(e,t){var r,n=e,a=t;if(n===(0|n)&&this._head!==this._tail){var s=this.size(),i=this._list.length;if(!(n>=s||n<-s||t<1)){if(n<0&&(n+=s),1===t||!t)return(r=new Array(1))[0]=this.removeOne(n),r;if(0===n&&n+t>=s)return r=this.toArray(),this.clear(),r;var o;for(n+t>s&&(t=s-n),r=new Array(t),o=0;o<t;o++)r[o]=this._list[this._head+n+o&this._capacityMask];if(n=this._head+n&this._capacityMask,e+t===s){for(this._tail=this._tail-t+i&this._capacityMask,o=t;o>0;o--)this._list[n=n+1+i&this._capacityMask]=void 0;return r}if(0===e){for(this._head=this._head+t+i&this._capacityMask,o=t-1;o>0;o--)this._list[n=n+1+i&this._capacityMask]=void 0;return r}if(n<s/2){for(this._head=this._head+e+t+i&this._capacityMask,o=e;o>0;o--)this.unshift(this._list[n=n-1+i&this._capacityMask]);for(n=this._head-1+i&this._capacityMask;a>0;)this._list[n=n-1+i&this._capacityMask]=void 0,a--;e<0&&(this._tail=n)}else{for(this._tail=n,n=n+t+i&this._capacityMask,o=s-(t+e);o>0;o--)this.push(this._list[n++]);for(n=this._tail;a>0;)this._list[n=n+1+i&this._capacityMask]=void 0,a--}return this._head<2&&this._tail>1e4&&this._tail<=i>>>2&&this._shrinkArray(),r}}},G.prototype.splice=function(e,t){var r=e;if(r===(0|r)){var n=this.size();if(r<0&&(r+=n),!(r>n)){if(arguments.length>2){var a,s,i,o=arguments.length,l=this._list.length,c=2;if(!n||r<n/2){for(s=new Array(r),a=0;a<r;a++)s[a]=this._list[this._head+a&this._capacityMask];for(0===t?(i=[],r>0&&(this._head=this._head+r+l&this._capacityMask)):(i=this.remove(r,t),this._head=this._head+r+l&this._capacityMask);o>c;)this.unshift(arguments[--o]);for(a=r;a>0;a--)this.unshift(s[a-1])}else{var u=(s=new Array(n-(r+t))).length;for(a=0;a<u;a++)s[a]=this._list[this._head+r+t+a&this._capacityMask];for(0===t?(i=[],r!=n&&(this._tail=this._head+r+l&this._capacityMask)):(i=this.remove(r,t),this._tail=this._tail-u+l&this._capacityMask);c<o;)this.push(arguments[c++]);for(a=0;a<u;a++)this.push(s[a])}return i}return this.remove(r,t)}}},G.prototype.clear=function(){this._head=0,this._tail=0},G.prototype.isEmpty=function(){return this._head===this._tail},G.prototype.toArray=function(){return this._copyArray(!1)},G.prototype._fromArray=function(e){for(var t=0;t<e.length;t++)this.push(e[t])},G.prototype._copyArray=function(e){var t,r=[],n=this._list,a=n.length;if(e||this._head>this._tail){for(t=this._head;t<a;t++)r.push(n[t]);for(t=0;t<this._tail;t++)r.push(n[t])}else for(t=this._head;t<this._tail;t++)r.push(n[t]);return r},G.prototype._growArray=function(){this._head&&(this._list=this._copyArray(!0),this._head=0),this._tail=this._list.length,this._list.length<<=1,this._capacityMask=this._capacityMask<<1|1},G.prototype._shrinkArray=function(){this._list.length>>>=1,this._capacityMask>>>=1};var V=G;const H=Symbol.for("endTag"),K=e=>e instanceof Object&&"throw"===e[H];class B extends Promise{#r;#n;#a;#s;#i;#o;static[Symbol.toStringTag]="Future";static[Symbol.species]=Promise;constructor(e,t){let r,n;super(((e,t)=>{r=e,n=t})),this.#a=r,this.#s=n,this.#r=e,this.#n=!!t}eval(e,t){if(!this.#r){if(this.#o)throw this.#o;return this.#i}try{return this.#i=this.#r(),this.#a?.(this.#i),this.#i}catch(e){throw this.#o=e,this.#s?.(e),e}finally{this.#r=void 0,this.#a=void 0,this.#s=void 0,(e||t)&&super.then(e,t)}}then(e,t){if(this.#r&&!this.#n&&(e||t))try{this.eval()}catch(e){}return e||t?super.then(e,t):this}}class W extends U{}const X=new class{of(...e){return this.enhance(e)}async asArray(e){const t=T(e),r=[];for(;;){const e=await t.next();if(e.done)return r;r.push(e.value)}}limit(e,t){let r;async function*n(t){let n,a=!1;try{for(let r=0;r<e;r++){const e=await t.next(n);if(e.done)return e.value;try{n=yield e.value}catch(e){await(t.throw?.(e))}}a=!0;const s=new RangeError(`Generator produced excessive values > ${e}.`);throw await(t.throw?.(s)),s}finally{a||await(t.return?.(r?.returning))}}return t?r=this.enhance(n(T(t))):e=>this.enhance(n(T(e)))}forEach(e,t,r){const n=async(e,t,r)=>{const n=T(r);let a=0;for(;;){const r=await n.next();if(r.done)return;await e.call(t,r.value,a++)}};return r?n(e,t,r):b(t)?n(e,void 0,t):(r,a)=>n(e,a??t,r)}map(e,t,r){const n=(t,r)=>{const n=x(r);let a;return a=this.enhance(async function*(){let r,s=0;for(;;)for(;;)try{for(;;){const a=await n.next(r);if(a.done)return a.value;const i=await e.call(t,await a.value,s++);try{r=yield i}catch(e){await n.throw(e)}}}finally{if(!(await n.return(a?.returning)).done)break}}())};return r?n(t,r):b(t)?n(void 0,t):(e,r)=>n(r??t,e)}filter(e,t,r){const n=(t,r)=>{const n=x(r);let a;return a=this.enhance(async function*(e){let r,s=0;for(;;)for(;;)try{for(;;){const a=await n.next(r);if(a.done)return a.value;if(await e.call(t,a.value,s++))try{r=yield a.value}catch(e){await n.throw(e)}}}finally{if(!(await(n.return?.(a?.returning)))?.done)break}}(e))};return r?n(t,r):b(t)?n(void 0,t):(e,r)=>n(r??t,e)}flat(e,t){const r=(e,t)=>{let r;const n=new Set;return _(t)&&n.add(t),r=this.enhance(async function*e(t,a){let s;for(;;)for(;;)try{for(;;){const r=await t.next(s);if(r.done)return r.value;const i=r.value;_(i)&&n.add(i);try{a>0&&E(i)?yield*e(i,a-1):a>0&&(O(i)||$(i))?yield*e(T(i),a-1):s=yield r.value}catch(e){await(t.throw?.(e))}}}finally{const e=await(t.return?.(r?.returning));if(_(t)&&n.delete(t),e&&!e.done)break;for(const e of n)await e.return(r?.returning)}}(T(t),e))};if("number"==typeof e){if(t){if(b(t))return r(e,t);throw new TypeError(`Invalid Genable: ${t}`)}return t=>r(e,t)}if(b(e))return r(t??1,e);throw new TypeError("Illegal arguments to flat()")}flatMap(e,t,r){const n=(t,r)=>{let n,a=0;return n=this.enhance(async function*t(r,s){let i;for(;;)for(;;)try{for(;;){const n=await r.next(i);if(n.done)return n.value;const o=await e(n.value,a++);try{if(E(o))if(s>1)yield*t(o,s-1);else if(1===s){const e=T(o);yield*x(e)}else yield o;else O(o)||$(o)?s>1?yield*t(T(o),s-1):1===s?yield*x(o):yield o:i=yield o}catch(e){await(r.throw?.(e))}}}finally{const e=await(r.return?.(n?.returning));if(e&&!e.done)break}}(T(r),t))};return b(r)?n(t??1,r):b(t)?n(1,t):(e,r)=>n(t??r??1,e)}slice(e,t,r){const n=r=>{const n=T(r);return this.enhance(async function*(e,t){for(let t=0;t<e;t++){const e=await n.next();if(e.done)return e.value}if(t===Number.POSITIVE_INFINITY)yield*A(n);else{let r;for(;;)try{for(let a=e;a<t;a++){const t=await n.next(r);if(t.done)return t.value;try{r=yield t.value}catch(e){const t=await(n.throw?.(e));if(t){if(t.done)return t.value;r=yield t.value}}}}finally{const e=await(n.return?.());if(e&&!e.done)break}}}(e,t))};return r?n(r):n}concat(...e){let t;return t=this.enhance(async function*(){let r=0;try{for(;r<e.length;r++){const t=A(e[r]);yield*t}}finally{for(;r<e.length;r++){const n=e[r];_(n)&&await n.return(t?.returning)}}}())}reduce(e,t,r){const n=async(t,r)=>{let n=await t;if(void 0===n){const e=await r.next();if(e.done)throw new TypeError("No initial value in reduce");n=e.value}for(;;){const t=await r.next();if(t.done)return n;n=await e(n,t.value)}};return b(r)?n(t,T(r)):b(t)?n(void 0,T(t)):(e,r)=>n(r??t,T(e))}some(e,t,r){const n=async(t,r)=>{let n=0;for(;;){const a=await r.next();if(a.done)return!1;if(e.call(t,a.value,n++))return!0}};if(b(r))return n(t,T(r));if(b(r))return(e,r)=>n(r??t,T(e));throw new Error(`Invalid argument to some: ${r??t}`)}every(e,t,r){const n=async(t,r)=>{let n=0;for(;;){const a=await r.next();if(a.done)return!0;if(!e.call(t,a.value,n++))return!1}};if(b(r))return n(t,T(r));if(g(r))return(e,r)=>n(r??t,T(e));throw new Error(`Invalid argument to every: ${r??t}`)}repeatLast(e,t=Number.POSITIVE_INFINITY){const r=T(e);let n,a;return a=this.enhance(async function*(){try{let e;for(;;){const t=await r.next(n);if(t.done)break;try{n=yield e=t.value}catch(t){const n=await(r.throw?.(t));if(n){if(n.done)break;yield e=n.value}}}for(let r=0;r<t;r++)yield await e}finally{await(r.return?.(a?.returning))}}())}repeat(e,t=Number.POSITIVE_INFINITY){return this.enhance(async function*(){for(let r=0;r<t;r++)yield await e}())}zip(...e){if(0===e.length)return this.enhance([]);const t=e.map(T);let r,n=!1;return r=this.enhance(async function*(){try{for(;;){let r=[];for(const e of t){const t=await e.next();if(t.done)return n=!0,t.value;r.push(t.value)}try{yield r}catch(t){for(const r of e)try{await(r.throw?.(t))}catch{}throw t}}}finally{if(!n)for(const t of e)try{await(t.return?.(r?.returning))}catch{}}}())}join(e,t){return"string"==typeof e?(t=e,e=>this.join(e,t)):Promise.resolve(this.enhance(e).asArray()).then((e=>e.join(t)))}merge(...e){let t,r;const n=new Promise((e=>r=e));let a,s=e.length;const i=new Promise((()=>null));let o=[];return a=[...e.map((async(e,t)=>{const n=T(e);o[t]=n;const l=async e=>()=>{if(e.done)return a[t]=i,--s>0?null:(r(e),e);{const r=n.next().then(l);return a[t]=r,e}};return await n.next().then(l)})),n],t=this.enhance(async function*(){try{let r;for(;s;){const e=[];a.forEach((t=>e.push(t)));const t=await await Promise.race(e);if("function"==typeof t){let e=t();if(e){if(e.done)return e.value;r=yield e.value}}else if(t&&t.done)return t.value}}finally{if(s)for(let r=0;r<e.length;r++)(null===a[r]?null:o[r])?.return?.(t?.returning)}}())}sort(e){return async(...t)=>(await this.merge(...t).asArray()).sort(e)}enhance(e){const t=x(e),r=Object.getPrototypeOf(t),n=Object.assign(Object.create(W.prototype),r);return n.return=e=>(t.returning=e,r.return.call(t,e)),n[Symbol.asyncIterator]=()=>t,Object.setPrototypeOf(t,n),t}};var J,Z;(J||(J={})).Mixin=function(e){class t extends e{#e=void 0;constructor(...e){super(...e)}#t(){return X.enhance(this[Symbol.asyncIterator]())}asArray(){return this.#t().asArray()}limit(e){return this.#t().limit(e)}forEach(e,t){return this.#t().forEach(e,t)}map(e,t){return this.#t().map(e,t)}filter(e,t){return this.#t().filter(e,t)}flat(e=1){return this.#t().flat(e)}flatMap(e,t=1){return this.#t().flatMap(e,t)}slice(e=0,t=Number.MAX_SAFE_INTEGER){return this.#t().slice(e,t)}concat(...e){return this.#t().concat(...e)}reduce(e,t){return this.#t().reduce(e,t)}some(e,t){return this.#t().some(e,t)}every(e,t){return this.#t().every(e,t)}repeatLast(e=Number.MAX_SAFE_INTEGER){return this.#t().repeatLast(e)}repeat(e,t=Number.MAX_SAFE_INTEGER){return this.#t().repeat(e,t)}join(e=""){return this.#t().join(e)}sort(e){return this.#t().sort(e)}get[Symbol.toStringTag](){try{return this.#e??(this.#e=`Async.Mixin(${e.name})`)}catch{return`Async.Mixin(${e.name}).prototype`}}}return t};class Q{#r;constructor(e,t){this.#r=e.bind(this,...t)}[Symbol.asyncIterator](){return X.enhance(x(this.#r()))}}class ee extends(J.Mixin(Q)){constructor(e,t){super(e,t)}}(Z||(Z={})).wrap=(e,...t)=>new ee(e,t);const te=Object.getPrototypeOf(async function*(){}());var re;Object.setPrototypeOf(W.prototype,(e=>{const t=Object.create(e);return(e=>{for(const r of Reflect.ownKeys(e))"constructor"!==r&&(t[r]=e[r])})(U.prototype),t})(te)),Object.defineProperty(W.prototype,"_impl",{value:X,writable:!1,enumerable:!1,configurable:!1}),function(e){e.asArray=X.asArray.bind(X),e.concat=X.concat.bind(X),e.every=X.every.bind(X),e.filter=X.filter.bind(X),e.flat=X.flat.bind(X),e.flatMap=X.flatMap.bind(X),e.forEach=X.forEach.bind(X),e.join=X.join.bind(X),e.limit=X.limit.bind(X),e.map=X.map.bind(X),e.merge=X.merge.bind(X),e.of=X.of.bind(X),e.reduce=X.reduce.bind(X),e.repeat=X.repeat.bind(X),e.repeatLast=X.repeatLast.bind(X),e.slice=X.slice.bind(X),e.some=X.some.bind(X),e.sort=X.sort.bind(X),e.zip=X.zip.bind(X),e.enhance=X.enhance.bind(X),e.Mixin=J.Mixin,e.wrap=Z.wrap}(re||(re={}));var ne=Object.freeze({__proto__:null,get Async(){return re},EnhancedAsyncGenerator:W,EnhancedGenerator:j,Future:B,get Sync(){return z},delay:(e,t)=>new Promise((r=>setTimeout((()=>r(t)),e))),doCatch:C,eventToGenerator:(e=(()=>new V))=>{let t=()=>{},r=null;const n=e(),a=e=>(n.push(e),t());return[async function*(){for(;;){for(;!n.length;)r=new Promise((e=>t=e)),await r,r=null,t=()=>{};const a=n.shift();if((e=a)instanceof Object&&"return"===e[H])return a.value;if(K(a))throw a.value;yield a}var e}(),new class{send(e){return a(e)}end(e){return a({[H]:"return",value:e})}throw(e){return a({[H]:"throw",value:e})}clear(){return n.clear()}}]},isAsyncGenable:b,isAsyncGenerator:_,isAsyncIterable:O,isAsyncIterableIterator:e=>E(e)&&O(e),isAsyncIterator:E,isGenable:g,isGenerator:v,isIterable:$,isIterableIterator:e=>N(e)&&$(e),isIterator:N,queue1:()=>{let e,t=!0;return new class{get length(){return t?0:1}push(r){return t=!1,e=r,1}shift(){t=!0;const r=e;return e=void 0,r}clear(){t=!0,e=void 0}}},queueNewest:(e=1)=>()=>{const t=new V;return new class{get length(){return t.length}push(r){for(;t.length>=e;)t.shift();return t.push(r)}shift(){return t.shift()}clear(){return t.clear()}}},queueOldest:(e=1)=>()=>{const t=new V;return new class{get length(){return t.length}push(r){return t.length<e?t.push(r):t.length}shift(){return t.shift()}clear(){return t.clear()}}},queueSticky:()=>{let e,t=!0;return new class{get length(){return t?0:1}push(r){return t=!1,e=r,1}shift(){return e}clear(){t=!0,e=void 0}}},queueUnique:e=>{const t=(e,t)=>()=>{const r=new Map;let n=null;return new class{get length(){return r.size}push(n){const a=t(n);return e?(r.delete(a),r.set(a,n)):r.has(a)||r.set(a,n),r.size}shift(){n||(n=r.values());const e=n.next();if(!e.done)return e.value;n=null}clear(){return r.clear()}}};return void 0===e?t(!1,(e=>e)):t(!!e.newest,e.keyFn||(e=>e))},queueUpdateShallow:(e={})=>()=>{const t={...e};let r={},n=!1;return new class{get length(){return n?1:0}push(e){const a=a=>Object.keys(a).forEach((a=>{t[a]!==e[a]&&(r[a]=e[a],n=!0)}));return a(t),a(e),1}shift(){try{return r}finally{Object.assign(t,r),this.clear()}}clear(){r={},n=!1}}},range:L,toAsyncGenerator:x,toAsyncIterable:A,toAsyncIterableIterator:function(e){if(O(e)&&E(e))return e;if(O(e)){let t;const r=()=>t??(t=e[Symbol.asyncIterator]()),n={[Symbol.asyncIterator]:()=>n,next:()=>r().next(),return:r().return&&(e=>r().return(e)),throw:r().throw&&(e=>r().throw(e))};return n}if($(e))return k(e);if(E(e)){const t={[Symbol.asyncIterator]:()=>t,next:t=>e.next(t),return:e.return&&(t=>e.return(t)),throw:e.throw&&(t=>e.throw(t))};return t}throw new Error(`Not iterator nor iterable: ${e}`)},toAsyncIterator:T,toGenerator:w,toIterable:I,toIterableIterator:function(e){if($(e)&&N(e))return e;if($(e)){let t;const r=()=>t??(t=e[Symbol.iterator]()),n={[Symbol.iterator]:()=>n,next:e=>r().next(e),return:r().return&&(e=>r().return(e)),throw:r().throw&&(e=>r().throw(e))};return n}if(N(e)){const t={[Symbol.iterator]:()=>t,next:t=>e.next(t),return:e.return&&(t=>e.return(t)),throw:e.throw&&(t=>e.throw(t))};return t}throw new Error(`Not iterator nor iterable: ${e}`)},toIterator:S});const ae=Symbol("MARK"),se=e=>e,ie=e=>"string"==typeof e?t=>t[e]:e,oe=e=>{const{key:t=se,value:r=se,compare:a=n,merge:s}=e,i=ie(t),o=ie(r);return e=>z.enhance(function*(){let t=ae,r=null;for(const n of e){const e=i(n),l=o(n);null===r||t===ae?(r=s(e),r.add(l)):a(t,e)?(yield*r.value(),r=s(e),r.add(l)):r.add(l),t=e}r&&(yield*r.value())}())};class le{key;constructor(e){this.key=e}}class ce extends le{constructor(e){super(e)}add(e){}value(){return[this.key]}}const ue=e=>new ce(e);class he extends le{list=[];add(e){this.list.push(e)}value(){return[this.list]}}const fe=e=>new he(e);var pe,me="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},ye={exports:{}};pe=ye,function(){var e,t,r,n,a,s,i,o,l,c,u,h,f,p,m;r=Math.floor,c=Math.min,t=function(e,t){return e<t?-1:e>t?1:0},l=function(e,n,a,s,i){var o;if(null==a&&(a=0),null==i&&(i=t),a<0)throw new Error("lo must be non-negative");for(null==s&&(s=e.length);a<s;)i(n,e[o=r((a+s)/2)])<0?s=o:a=o+1;return[].splice.apply(e,[a,a-a].concat(n)),n},s=function(e,r,n){return null==n&&(n=t),e.push(r),p(e,0,e.length-1,n)},a=function(e,r){var n,a;return null==r&&(r=t),n=e.pop(),e.length?(a=e[0],e[0]=n,m(e,0,r)):a=n,a},o=function(e,r,n){var a;return null==n&&(n=t),a=e[0],e[0]=r,m(e,0,n),a},i=function(e,r,n){var a;return null==n&&(n=t),e.length&&n(e[0],r)<0&&(r=(a=[e[0],r])[0],e[0]=a[1],m(e,0,n)),r},n=function(e,n){var a,s,i,o,l,c;for(null==n&&(n=t),l=[],s=0,i=(o=function(){c=[];for(var t=0,n=r(e.length/2);0<=n?t<n:t>n;0<=n?t++:t--)c.push(t);return c}.apply(this).reverse()).length;s<i;s++)a=o[s],l.push(m(e,a,n));return l},f=function(e,r,n){var a;if(null==n&&(n=t),-1!==(a=e.indexOf(r)))return p(e,0,a,n),m(e,a,n)},u=function(e,r,a){var s,o,l,c,u;if(null==a&&(a=t),!(o=e.slice(0,r)).length)return o;for(n(o,a),l=0,c=(u=e.slice(r)).length;l<c;l++)s=u[l],i(o,s,a);return o.sort(a).reverse()},h=function(e,r,s){var i,o,u,h,f,p,m,y,d;if(null==s&&(s=t),10*r<=e.length){if(!(u=e.slice(0,r).sort(s)).length)return u;for(o=u[u.length-1],h=0,p=(m=e.slice(r)).length;h<p;h++)s(i=m[h],o)<0&&(l(u,i,0,null,s),u.pop(),o=u[u.length-1]);return u}for(n(e,s),d=[],f=0,y=c(r,e.length);0<=y?f<y:f>y;0<=y?++f:--f)d.push(a(e,s));return d},p=function(e,r,n,a){var s,i,o;for(null==a&&(a=t),s=e[n];n>r&&a(s,i=e[o=n-1>>1])<0;)e[n]=i,n=o;return e[n]=s},m=function(e,r,n){var a,s,i,o,l;for(null==n&&(n=t),s=e.length,l=r,i=e[r],a=2*r+1;a<s;)(o=a+1)<s&&!(n(e[a],e[o])<0)&&(a=o),e[r]=e[a],a=2*(r=a)+1;return e[r]=i,p(e,l,r,n)},e=function(){function e(e){this.cmp=null!=e?e:t,this.nodes=[]}return e.push=s,e.pop=a,e.replace=o,e.pushpop=i,e.heapify=n,e.updateItem=f,e.nlargest=u,e.nsmallest=h,e.prototype.push=function(e){return s(this.nodes,e,this.cmp)},e.prototype.pop=function(){return a(this.nodes,this.cmp)},e.prototype.peek=function(){return this.nodes[0]},e.prototype.contains=function(e){return-1!==this.nodes.indexOf(e)},e.prototype.replace=function(e){return o(this.nodes,e,this.cmp)},e.prototype.pushpop=function(e){return i(this.nodes,e,this.cmp)},e.prototype.heapify=function(){return n(this.nodes,this.cmp)},e.prototype.updateItem=function(e){return f(this.nodes,e,this.cmp)},e.prototype.clear=function(){return this.nodes=[]},e.prototype.empty=function(){return 0===this.nodes.length},e.prototype.size=function(){return this.nodes.length},e.prototype.clone=function(){var t;return(t=new e).nodes=this.nodes.slice(0),t},e.prototype.toArray=function(){return this.nodes.slice(0)},e.prototype.insert=e.prototype.push,e.prototype.top=e.prototype.peek,e.prototype.front=e.prototype.peek,e.prototype.has=e.prototype.contains,e.prototype.copy=e.prototype.clone,e}(),pe.exports=e}.call(me);var de=ye.exports;const ge=de,be=e=>{if(e instanceof Error)throw e;throw new Error(e)},ve=e=>be(e?`Not yet implemented: ${e}`:"Not yet implemented."),_e=e=>z.enhance(function*(e){for(;e.size()>0;)yield e.pop()}(e)),we=e=>e.reduce(((e,t)=>(e[t.name]=t,e)),{}),xe=(e,t=2)=>e.toLocaleString("en",{minimumFractionDigits:t,maximumFractionDigits:t,currency:"USD",style:"currency"}),Se=(e,t=3)=>`${(100*e).toLocaleString("en",{minimumFractionDigits:t,maximumFractionDigits:t})}%`,Te=(e,t=`Unexpected ${e}`)=>be(t),Me=(e,t)=>e.type===t,Ie=(e,t)=>Me(e,t)?e:be(`Row not of type ${t}.`),Ae=e=>{if(e instanceof Object)for(const t of Object.values(e)){try{Object.freeze(e)}catch{}Ae(t)}return e},ke=e=>[...e.reduce(((e,t)=>(e.add(t),e)),new Set).keys()],Ne=(e,t)=>t?r=>t(r.reduce(((t,r)=>t+e(r)),0)):t=>t.reduce(((t,r)=>t+e(r)),0),Ee=e=>e.value,$e=Ne(Ee),Oe=(e,t)=>{const r=t=>t instanceof e?t:be(`${t} is not an instance of ${t.name}`),n=t?n=>n instanceof e?n:r(t(n)):r;return[t=>t instanceof e,n,r]},Ce=(e,t,r)=>{const n=r=>e(r)?r:be(`${r} is not ${t}`),a=r?t=>e(t)?t:n(r(t)):n;return[a,n]},Ue=e=>"function"==typeof e,je=e=>e,Fe=e=>"number"==typeof e.value,[Pe,De]=Ce(Fe,"a monetary item"),Re=e=>"object"==typeof e,[Ye,qe]=Ce(Re,"an object"),ze=e=>!0===e||!1===e,[Le,Ge]=Ce(ze,"true or false",(e=>!/^\s*(?:false|f)\s*$/i.test(e)&&(!!/^\s*(?:true|t)\s*$/i.test(e)||void 0)));function Ve(e,t){return t?`${e}/${t}`:t=>`${e}/${t}`}const He=e=>Object.entries(e),Ke=e=>Object.keys(e),Be=e=>Object.values(e);var We;!function(e){e[e.END_ON_FIRST=0]="END_ON_FIRST",e[e.END_ON_LAST=1]="END_ON_LAST",e[e.ERROR=2]="ERROR"}(We||(We={}));class Xe extends le{#l;#c;#u;#h;#f;constructor(e,t,r,n,a,s){super(e),this.#c=t;const i={};for(const n of t)i[n]=r[n](e);this.#l=i,this.#u=n,this.#f=a,this.#h=s}add(e){for(const t of this.#c){const r=this.#l[t],n=(0,this.#u[t])(e);r.add(n)}}value(){const e={};for(const t of this.#c){const r=this.#l[t];e[t]=r.value()[Symbol.iterator]()}const t=this.#c,r=this.#h,n=this.#f;return function*(){let a=!0,s=!1;for(;a;){a=!1;let i=n?[]:{};for(const n of t){const t=e[n]?.next();if(t)if(t.done){if(delete e[n],r===We.END_ON_FIRST)return;s=!0}else a=!0,i[n]=t.value}if(a){if(s&&r===We.ERROR)throw new Error("Unmatched result lengths in object aggregation merge");yield i}}}()}}const Je=(e,t=We.ERROR)=>{const r={},n={},a=Ke(e);for(const t of a){const a=e[t];if(Array.isArray(a)){const[e,s]=a;r[t]=s,n[t]=ie(e)}else r[t]=a,n[t]=ie(t)}const s=Array.isArray(e);return e=>new Xe(e,a,r,n,s,t)};class Ze extends le{#p=0;constructor(e){super(e),this.#p}add(e){null!=e&&(this.#p+=e)}value(){return[this.#p]}}const Qe=e=>new Ze(e),et=(e,t,r)=>{const a=ie(e);return({pre:e,post:s,cmp:i=n}={})=>n=>z.enhance(function*(){let o,l={},c={},u=e;for(const e of n){const n=a(e),s=e[t];if(void 0===u||0!==i(s,u)){for(const e in c)yield c[e];l=c,o=u,c={},u=s}void 0!==o&&void 0===l[n]&&(yield{...e,[t]:o,[r]:0}),c[n]=e}for(const e in c)yield c[e];if(void 0!==s)for(const e in c){const n=c[e];yield{...n,[t]:s,[r]:0}}}())};class tt extends le{#m;#y;#d;constructor(e,t,r,n){super(e),this.#m=t,this.#y=r,this.#d=n??ie(r)}add(e){this.#m(e),this.#d(e)}value(){return[]}}const rt=(e,t,r)=>n=>new tt(n,e,t,r);var nt;!function(e){e.year="year",e.semiannually="semiannually",e.quarter="quarter",e.month="month",e.semimonthly="semimonthly",e.biweekly="biweekly",e.week="week",e.day="day"}(nt||(nt={}));const at=e=>"number"==typeof e&&!isNaN(e)&&isFinite(e),st=e=>{if(at(e))return e;const t=Number(e);if(at(t))return t;throw new Error(`${e} is not a valid number.`)},it=(e,t)=>{const r=(({min:e,max:t,mod:r,minEx:n,maxEx:a})=>{const s=0|(void 0!==e?1:0)|(void 0!==t?2:0)|(n?4:0)|(a?8:0)|(void 0!==r?16:0);switch(s){case 0:case 4:case 8:case 12:return at;case 1:case 9:return t=>at(t)&&t>=e;case 2:case 6:return e=>at(e)&&e<=t;case 3:return r=>at(r)&&r>=e&&r<=t;case 5:case 13:return t=>at(t)&&t>e;case 10:case 14:return e=>at(e)&&e<t;case 7:return r=>at(r)&&r>e&&r<=t;case 11:return r=>at(r)&&r>=e&&r<t;case 15:return r=>at(r)&&r>e&&r<t;case 16:case 20:case 24:case 28:return e=>at(e)&&e/r%1==0;case 17:case 25:return t=>at(t)&&t>=e&&t/r%1==0;case 18:case 22:return e=>at(e)&&e<=t&&e/r%1==0;case 19:return n=>at(n)&&n>=e&&n<=t&&n/r%1==0;case 21:case 29:return t=>at(t)&&t>e&&t/r%1==0;case 26:case 30:return e=>at(e)&&e<t&&e/r%1==0;case 23:return n=>at(n)&&n>e&&n<=t&&n/r%1==0;case 27:return n=>at(n)&&n>=e&&n<t&&n/r%1==0;case 31:return n=>at(n)&&n>e&&n<t&&n/r%1==0;default:throw new Error(`Impossible ${s}`)}})(t),n=t=>r(t)?t:be(`${t} is not a valid ${e}.`);return{is:r,as:n,to:e=>at(e)?n(e):n(Number(e))}},{is:ot,as:lt,to:ct}=it("Integer",{mod:1}),ut=Math.floor,ht=Math.ceil,ft=Math.round,pt=Math.max,mt=Math.min,yt=e=>t=>ft(t/e)*e,dt=Math.trunc,gt=(e,t)=>dt(e%t),bt=(e,t)=>dt(e/t),vt=e=>lt(e+1),_t=e=>lt(e-1),wt=(()=>{let e;return(...t)=>(e||(e=Ne(lt,lt)),e(t))})(),xt=e=>"string"==typeof e,St=e=>{if(xt(e))return e;if(at(e))return String(e);throw new Error(`${e} is not a valid string.`)},{is:Tt,as:Mt,to:It}=it("Degrees",{min:0,max:360,maxEx:!0}),At=e=>{if("number"!=typeof e||isNaN(e)||!isFinite(e))throw`${e} is not a valid number of degrees.`;const t=e%360;return t<0?t+360:t},{is:kt,as:Nt,to:Et}=it("Unit",{min:0,max:1}),{is:$t,as:Ot,to:Ct}=it("Probability",{min:0,max:1}),{is:Ut,as:jt,to:Ft}=it("Integer",{mod:1}),{is:Pt,as:Dt,to:Rt}=it("Byte",{min:0,max:255,mod:1}),{is:Yt,as:qt,to:zt}=it("Money",{}),Lt=yt(.01),Gt=e=>qt(Lt(qt(e))),Vt=(...e)=>Gt(pt(...e)),Ht=(...e)=>Gt(mt(...e)),Kt=Gt(0),{is:Bt,as:Wt,to:Xt}=it("Rate",{min:-2,max:2,minEx:!0}),{is:Jt,as:Zt,to:Qt}=it("TaxRate",{min:0,max:1}),{is:er,as:tr,to:rr}=it("Year",{min:1900,max:2300,mod:1}),{is:nr,as:ar,to:sr}=it("Age",{min:0,max:130}),{is:ir,as:or,to:lr}=it("IAge",{min:0,max:130,mod:1}),cr=e=>t=>void 0===t||e(t),ur=e=>t=>void 0===t||e(t),hr=e=>t=>void 0===t?void 0:e(t),fr=e=>e,pr={year:1,semiannually:2,quarter:4,month:12,semimonthly:24,biweekly:365.25/14,week:365.25/7,day:365.25};function mr(e,t=0,r=1){return xt(e)?Lr(e):new Date(Date.UTC(Ft(e),Ft(t),Ft(r),0,0,0,0))}const yr=[[0,31,59,90,120,151,181,212,243,273,304,334,365],[0,31,60,91,121,152,182,213,244,274,305,335,366]],dr=[[31,28,31,30,31,30,31,31,30,31,30,31],[31,29,31,30,31,30,31,31,30,31,30,31]],gr=e=>e in nt,[br,vr]=Ce(gr,"a calendar unit"),_r=e=>{if(e instanceof Object){const t=Object.keys(e);switch(t.length){case 0:default:return!1;case 1:return gr(t[0])&&Ut(e[t[0]]);case 2:return gr(t[0])&&Ut(e[t[0]])&&"totalDays"===t[1]&&Ut(e.totalDays)||gr(t[1])&&Ut(e[t[1]])&&"totalDays"===t[0]&&Ut(e.totalDays)}}return!1},[wr,xr]=Ce(_r,"a CalendarInterval"),Sr=e=>e.year?[nt.year,e.year]:e.semiannually?[nt.semiannually,e.semiannually]:e.quarter?[nt.quarter,e.quarter]:e.month?[nt.month,e.month]:e.semimonthly?[nt.semimonthly,e.semimonthly]:e.biweekly?[nt.biweekly,e.biweekly]:e.week?[nt.week,e.week]:e.day?[nt.day,e.day]:be(`${JSON.stringify(e)} is not a CalendarInterval`),Tr=e=>{if("object"==typeof e&&Dr(e.date)&&Ut(e.totalDays))for(const t in nt)if(Ut(e[t]))return!0;return!1},[Mr,Ir]=Ce(Tr,"a valid CalendarLength");function Ar(e,t,r=1){if(_r(t)){const[r,n]=Sr(t);return Ar(e,r,n)}const n=t,a=Yr(e),s=a.getUTCFullYear(),i=a.getUTCMonth(),o=a.getUTCDate(),l=jt(r),[c,u,h]=(()=>{const e=e=>{const t=i+e;return[ut(t/12),t%12-i,0]};switch(n){case nt.year:return[l,0,0];case nt.semiannually:return e(6*l);case nt.quarter:return e(3*l);case nt.month:return e(l);case nt.semimonthly:return(e=>{const t=i+ut(e/2);return[ut(t/12),(o>=15&&1&e?t%12+1:t%12)-i,o>=15?1&e?1-o:0:1&e?14:0]})(l);case nt.biweekly:return[0,0,14*l];case nt.week:return[0,0,7*l];case nt.day:return[0,0,l]}throw new Error(`Unknown TimeInterval: ${n}`)})(),f=mr(s+c,i+u,o);return h?new Date(f.getTime()+24*h*60*60*1e3):f}const kr=e=>String(e).padStart(2,"0"),Nr=e=>Dr(e)?e.getUTCFullYear()-2e3+"}":$r(Yr(e)),Er=e=>Dr(e)?`'${e.getUTCFullYear()-2e3}}`:$r(Yr(e)),$r=e=>Dr(e)?`${e.getUTCFullYear()}}`:$r(Yr(e)),Or=e=>Dr(e)?`${e.getUTCFullYear()}-${kr(e.getUTCMonth()+1)}`:Or(Yr(e)),Cr=e=>Dr(e)?`${e.getUTCFullYear()}-${kr(e.getUTCMonth()+1)}-${kr(e.getUTCDate())}`:Cr(Yr(e)),Ur=e=>Dr(e)?`${kr(e.getUTCHours())}:${kr(e.getUTCMinutes()+1)}:${kr(e.getUTCSeconds())}`:Ur(Yr(e)),jr=e=>Dr(e)?`${Cr(e)} ${Ur(e)}`:jr(Yr(e));function Fr(e){if(e instanceof Date)return Fr(e.getUTCFullYear());const t=tr(e);return t%4==0&&(t%100!=0||t%400==0)}const Pr=e=>{switch(e){case nt.year:return e=>mr(e.getUTCFullYear());case nt.quarter:return e=>mr(e.getUTCFullYear(),3*ut(e.getUTCMonth()/3));case nt.month:return e=>mr(e.getUTCFullYear(),e.getUTCMonth());case nt.week:throw new Error("'week' is not a meaningful unit to truncate a date to.");case nt.day:return e=>mr(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}throw new Error(`Unknown TimeInterval: ${e}`)},Dr=e=>e instanceof Date&&!isNaN(e.valueOf())&&0===e.getUTCHours()&&0===e.getUTCMinutes()&&0===e.getUTCSeconds()&&0===e.getUTCMilliseconds(),Rr=Pr(nt.day),[Yr,qr]=Ce(Dr,"is not a UTC Date",(e=>e instanceof Date?Rr(e):mr(e))),zr=Pr(nt.day),Lr=e=>{const t=/^\s*(\d{4})(?:-(\d{1,2})(?:-(\d{1,2}))?)?\s*$/.exec(e);if(!t)throw new Error(`${e} is not a valid date. Must be in the form YYYY-01-23. Month and day are optional, default to 01.`);return mr(Number(t[1]),Number(t[2]??1)-1,Number(t[3]??1))};class Gr{start;end;constructor(e,t,r){if(this.start=Yr(e),gr(t))this.end=Ar(this.start,t,r??1);else if(_r(t)){const[e,r]=Sr(t);this.end=Ar(this.start,e,r)}else this.end=Yr(t)}get length(){const e=this.end.getUTCFullYear()-this.start.getUTCFullYear(),t=this.end.getUTCMonth()-this.start.getUTCMonth(),r=this.end.getUTCDate()-this.start.getUTCDate(),n=Fr(this.end),[a,s]=r<0?[t-1,r+dr[n?1:0][this.end.getUTCMonth()]]:[t,r],[i,o]=a<0?[e-1,a+12]:[e,a],l=ut(r/7),c=s-7*l;return{...i&&{year:i},...o&&{month:o},...l&&{week:l},...c&&{day:c},totalDays:ut((this.end.getTime()-this.start.getTime())/864e5)}}range(e,t=1){return Gr.calendarRange(this.start,this.end,e,void 0===t?void 0:jt(t))}toString(){return`${Cr(this.start)} to ${Cr(this.end)}`}static calendarRange}const[Vr,Hr,Kr]=Oe(Gr,(e=>"object"==typeof e&&e.start&&e.end?new Gr(e.start,e.end):void 0));class Br extends Gr{step;constructor(e,t,r=0){super(e,t),this.step=r}}const[Wr,Xr,Jr]=Oe(Br);class Zr extends Gr{interval;unit;n;constructor(e,t,r,n){super(e,t),this.interval={[r]:n??1},this.unit=r,this.n=n??1}[Symbol.iterator](){const e=this;return z.enhance(function*(){let t=e.start,r=0;for(;t<e.end;){const n=Ar(t,e.unit,e.n);yield new Br(t,n,r),t=n,r++}}())}}class Qr extends(z.Mixin(Zr)){constructor(e,t,r,n){super(Yr(e),Yr(t),Qr.#g(r),Qr.#b(r,n))}static#g(e){if(gr(e))return e;const[t,r]=Sr(xr(e));return t}static#b(e,t){if(gr(e))return jt(t??1);{const[t,r]=Sr(xr(e));return r}}}function en(e,t,r,n){return new Qr(e,t,r,void 0===n?void 0:jt(n))}const tn=e=>(e.valueOf()-rn(e).valueOf())/864e5,rn=e=>fn[e.getUTCFullYear()]??mr(e.getUTCFullYear()),nn=e=>Fr(e)?366:365,an=e=>{const t=e.getUTCMonth(),r=e.getUTCDate();return yr[Fr(e.getUTCFullYear())?1:0][t]+r},sn=(e,t)=>{const r=tn(e),n=tn(t);Fr(e.getUTCFullYear()),Fr(t.getUTCFullYear());const a=t.getUTCFullYear(),s=a-e.getUTCFullYear(),i=nn(r<60?a-1:a);return ar(s+(n-r)/i)},on=zr(new Date),ln=tr(on.getUTCFullYear());let cn=tr(ln+50);const un=mr(ln+100),hn=tr(un.getUTCFullYear()+1),fn=L(ln,hn).map((e=>mr(e))).asArray(),pn=rn(on),mn=new Date;let yn=1===mn.getUTCDate()?mr(mn.getUTCFullYear(),mn.getUTCMonth()):mn.getUTCMonth()<=11?mr(mn.getUTCFullYear(),mn.getUTCMonth()+1):mr(mn.getUTCFullYear()+1,0),dn=mr(yn.getUTCFullYear()+50,yn.getUTCMonth());class gn{id;prettyName;start;end;scenario;categories;scenarios;name;type;notes;#e;sort;#v=void 0;constructor(e,t){this.type=e.type,this.name=e.name,this.id=`${this.type}/${this.name}`,this.prettyName=e.prettyName??e.name,this.scenario=t??this,this.start=e.start??t?.start??yn,this.end=e.end,this.categories=e.categories??[],this.scenarios=e.scenarios?.length?e.scenarios:["Default"],this.notes=e.notes,this.sort=Number(e.sort||0)}set temporal(e){if(this.#v)throw new Error("Cannot reset .temporal");this.#v=e}get temporal(){return this.#v??be(".temporal has not been set.")}get[Symbol.toStringTag](){try{return this.#e??(this.#e=`${this.type}[${this.name}]`)}catch{return`${this.constructor.name}.prototype`}}hasCategory(e){return!!this.categories.find((t=>t===e))}inScenario(e){return!!this.scenarios.find((t=>t===e))}static inScenario(e,t){return Array.isArray(t)?!!t.find((t=>t===e)):this.inScenario(e,t.scenarios)}}class bn extends gn{value;constructor(e,t){super(e,t),this.value=e.value}}function vn(e){class t extends e{state;scenario;item;#e=void 0;constructor(e,t,r){super(e,t,r),this.item=e,this.scenario=t,this.state=r}get[Symbol.toStringTag](){try{return this.#e??(this.#e=`${this.type}State[${this.name} #${this.state?.step?.step??"??"}]`)}catch{return`${this.type}State.prototype`}}}return t}const _n=()=>{};function wn(e,t,r){return z.enhance(function*(){const n=e=>Math.round(100*e)/100,a=(t-1)/12;let s=0,i=0,o=0,l=e;for(;0!==l;){const e=n(l*a),t=l+e;if(o+=e,void 0===r)return l=n(t),{value:l,interest:o};{const a=Math.min(t,Math.max(0,r-e)),o=Math.min(r,t);l=n(t-a),i+=a,s+=o,yield{value:l,interest:e,principal:a,payment:o}}}return{value:l,principal:i,interest:o,payments:s}}())}const xn=(e,t,r)=>gr(t)?xn(e,pr[t],r):gr(r)?xn(e,t,pr[r]):r*Sn(e,t,r),Sn=(e,t,r)=>gr(t)?Sn(e,pr[t],r):gr(r)?Sn(e,t,pr[r]):Math.pow(1+e/t,t/r)-1,Tn=(e,t,r)=>gr(t)?Tn(e,pr[t],r):gr(r)?Tn(e,t,pr[r]):Gt(e*t/r);class Mn extends bn{rate;rateType;paymentPeriod;constructor(e,t){super(e,t),this.rate=e.rate??0,this.rateType=e.rateType||nt.year,this.paymentPeriod=e.paymentPeriod||nt.year}*stepper(e,t){let r=this.value,n=e.start,a=Sn(this.rate,vr(this.rateType),nt.month),s=Kt;for(;;){this.start,t.addTimeLine("interest",n,this,{amount:s,balance:r});const e=yield{value:r,interest:s,rate:a};a=e.rate,s=Gt(a*r),r=Gt(e.value+s),n=e.date}}}class In extends(vn(Mn)){constructor(e,t,r){super(e,t,r)}}const[An,kn,Nn]=Oe(Mn);class En extends bn{paymentPeriod;constructor(e,t){super(e,t);const r=this.end||"incomeStream"===this.type||"incomeTax"===this.type;this.paymentPeriod=e.paymentPeriod??(r?nt.month:be(`Missing payment period in ${this.id}`))}}class $n extends En{fromStream;constructor(e,t){super(e,t),this.fromStream=e.fromStream??be(`fromStream must be specified for ${this.name}.`)}*stepper(e,t){let r=Tn(this.value,this.paymentPeriod,nt.month),n=e.start,a=Kt;for(;;){a=Gt(a+(n>=this.start?r:Kt));const e=a;t.addTimeLine("pay",n,this,{amount:e,balance:a});const s=yield{value:a,payment:e};a=s.value,n=s.date}}}class On extends(vn($n)){constructor(e,t,r){super(e,t,r)}}const[Cn,Un,jn]=Oe($n);class Fn extends En{constructor(e,t){super(e,t)}*stepper(e,t){let r=this.value,n=e.start;for(;;){const e=n>=this.start?r:Kt,a=e;t.addTimeLine("receive",n,this,{amount:a,balance:r});const s=yield{value:e,payment:a};r=Gt(this.value+s.value),n=s.date}}}class Pn extends(vn(Fn)){constructor(e,t,r){super(e,t,r)}}const[Dn,Rn,Yn]=Oe(Fn),qn=(e,t)=>{for(const[r,n]of He(t))e[r]=Gt((e[r]??Kt)+(n??Kt))};class zn extends En{#_;#w;constructor(e,t){super(e,t),this.#_=zn.parse(e.spec)}static parse(e,t){if("string"==typeof e){const r=e.replace(/[“”]/g,'"');if(/^["\[{]/.test(r))try{return JSON.parse(r)}catch(e){throw new Error(`Error parsing incomeStream ${t??"unknown"}: ${e.message}`)}}return e}get spec(){return this.#w??(this.#w=this.bind(this.#_))}bind(e){const t=e=>e.startsWith("@")?this.scenario.incomeStreams[e.substring(1)].id??be(`There is no IncomeStream named ${e.substring(1)}`):(this.scenario.incomes[e]??this.scenario.assets[e]??this.scenario.liabilities[e])?.id??be(`There is no income, asset, or liability named "${e}"`);if(xt(e)){if(e.startsWith("@")){const t=e.substring(1);return this.scenario.incomeStreams[t].id}return t(e)}if(Array.isArray(e))return e.map((e=>this.bind(e)));if("object"==typeof e){const r={};let n=0;for(const t in e)n+=e[t];for(const a in e){r[t(a)]={weight:e[a]/n}}return r}throw new Error(`Unknown income stream spec: ${e}`)}withdraw(e,t,r){const n={},a=(e,s)=>{if(xt(s)){const a=r[s]?.current;if(a){if(Hn(a.item)){const{amount:s,sources:i}=a.item.withdraw(e,t,r);return qn(n,i),s}if(Gn(a)){const t=a.item,r=Ht(e,a.value);return a.used=Gt((a.used??Kt)+r),"liability"===t.type?a.value=Gt(a.value+r):a.value=Gt(a.value-r),((e,t)=>{n[e]=Gt((n[e]??Kt)+t)})(t.id,r),r}throw new Error(`${s} is not a valid source of income.`)}return console.log(`The income source ${s} is not available at ${r.date}.`),Kt}if(Array.isArray(s)){let t=0;for(const r of s)if(t+=a(Vt(e-t,Kt),r),t>=e)break;return Gt(t)}if("object"==typeof s){const t=s;let r=0;for(const n in s)r+=a(Gt(e*t[n].weight),n);return Gt(r)}throw new Error(`Unknown spec: ${s}`)};return{id:t,amount:a(e,this.spec),sources:n}}*stepper(e,t){for(;;)yield{}}}const Ln=e=>e.item&&Fe(e),Gn=e=>e.item&&("asset"===e.item.type||"liability"===e.item.type||"income"===e.item.type);class Vn extends(vn(zn)){constructor(e,t,r){super(e,t,r)}parse(e){return e}}const[Hn,Kn,Bn]=Oe(zn);class Wn extends En{state;constructor(e,t){super(e,t),this.state=e.state}*stepper(e,t){for(;;)yield{}}}class Xn extends(vn(Wn)){constructor(e,t,r){super(e,t,r)}}const[Jn,Zn,Qn]=Oe(Wn);class ea extends bn{rate;rateType;payment;paymentPeriod;expense;constructor(e,t){super(e,t),this.rate=e.rate??0,this.rateType=e.rateType||nt.year,this.payment=e.payment??Kt,this.paymentPeriod=e.paymentPeriod??nt.month}*stepper(e,t){let r=this.value,n=e.start,a=Sn(this.rate,vr(this.rateType),nt.month);for(;;){if(r<=0)return;const e=Ht(r,this.payment??Kt);t.addTimeLine("pay",n,this,{amount:e,balance:r});const s=Gt(a*r),i=Gt(e-s),o=n>=this.start?r:Kt;t.addTimeLine("interest",n,this,{amount:s,balance:o});const l=yield{value:o,interest:s,principal:i,payment:e,rate:a};r=Gt(l.value-i),n=l.date}}}class ta extends(vn(ea)){constructor(e,t,r){super(e,t,r)}}const[ra,na,aa]=Oe(ea);class sa extends gn{text;constructor(e,t){super(e,t),this.text=e.text}*stepper(e,t){let r=e.start;for(;;){let e=r>=this.start?this.text:"";r=(yield{text:e}).date}}}class ia extends(vn(sa)){constructor(e,t,r){super(e,t,r)}}const[oa,la,ca]=Oe(sa);const ua=[{age:0,male:{p:.006304,n:1e5,years:75.97},female:{p:.005229,n:1e5,years:80.96}},{age:1,male:{p:426e-6,n:99370,years:75.45},female:{p:342e-6,n:99477,years:80.39}},{age:2,male:{p:29e-5,n:99327,years:74.48},female:{p:209e-6,n:99443,years:79.42}},{age:3,male:{p:229e-6,n:99298,years:73.5},female:{p:162e-6,n:99422,years:78.43}},{age:4,male:{p:162e-6,n:99276,years:72.52},female:{p:143e-6,n:99406,years:77.45