UNPKG

@cmtlyt/base

Version:
2 lines (1 loc) 3.48 kB
import{c as b,i as R,w as g,g as M,I as f,a as x}from"./base.CBZTi4S8.mjs";import"ms";const w=new WeakMap;function c(e){return w.get(e)}function u(e,t){const s=c(e);w.set(e,{...s,...t})}class l{constructor(t){u(this,{value:t})}valueOf(){return c(this).value}inspect(){return`${this.name} { ${this.valueOf()} }`}join=this.valueOf}let B=class extends l{name="Container";map(t){return p(t(this.valueOf()))}flatMap(t){return p(t(this.valueOf()).valueOf())}};function p(e){return new B(e)}class D extends l{name="Right";map(t){return v(t(this.valueOf()))}flatMap(t){return v(t(this.valueOf()).valueOf())}}function v(e){return new D(e)}let F=class extends l{name="Left";map(t){return this}flatMap(t){return this}};function O(e){return new F(e)}class I extends l{name="Either";map(t){try{return d(t(this.valueOf()))}catch(s){return O(s)}}flatMap(t){try{return d(t(this.valueOf()).valueOf())}catch(s){return O(s)}}}function d(e){return new I(e)}class N extends l{name="IO";map(t){return m((...s)=>t(this.valueOf()(...s)))}flatMap(t){return m((...s)=>t(this.valueOf()(...s)).valueOf())}run(...t){return this.valueOf()(...t)}}function m(e){return new N(e)}class P extends l{name="Maybe";isNothing(){return typeof this.valueOf()>"u"||this.valueOf()===null}map(t){return this.isNothing()?h(null):h(t(this.valueOf()))}flatMap(t){return this.isNothing()?h(null):h(t(this.valueOf()).valueOf())}}function h(e){return new P(e)}function E(e){return(e||!1)&&typeof e.then=="function"}const _=b(()=>R()?(g("iframe \u4E2D\u65E0\u6CD5\u6B63\u786E\u5224\u65AD!!!"),!1):File?File.prototype?e=>Object.prototype.isPrototypeOf.call(File.prototype,e):e=>e instanceof File:!1),k=b(()=>R()?(g("iframe \u4E2D\u65E0\u6CD5\u6B63\u786E\u5224\u65AD!!!"),!1):Blob?Blob.prototype?e=>Object.prototype.isPrototypeOf.call(Blob.prototype,e):e=>e instanceof Blob:!1);function T(e){return typeof e=="object"&&e!==null}function $(e){return M(e)==="object"}class A extends l{name="Task";constructor(t){super(t),u(this,{value:t})}async#t(t,s,n){const a=n===f?s:n;try{const r=t(a);E(r)?r.then(s.resolve,s.reject):n!==f&&s.resolve(r)}catch(r){s.reject(r)}}map(t){return j(s=>{const n=this.valueOf(),a={reject:s.reject,resolve:r=>{this.#t(t,s,r)}};this.#t(n,a,f)})}flatMap(t){return this.map(s=>t(s).valueOf())}then(t,s){const{promise:n,resolve:a,reject:r}=x(),y={onResolved:i=>{try{a(t?t(i):i)}catch(o){r(o)}},onRejected:i=>{try{s?a(s(i)):r(i)}catch(o){r(o)}}};return this.listen(y).run(),n}catch(t){return this.then(void 0,t)}#e(){return{resolve:t=>{u(this,{result:t,status:"finished"}),this.#n()},reject:t=>{u(this,{error:t,status:"finished"}),this.#s()}}}run(){const{status:t}=c(this);if(t)return this;u(this,{status:"running"});const s=this.#e();return this.#t(this.valueOf(),s,f),this}#s(){const{listen:t,error:s}=c(this);t&&(s&&t.onRejecteds.forEach(n=>n(s)),u(this,{listen:void 0,error:void 0}))}#n(){const{listen:t,result:s}=c(this);t&&(s&&t.onResolveds.forEach(n=>n(s)),u(this,{listen:void 0}))}listen(t){const s=c(this);let{listen:n,result:a,error:r,status:y}=s;const{onRejected:i,onResolved:o}=t;if(y==="finished"){if(r){if(!i)throw r;i(r),u(this,{error:void 0})}return a&&o&&o(a),this}return n||(n={onResolveds:[],onRejecteds:[]}),o&&n.onResolveds.push(o),i&&n.onRejecteds.push(i),u(this,{listen:n}),this}}function j(e){return new A(e)}const C={__proto__:null,container:p,either:d,io:m,left:O,maybe:h,right:v,task:j};export{E as a,_ as b,k as c,T as d,$ as e,p as f,d as g,m as h,C as i,O as l,h as m,v as r,j as t};