UNPKG

@dark-engine/core

Version:

The lightweight and powerful UI rendering engine without dependencies and written in TypeScript (Browser, Node.js, Android, iOS, Windows, Linux, macOS)

2 lines 31.5 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("DarkCore",[],e):"object"==typeof exports?exports.DarkCore=e():t.DarkCore=e()}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var n in s)t.o(s,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:s[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{$$scope:()=>Jt,ATTR_BLACK_LIST:()=>_,CLEANUP_HOST_MASK:()=>p,CREATE_EFFECT_TAG:()=>c,Comment:()=>It,CommentVirtualNode:()=>gt,Component:()=>C,DELETE_EFFECT_TAG:()=>h,EFFECT_HOST_MASK:()=>f,ErrorBoundary:()=>ps,EventEmitter:()=>Vt,FLUSH_MASK:()=>g,Fiber:()=>Ee,Fragment:()=>xe,Guard:()=>as,HOOK_DELIMETER:()=>v,Hook:()=>Te,INDEX_KEY:()=>o,IS_BOUNDARY_HOOK_MASK:()=>E,IS_PENDING_HOOK_MASK:()=>T,IS_PORTAL_HOOK_MASK:()=>I,IS_SUSPENSE_HOOK_MASK:()=>y,IS_WIP_HOOK_MASK:()=>k,KEY_ATTR:()=>a,LIB:()=>n,MOVE_MASK:()=>m,NodeType:()=>At,REF_ATTR:()=>l,REJECTED_STATUS:()=>w,REPLACER:()=>i,ROOT:()=>r,SKIP_EFFECT_TAG:()=>d,STATE_SCRIPT_TYPE:()=>b,Suspense:()=>cs,TagVirtualNode:()=>ft,TaskPriority:()=>O,Text:()=>kt,TextVirtualNode:()=>pt,UPDATE_EFFECT_TAG:()=>u,VERSION:()=>s,View:()=>mt,VirtualNode:()=>dt,YIELD_INTERVAL:()=>S,__useCursor:()=>ue,__useInBoundary:()=>fe,__useInSuspense:()=>de,__useLoc:()=>pe,__useSSR:()=>he,applyRef:()=>is,batch:()=>ws,collectElements:()=>Lt,component:()=>x,createContext:()=>Ze,createError:()=>ot,createHookLoc:()=>Bt,createIndexKey:()=>rt,createLoc:()=>Wt,createReplacer:()=>yt,createUpdate:()=>ze,detectAreDepsDifferent:()=>st,detectAreSameComponentTypesWithSameKeys:()=>Mt,detectAreSameInstanceTypes:()=>xt,detectIsArray:()=>B,detectIsBoolean:()=>H,detectIsBusy:()=>Xe,detectIsCommentVirtualNode:()=>vt,detectIsComponent:()=>M,detectIsEmpty:()=>F,detectIsEqual:()=>j,detectIsFalsy:()=>K,detectIsFiberAlive:()=>Pt,detectIsFunction:()=>N,detectIsHydration:()=>se,detectIsMutableRef:()=>rs,detectIsNull:()=>W,detectIsNumber:()=>R,detectIsObject:()=>U,detectIsPlainVirtualNode:()=>wt,detectIsPromise:()=>V,detectIsSSR:()=>ne,detectIsServer:()=>ee,detectIsString:()=>P,detectIsTagVirtualNode:()=>Tt,detectIsTextBased:()=>D,detectIsTextVirtualNode:()=>St,detectIsUndefined:()=>L,detectIsVirtualNode:()=>Et,detectIsVirtualNodeFactory:()=>bt,dummyFn:()=>q,falseFn:()=>Q,flatten:()=>et,formatErrorMsg:()=>J,getComponentKey:()=>A,getElementKey:()=>_t,getElementType:()=>Ot,getFiberWithElement:()=>Rt,getHook:()=>ve,getRootId:()=>qt,getTime:()=>G,hasChildrenProp:()=>Ct,hasKeys:()=>$,hot:()=>Os,illegal:()=>tt,keys:()=>Y,lazy:()=>ns,logError:()=>X,mapRecord:()=>it,memo:()=>oe,nextTick:()=>nt,notifyParents:()=>Ft,platform:()=>te,removeScope:()=>Qt,replaceScope:()=>Xt,resolveBoundary:()=>Ht,resolveSuspense:()=>Ut,scheduler:()=>_e,setRootId:()=>zt,startTransition:()=>gs,stringify:()=>at,throwThis:()=>Z,trueFn:()=>z,unmountRoot:()=>Re,useCallback:()=>us,useContext:()=>ts,useDeferredValue:()=>ks,useEffect:()=>Ie,useError:()=>fs,useEvent:()=>ds,useId:()=>Ts,useImperativeHandle:()=>ys,useInsertionEffect:()=>Is,useLayoutEffect:()=>ye,useMemo:()=>ce,useReducer:()=>Es,useRef:()=>os,useState:()=>hs,useSyncExternalStore:()=>bs,useTransition:()=>ms,useUpdate:()=>Je,walk:()=>Nt,workLoop:()=>Pe});const s="1.6.0",n="@dark-engine/core",r="dark:root",i="dark:matter",o="dark:idx",a="key",l="ref",c="C",u="U",h="D",d="S",f=1,p=2,g=4,m=8,k=1,I=2,y=4,E=8,T=16,v=":",S=6,b="text/dark-state",w="rejected";var O;!function(t){t[t.LOW=0]="LOW",t[t.NORMAL=1]="NORMAL",t[t.HIGH=2]="HIGH"}(O||(O={}));const _={[a]:!0,[l]:!0};class C{type=null;props=null;token=null;displayName="";shouldUpdate=null;children=null;constructor(t,e,s=null,n=""){this.type=t,this.props=e,this.token=s,this.displayName=n}inject(t,e){return this.shouldUpdate=t,this.token=e,this}}function x(t,e={}){const{token:s,displayName:n}=e,r=(e={})=>new C(t,e,s,n);return r.displayName=n,r}const M=t=>t instanceof C,A=t=>t.props[a]??null,N=t=>"function"==typeof t,L=t=>void 0===t,R=t=>"number"==typeof t,P=t=>"string"==typeof t,D=t=>"string"==typeof t||"number"==typeof t,U=t=>"object"==typeof t,H=t=>"boolean"==typeof t,B=Array.isArray,W=t=>null===t,F=t=>null==t,K=t=>null==t||!1===t,V=t=>t instanceof Promise,j=Object.is,Y=Object.keys,$=t=>Y(t).length>0,G=()=>Date.now(),q=()=>{},z=()=>!0,Q=()=>!1,X=(...t)=>!L(console)&&console.error(...t),J=(t,e=n)=>`[${e}]: ${t}`;function Z(t){throw t}const tt=(t,e=n)=>Z(new Error(J(t,e))),et=t=>t.flat(1/0);function st(t,e){if(t===e||0===t.length&&0===e.length)return!1;const s=Math.max(t.length,e.length);for(let n=0;n<s;n++)if(!j(t[n],e[n]))return!0;return!1}const nt=t=>Promise.resolve().then(t),rt=t=>`${o}:${t}`,it=t=>Y(t).map((e=>t[e])),ot=t=>t instanceof Error?t:new Error(String(t)),at=JSON.stringify,lt=Symbol("vNode"),ct="props",ut="attrs",ht="type";class dt{type=null;constructor(t){this.type=t}}class ft extends dt{name;attrs;children;constructor(t,e,s){super(At.TAG),this.name=t,this.attrs=e,this.children=s}}class pt extends dt{value;constructor(t){super(At.TEXT),this.value=String(t)}}class gt extends dt{value="";constructor(t){super(At.COMMENT),this.value=t}}const mt=t=>{const e=()=>{const{as:e,slot:s,_void:n=!1,...r}=t,i=n?[]:B(s)?s:F(s)?[]:[s];return new ft(e,r,i)};return e[lt]=!0,e[ht]=t.as,e[a]=t.key,e},kt=t=>new pt(t);kt.from=t=>St(t)?t.value:String(t);const It=t=>new gt(t),yt=()=>new gt(i),Et=t=>t instanceof dt,Tt=t=>t instanceof ft,vt=t=>t instanceof gt,St=t=>t instanceof pt,bt=t=>t?.[lt],wt=t=>!Tt(t),Ot=t=>t.name??t[ht]??null,_t=t=>t?t[ct]?t[ct][a]??null:t[ut]?t[ut][a]??null:t[a]??null:null,Ct=t=>void 0!==t?.children,xt=(t,e)=>Ot(t)===Ot(e),Mt=(t,e)=>M(t)&&M(e)&&xt(t,e)&&_t(t)===_t(e);var At;function Nt(t,e){let s=!0,n=!1;const r=()=>s=!1,i=()=>n=!0,o=[t];for(;0!==o.length;){const a=o.pop();if(e(a,r,i),n)break;a!==t&&a.next&&o.push(a.next),s&&a.child&&o.push(a.child),s=!0}}function Lt(t,e){const s=[];return Nt(t,function(t,e){return(s,n)=>{if(s.el)return!s.hook?.getIsPortal()&&t.push(e(s)),n()}}(s,e)),s}function Rt(t){let e=t;for(;e;){if(e.el)return e;e=e.parent}return e}function Pt(t){let e=t;for(;e;){if(e.tag===h)return!1;e=e.parent}return Boolean(t)}function Dt(t,e){let s=t;for(;s;){if(s.hook?.getIsSuspense()&&(!e||s.hook.getIsPending()))return s;s=s.parent}return null}function Ut(t){return Dt(t,!0)||Dt(t,!1)||null}function Ht(t){let e=t;for(;e;){if(e.hook?.getIsBoundary())return e;e=e.parent}return null}function Bt(t,e,s){const n=s.owner;let r=n,i=`${n.idx}${v}${e}`;for(;r;)r=r.parent,r&&(i=`${r.idx}.${i}`);return i=`[${t}]${i}`,i}!function(t){t.TAG="TAG",t.TEXT="TEXT",t.COMMENT="COMMENT"}(At||(At={}));const Wt=(t,e,s)=>()=>Bt(t,e,s);function Ft(t,e=t){t.increment(e.el?1:e.cec),e.mask&f&&t.markHost(f),e.mask&p&&t.markHost(p)}class Kt{store;constructor(t={}){this.store=t}get(t){return this.store[t]}reset(){this.store={}}fork(){return new Kt({...this.store})}reconcile(t,e,s){const{id:n,inst:r}=t,i=xt(e.inst,r),o=r.children;if(i){if(Ct(e.inst)&&o){const{prevKeys:t,nextKeys:r,prevKeysMap:i,nextKeysMap:a,keyedFibersMap:l}=function(t,e){let s=t,n=0;const r=[],i=[],o={},a={},l={},c={};for(;s||n<e.length;){if(s){const t=_t(s.inst),e=F(t)?rt(n):t;o[e]||(o[e]=!0,r.push(e)),l[e]=s}if(n<e.length){const t=e[n],s=_t(t),r=F(s)?rt(n):s;a[r]||(a[r]=!0,i.push(r)),c[r]=!0}s=s?s.next:null,n++}return{prevKeys:r,nextKeys:i,prevKeysMap:o,nextKeysMap:a,keyedFibersMap:l}}(e.child,o),c=0===r.length;let u=Math.max(t.length,r.length),h=0,d=0;this.createStore(n,l);for(let e=0;e<u;e++){const o=r[e-d]??null,f=t[e-h]??null,p=l[f]||null;o!==f?null===o||i[o]?a[f]?a[f]&&a[o]&&this.move(n,o):(this.remove(n,f),s.addDeletion(p),c&&(p.mask|=g),d++,u++):null===f||a[f]?(this.insert(n,o),h++,u++):(this.replace(n,o),s.addDeletion(p)):null!==o&&this.stable(n,o)}}}else s.addDeletion(e)}createStore(t,e){this.store[t]={map:e,replace:null,insert:null,remove:null,move:null,stable:null}}replace(t,e){!this.store[t].replace&&(this.store[t].replace={}),this.store[t].replace[e]=!0}insert(t,e){!this.store[t].insert&&(this.store[t].insert={}),this.store[t].insert[e]=!0}remove(t,e){!this.store[t].remove&&(this.store[t].remove={}),this.store[t].remove[e]=!0}move(t,e){!this.store[t].move&&(this.store[t].move={}),this.store[t].move[e]=!0}stable(t,e){!this.store[t].stable&&(this.store[t].stable={}),this.store[t].stable[e]=!0}}class Vt{subscribers=new Map;on(t,e){return!this.subscribers.has(t)&&this.subscribers.set(t,new Set),this.subscribers.get(t).add(e),()=>this.subscribers.has(t)&&this.subscribers.get(t).delete(e)}emit(t,e){if(!this.subscribers.has(t))return;const s=Array.from(this.subscribers.get(t));for(const t of s)t(e)}kill(){this.subscribers=new Map}__getSize(t){return t?this.subscribers.get(t)?.size??0:this.subscribers.size}}class jt{store=new Map;add(t,e,s){const n=t?.hook||e?.hook;!this.store.has(n)&&this.store.set(n,[null,null,new Set]);const r=this.store.get(n);r[0]=t?.hook||null,r[1]=e?.hook||null,r[2].add(s)}resolve(){for(const[t,e]of this.store){this.store.delete(t);const[s,n,r]=e;let i=0;0!==r.size&&(s&&(s.setIsPeinding(!0),s.incrementPendings(),i=s.getPendings(),s.update()),Promise.allSettled(r).then((t=>{const e=n&&s?n.owner.id<s.owner.id?n:s:n||s;if(n){const e=t.find((t=>t.status===w));e&&n.owner.setError(ot(e.reason))}s&&i===s.getPendings()&&s.setIsPeinding(!1),e.update()})))}}}class Yt{root=null;wip=null;cursor=null;unit=null;mDeep=!0;mLevel=0;mNav=new Map;events=new Map;offs=new Set;reconciler=new Kt;candidates=new Set;deletions=new Set;cancels=[];asyncEffects=new Set;layoutEffects=new Set;insertionEffects=new Set;resId=0;resources=new Map;awaiter=new jt;onTransitionEnd=null;isLayoutEffect=!1;isInsertionEffect=!1;isUpdate=!1;isBatch=!1;isForce=!1;isHydration=!1;isStream=!1;isTransition=!1;isEvent=!1;isHot=!1;isDynamic=te.detectIsDynamic();isServer=ee();emitter=new Vt;fork(){const t=new Yt;return t.root=null,t.wip=null,t.cursor=null,t.unit=this.unit,t.mDeep=this.mDeep,t.mLevel=this.mLevel,t.mNav=new Map(this.mNav),t.events=this.events,t.offs=this.offs,t.reconciler=this.reconciler.fork(),t.candidates=new Set([...this.candidates]),t.deletions=new Set([...this.deletions]),t.asyncEffects=new Set([...this.asyncEffects]),t.layoutEffects=new Set([...this.layoutEffects]),t.isUpdate=this.isUpdate,t.emitter=this.emitter,t.awaiter=this.awaiter,t}getRoot(){return this.root}setRoot(t){this.root=t}keepRoot(){!this.isUpdate&&this.setRoot(this.wip)}getWorkInProgress(){return this.wip}setWorkInProgress(t){this.wip=t}getNextUnitOfWork(){return this.unit}setUnitOfWork(t){this.unit=t}getCursor(){return this.cursor}setCursor(t){this.cursor=t}navToChild(){this.mLevel=this.mLevel+1,this.mNav.set(this.mLevel,0)}navToSibling(){this.mNav.set(this.mLevel,this.mNav.get(this.mLevel)+1)}navToParent(){this.mLevel=this.mLevel-1}navToPrev(){0===this.getMountIndex()?(this.navToParent(),this.setMountDeep(!0)):(this.mNav.set(this.mLevel,this.mNav.get(this.mLevel)-1),this.setMountDeep(!1))}getMountIndex(){return this.mNav.get(this.mLevel)}getMountDeep(){return this.mDeep}setMountDeep(t){this.mDeep=t}resetMount(){this.mLevel=0,this.mNav=new Map,this.mDeep=!0}getEvents(){return this.events}addOff(t){this.offs.add(t)}off(){this.offs.forEach((t=>t())),this.offs=new Set}getCandidates(){return this.candidates}addCandidate(t){this.candidates.add(t)}resetCandidates(){this.candidates=new Set}getDeletions(){return this.deletions}hasDeletion(t){let e=t;for(;e;){if(this.deletions.has(e))return!0;e=e.parent}return!1}addDeletion(t){!this.hasDeletion(t)&&this.deletions.add(t)}resetDeletions(){this.deletions=new Set}addAsyncEffect(t){this.asyncEffects.add(t)}resetAsyncEffects(){this.asyncEffects=new Set}runAsyncEffects(){if(!this.isDynamic)return;const t=this.asyncEffects;t.size>0&&setTimeout((()=>t.forEach((t=>t()))))}addLayoutEffect(t){this.layoutEffects.add(t)}resetLayoutEffects(){this.layoutEffects=new Set}runLayoutEffects(){this.isDynamic&&(this.setIsLayoutEffect(!0),this.layoutEffects.forEach((t=>t())),this.setIsLayoutEffect(!1))}addInsertionEffect(t){this.insertionEffects.add(t)}resetInsertionEffects(){this.insertionEffects=new Set}runInsertionEffects(){this.isDynamic&&(this.setIsInsertionEffect(!0),this.insertionEffects.forEach((t=>t())),this.setIsInsertionEffect(!1))}addCancel(t){this.cancels.push(t)}applyCancels(){for(let t=this.cancels.length-1;t>=0;t--)this.cancels[t]()}resetCancels(){this.cancels=[]}getIsLayoutEffect(){return this.isLayoutEffect}setIsLayoutEffect(t){this.isLayoutEffect=t}getIsInsertionEffect(){return this.isInsertionEffect}setIsInsertionEffect(t){this.isInsertionEffect=t}getIsUpdate(){return this.isUpdate}setIsUpdate(t){this.isUpdate=t}getIsBatch(){return this.isBatch}setIsBatch(t){this.isBatch=t}getIsHydration(){return this.isHydration}setIsHydration(t){this.isHydration=t}getIsStream(){return this.isStream}setIsStream(t){this.isStream=t}getIsTransition(){return this.isTransition}setIsTransition(t){this.isTransition=t}getIsEvent(){return this.isEvent}setIsEvent(t,e=!1){this.isEvent=t,this.isForce=e}getIsForce(){return this.isForce}getIsHot(){return this.isHot}setIsHot(t){this.isHot=t}getOnTransitionEnd(){return this.onTransitionEnd}setOnTransitionEnd(t){this.onTransitionEnd=t}getReconciler(){return this.reconciler}cleanup(){this.keepRoot(),this.setWorkInProgress(null),this.setUnitOfWork(null),this.setCursor(null),this.resetMount(),this.resetCandidates(),this.resetDeletions(),this.resetCancels(),this.resetInsertionEffects(),this.resetLayoutEffects(),this.resetAsyncEffects(),this.setIsHydration(!1),this.setIsUpdate(!1),this.reconciler.reset()}getEmitter(){return this.emitter}getResource(t){return this.resources.get(t)}setResource(t,e){this.resources.set(t,e)}getResources(){return this.resources}getNextResourceId(){return++this.resId}getAwaiter(){return this.awaiter}runAfterCommit(){this.resources=new Map,this.isServer&&(this.resId=0)}}let $t=null;const Gt=new Map,qt=()=>$t,zt=t=>{$t=t,!Gt.has($t)&&Gt.set($t,new Yt)},Qt=t=>Gt.delete(t),Xt=(t,e=$t)=>Object.assign(Gt.get(e),t),Jt=(t=$t)=>Gt.get(t),Zt=()=>tt("The function was not installed by renderer!"),te={createElement:Zt,toggle:Zt,raf:Zt,caf:Zt,spawn:Zt,commit:Zt,finishCommit:Zt,detectIsDynamic:Zt},ee=()=>!te.detectIsDynamic(),se=()=>Jt().getIsHydration(),ne=()=>ee()||se(),re=Symbol("memo"),ie=(t,e)=>{for(const s in e)if("slot"!==s&&e[s]!==t[s])return!0;return!1};function oe(t,e=ie){const s=s=>t(s).inject(e,re);return s.displayName=t.displayName,s}const ae=t=>M(t)&&t.token===re,le=oe(x((({getValue:t})=>t())),((t,e)=>st(t.deps,e.deps)));function ce(t,e){const s=ue(),{hook:n}=s,{idx:r,values:i}=n,o=i[r]||(i[r]={deps:e,value:t()});let a=null,l=null;return function(t){return M(t)||bt(t)}(o.value)?(a=o.value,l=le({getValue:t,deps:e})):(a=st(o.deps,e)?t():o.value,l=a),o.deps=e,o.value=a,n.idx++,l}function ue(){return Jt().getCursor()}function he(){const t=ee(),e=se();return{isServer:t,isHydration:e,isSSR:t||e}}function de(){const t=ue(),e=ce((()=>Ut(t)),[t]);return Boolean(e)}function fe(){const t=ue(),e=ce((()=>Ht(t)),[t]);return Boolean(e)}function pe(){const t=qt(),e=ue(),{hook:s}=e,{idx:n}=s;return Wt(t,n,s)}const ge=Symbol("effect");function me(t){return(e,s=[{}])=>{const n=Jt(),r=ue(),i=ce((()=>({token:ge,cleanup:void 0})),[]);r.markHost(f),ce((()=>{const s=()=>{i.cleanup=e(),t===ke.ASYNC&&N(i.cleanup)&&!Pt(r)&&i.cleanup()};switch(t){case ke.INSERTION:n.addInsertionEffect(s);break;case ke.LAYOUT:n.addLayoutEffect(s);break;case ke.ASYNC:n.addAsyncEffect(s)}return N(i.cleanup)&&i.cleanup(),null}),s)}}var ke;!function(t){t.ASYNC="ASYNC",t.LAYOUT="LAYOUT",t.INSERTION="INSERTION"}(ke||(ke={}));const Ie=me(ke.ASYNC),ye=me(ke.LAYOUT);class Ee{id=0;cc=0;cec=0;idx=0;eidx=0;mask=0;el=null;tag=null;parent=null;child=null;next=null;alt=null;inst=null;hook=null;constructor(t=0,e=null){this.id=Ee.incrementId(),this.idx=t,this.hook=e}mutate(t){for(const e in t)this[e]=t[e];return this}markHost(t){this.mask|=t,this.parent&&!(this.parent.mask&t)&&this.parent.markHost(t)}increment(t=1){this.parent&&(this.parent.cec+=t,this.parent.el||this.parent.hook?.getIsWip()||this.parent.increment(t))}setError(t){if(this.hook?.hasCatch())this.hook.catch(t),X(t);else{if(!this.parent)throw t;this.parent.setError(t)}}static incrementId(){return++Ee.nextId}static setNextId(t){Ee.nextId=t}static nextId=0}class Te{idx=0;values=[];owner=null;mask=0;providers=null;cleanups=null;catch=null;pendings=0;update=null;__getMask(t){return Boolean(this.mask&t)}__mark(t,e){e?this.mask|=t:this.mask&=~t}getIsWip(){return this.__getMask(k)}setIsWip(t){this.__mark(k,t)}getIsPortal(){return this.__getMask(I)}setIsPortal(t){this.__mark(I,t)}getIsSuspense(){return this.__getMask(y)}setIsSuspense(t){this.__mark(y,t)}getIsBoundary(){return this.__getMask(E)}setIsBoundary(t){this.__mark(E,t)}getIsPending(){return this.__getMask(T)}setIsPeinding(t){this.__mark(T,t)}getProviders(){return this.providers}setProviders(t){this.providers=t}hasCatch(){return N(this.catch)}setCatch(t){this.catch=t}setUpdate(t){this.update=t}createCleanup(t,e){this.owner.markHost(p),this.cleanups||(this.cleanups=new Map),this.cleanups.get(t)?.(),this.cleanups.set(t,e())}incrementPendings(){this.pendings++}getPendings(){return this.pendings}drop(){const{values:t,owner:e}=this;if(t.length>0&&e.mask&f&&function(t){const{values:e}=t;for(const{value:t}of e)t?.token===ge&&N(t.cleanup)&&t.cleanup()}(this),this.cleanups){for(const[t,e]of this.cleanups)e();this.cleanups.clear()}}}function ve(t,e,s){return t&&Mt(e,s)?t.hook:M(s)?new Te:null}class Se extends Vt{port1=null;port2=null;constructor(){super(),this.port1=new be(this),this.port2=new be(this)}}class be{channel;offs=[];constructor(t){this.channel=t}on(t,e){const s=this.channel.on(t,e);this.offs.push(s)}postMessage(t){te.spawn((()=>{this.channel.emit("message",t)}))}unref(){this.offs.forEach((t=>t())),this.offs=[]}}class we{__id;priority;forceAsync=!1;isTransition=!1;isObsolete=!1;callback=null;createLoc=null;onRestore=null;onTransitionEnd=null;static nextTaskId=0;constructor(t,e,s){this.__id=++we.nextTaskId,this.callback=t,this.priority=e,this.forceAsync=s}getId(){return this.__id}getPriority(){return this.priority}getForceAsync(){return this.forceAsync}setIsTransition(t){this.isTransition=t}getIsTransition(){return this.isTransition}run(){this.isObsolete=!1,this.callback(this.onRestore),this.onRestore=null}complete(t){this.isTransition&&!this.isObsolete&&N(this.onTransitionEnd)&&this.onTransitionEnd((e=>!!t&&this.createBase(e)===this.base()))}markAsObsolete(){this.isObsolete=!0}getIsObsolete(){return this.isObsolete}setOnRestore(t){this.onRestore=t}setCreateLoc(t){this.createLoc=t}createBase(t){const[e]=t.split(v);return e}base(){return this.createBase(this.loc())}loc(){return this.createLoc()}setOnTransitionEnd(t){this.onTransitionEnd=t}}const Oe=()=>">",_e=new class{queue={[O.HIGH]:[],[O.NORMAL]:[],[O.LOW]:[]};batched=[];deadline=0;lastId=0;task=null;scheduledCallback=null;isMessageLoopRunning=!1;channel=null;port=null;constructor(){this.channel=new Se,this.port=this.channel.port2,this.channel.port1.on("message",this.performWorkUntilDeadline.bind(this))}reset(){this.deadline=0,this.task=null,this.scheduledCallback=null,this.isMessageLoopRunning=!1}shouldYield(){return G()>=this.deadline}schedule(t,e){const s=function(t,e){const{priority:s=O.NORMAL,forceAsync:n=!1,isTransition:r=!1,loc:i,onTransitionEnd:o}=e,a=new we(t,s,n);return a.setIsTransition(r),a.setOnTransitionEnd(o),a.setCreateLoc(i||Oe),a}(t,e);if(e.isBatch){const{setupBatch:t}=e;this.batched.push({task:s,setup:t})}else this.putAndExecute(s)}putAndExecute(t){this.lastId=t.getId(),this.put(t),this.execute()}batch(){const{batched:t}=this,e=t.length;for(let s=0;s<e;s++){const{task:n,setup:r}=t[s];s<e-1?N(r)&&r():this.putAndExecute(n)}this.batched=[]}getLastId(){return this.lastId}detectIsTransition(){return this.task.getIsTransition()}hasNewTask(){const{high:t,normal:e,low:s}=this.getQueues();return t.length+e.length+s.length>0}retain(t){const{high:e,normal:s,low:n}=this.getQueues(),r=[...e,...s,...n],{hasHostUpdate:i,hasChildUpdate:o}=function(t,e){const s=t.base();let n=!1,r=!1,i=!1;for(let t=0;t<e.length;t++){const o=e[t].base();o.length<s.length&&0===s.indexOf(o)?n=!0:o===s?r=!0:o.length>s.length&&0===o.indexOf(s)&&(i=!0)}return{hasTopUpdate:n,hasHostUpdate:r,hasChildUpdate:i}}(this.task,r);if(i||o){const t=function(t,e){const s=t.loc();return e.some((t=>t.loc()===s))}(this.task,r);t?this.complete(this.task,!0):this.defer(this.task),this.task.markAsObsolete()}else this.task.setOnRestore(t),this.defer(this.task)}complete(t,e){t.complete(e)}put(t){const e=this.queue[t.getPriority()];if(t.getIsTransition()){const s=t.base(),n=e.filter((t=>t.base()!==s));e.splice(0,e.length,...n)}e.push(t)}pick(t){return 0!==t.length&&(this.task=t.shift(),this.run(this.task),!0)}run(t){try{t.run(),t.getForceAsync()?this.requestCallbackAsync(Pe):this.requestCallback(Pe)}catch(e){if(!V(e))throw e;e.catch(q).finally((()=>{this.run(t)}))}}execute(){if(!Xe()&&!this.isMessageLoopRunning){const{high:t,normal:e,low:s}=this.getQueues();this.pick(t)||this.pick(e)||this.pick(s)}}requestCallbackAsync(t){this.scheduledCallback=t,this.isMessageLoopRunning||(this.isMessageLoopRunning=!0,this.port.postMessage(null))}requestCallback(t){const e=t(!1);V(e)?e.catch(q).finally((()=>{this.requestCallback(t)})):(this.task=null,this.execute())}performWorkUntilDeadline(){if(this.scheduledCallback){this.deadline=G()+S;const t=this.scheduledCallback(!0);V(t)?t.catch(q).finally((()=>{this.port.postMessage(null)})):t?this.port.postMessage(null):(this.complete(this.task,!1),this.reset(),this.execute())}else this.isMessageLoopRunning=!1}defer(t){const{low:e}=this.getQueues();e.unshift(t)}getQueues(){return{high:this.queue[O.HIGH],normal:this.queue[O.NORMAL],low:this.queue[O.LOW]}}},Ce=Symbol("fragment"),xe=x((({slot:t})=>t||null),{token:Ce,displayName:"Fragment"}),Me=t=>M(t)&&t.token===Ce,Ae=f|p;function Ne(t){t.mask&Ae&&Nt(t,Le)}function Le(t,e){const{hook:s}=t;if(!(t.mask&Ae))return e();s?.drop()}function Re(t){if(L(t))return;const e=Jt(t);te.detectIsDynamic()&&(Ne(e.getRoot()),e.off()),Qt(t)}function Pe(t){const e=Jt(),s=e.getWorkInProgress(),n=e.getIsStream(),r=e.getEmitter();let i=e.getNextUnitOfWork(),o=!1;try{for(;i&&!o;)if(i=De(i,s,e.getMountDeep(),n,r,e),o=t&&_e.shouldYield(),e.setUnitOfWork(i),o&&_e.detectIsTransition()&&_e.hasNewTask())return Ge(e),!1;!i&&s&&function(t){if(t.getIsStream())te.finishCommit(),Ye(t);else{const e=t.getWorkInProgress(),s=t.getDeletions(),n=t.getCandidates(),r=t.getIsUpdate(),i=t.getAwaiter(),o=e.inst;for(const t of s)Ne(t),t.tag=h,te.commit(t);r&&function(t){const e=t.cec-t.alt.cec;if(0===e)return;const s=Rt(t.parent);t.hook.setIsWip(!1),t.increment(e),Nt(s.child,$e(e,t,{isRight:!1}))}(e),t.runInsertionEffects();for(const t of n){const e=t.inst;t.tag!==d&&te.commit(t),t.alt=null,e.children&&(e.children=null)}e.alt=null,e.hook?.setIsWip(!1),o.children=null,te.finishCommit(),t.runLayoutEffects(),t.runAsyncEffects(),i.resolve(),Ye(t)}}(e)}catch(s){if(V(s))return s;{const n=e.getEmitter();if(e.keepRoot(),n.emit("error",ot(s)),!t)throw s;return X(s),!1}}return Boolean(i)}function De(t,e,s,n,r,i){if(t.hook&&(t.hook.idx=0),s){const e=t.inst.children;if(e&&e.length>0){const e=function(t,e){e.navToChild();const s=t.inst?.children||null,n=s?He(s,0):null,r=We(Fe(t,n,0,e),n,0);return r.hook=t.child?.hook||r.hook,r.parent=t,t.child=r,r.eidx=t.el?0:t.eidx,Be(r,t,n,e),r}(t,i);return n&&r.emit("chunk",e),e}}let o=t.parent;for(;o&&t!==e;){const e=Ue(t,i);if(n&&(r.emit("chunk",t),e&&r.emit("chunk",e)),e)return e;o=(t=o).parent}return null}function Ue(t,e){e.navToSibling();const s=e.getMountIndex(),n=t.parent.inst.children,r=n?He(n,s):null;if(!r)return e.navToParent(),e.setMountDeep(!1),null;e.setMountDeep(!0);const i=We(Fe(t,r,s,e),r,s);return i.hook=t.next?.hook||i.hook,i.parent=t.parent,t.next=i,i.eidx=t.eidx+(t.el?t.hook?.getIsPortal()?0:1:t.cec),Be(i,t,r,e),i}function He(t,e){if(!t||e>=t.length)return null;const s=t[e];let n=null;return t[e]=B(s)?xe({slot:s}):D(s)?kt(s):s||function(t){return K(t)?yt():t}(s),n=t[e],n}function Be(t,e,s,n){const{alt:r}=t,i=!r||!ae(s)||function(t,e,s){const n=t.alt,r=n.inst,i=e;if(i.type!==r.type||i.shouldUpdate(r.props,i.props))return!0;s.setMountDeep(!1),t.tag=d,t.child=n.child,t.child.parent=t,t.hook=n.hook,t.cc=n.cc,t.cec=n.cec,n.el&&(t.el=n.el);const o=t.eidx-n.eidx;return 0!==o&&Nt(t.child,Ke(o)),Ft(t,n),!1}(t,s,n);n.setCursor(t),t.inst=s,r&&r.mask&m&&(t.mask|=m,r.mask&=~m),t.hook&&(t.hook.owner=t),i?(t.inst=Ve(t,e,n),r&&n.getReconciler().reconcile(t,r,n),function(t,e){const s=t.inst;let n=!1;t.parent.tag===c&&(t.tag=t.parent.tag),n=e&&t.tag!==c&&xt(e.inst,s)&&_t(e.inst)===_t(s),t.tag=n?u:c,t.el||(n&&e.el?t.el=e.el:Et(t.inst)&&(t.el=te.createElement(t.inst))),t.el&&!t.hook?.getIsPortal()&&t.increment()}(t,r)):t.mask&m&&(t.tag=u),n.addCandidate(t)}function We(t,e,s){const n=t?t.inst:null,r=new Ee(s,ve(t,n,e));return r.alt=t||null,r}function Fe(t,e,s,n){const r=0===s,i=r?t:t.parent;if(!t.hook?.getIsWip()&&i.tag===c)return null;const o=r?t.id:t.parent.id,a=_t(e),l=n.getReconciler().get(o);let u=null;if(null!==a&&l){const t=l.move&&Boolean(l.move[a]),e=l.stable&&Boolean(l.stable[a]);(t||e)&&(u=l.map[a],t&&(u.mask|=m))}else u=t.alt?r?t.alt.child:t.alt.next:l&&l.map[rt(s)]||null;return u}const Ke=t=>(e,s)=>{if(e.eidx+=t,e.el)return s()};function Ve(t,e,s){let n=t.inst;const r=M(n),i=n;if(r)try{let t=i.type(i.props);B(t)?!Me(i)&&(t=xe({slot:t})):D(t)&&(t=kt(t)),i.children=t}catch(n){const r=ne();if(V(n)){const i=n,o=je(t,e,s),a=Ht(t);if(r)throw o(),i;{const e=Ut(t);if(!e&&!a)throw o(),i;s.getAwaiter().add(e,a,i)}}else i.children=[],!r&&t.setError(n)}else bt(n)&&(n=n());return Ct(n)&&(n.children=B(n.children)?n.children:[n.children],r&&0===i.children.length&&i.children.push(yt()),t.cc=n.children.length),n}const je=(t,e,s)=>()=>{e?(t.hook.owner=null,t.hook.idx=0,s.navToPrev(),s.setUnitOfWork(e),Ee.setNextId(e.id)):(t.id=Ee.incrementId(),t.cec=t.alt.cec)};function Ye(t,e=!1){t.cleanup(),!e&&t.getEmitter().emit("finish"),t.runAfterCommit()}const $e=(t,e,s)=>(n,r)=>{if(n===e)return s.isRight=!0,r();n.el&&r(),s.isRight&&(n.eidx+=t)};function Ge(t){const e=t.fork(),s=t.getWorkInProgress(),n=qe(e,s.child),{alt:r}=s;s.child=r.child,s.cc=r.cc,s.cec=r.cec,s.hook?.setIsWip(!1),s.alt=null,s.hook.idx=0,s.hook.owner=s,t.runInsertionEffects(),t.applyCancels(),Ye(t,!0),_e.retain(n)}const qe=(t,e)=>s=>{const{fiber:n,setValue:r,resetValue:i}=s,o=Jt();N(r)&&r(),N(i)&&t.addCancel(i),n.alt=(new Ee).mutate(n),n.tag=u,n.child=e,n.hook?.setIsWip(!0),e.parent=n,t.setRoot(o.getRoot()),t.setWorkInProgress(n),Xt(t)};function ze(t,e){const{idx:s}=e;return n=>{const{getTools:r,setupBatch:i}=n||{},o=Jt();if(o.getIsInsertionEffect())return;const a=o.getIsTransition(),l=o.getIsEvent(),c=a?O.LOW:l?O.HIGH:O.NORMAL,h=a,d=a?o.getOnTransitionEnd():null,f=o.getIsBatch(),p=function(t){const{rootId:e,hook:s,isTransition:n,getTools:r=Qe}=t;return t=>{zt(e);const i=N(t),{shouldUpdate:o,setValue:a,resetValue:l}=r(),c=Jt(),h=s.owner,d=h.alt||h;d.tag&&o()&&Pt(d)&&!i?(N(a)&&a(),N(l)&&n&&c.addCancel(l),d.alt=null,d.alt=(new Ee).mutate(d),d.tag=u,d.cc=0,d.cec=0,d.child=null,d.hook.setIsWip(!0),s.idx=0,s.owner=d,c.setIsUpdate(!0),c.resetMount(),c.setWorkInProgress(d),c.setCursor(d),d.inst=Ve(d,null,c),c.setUnitOfWork(d)):i&&t({fiber:d,setValue:a,resetValue:l})}}({rootId:t,hook:e,isTransition:a,getTools:r}),g=Wt(t,s,e);_e.schedule(p,{priority:c,forceAsync:h,isTransition:a,isBatch:f,setupBatch:i,loc:g,onTransitionEnd:d})}}const Qe=()=>({shouldUpdate:z,setValue:null,resetValue:null}),Xe=()=>Boolean(Jt()?.getWorkInProgress());function Je(){return ze(qt(),ue().hook)}function Ze(t,e){const{displayName:s="Component"}=e||{},n=x((({value:e=t,slot:s})=>{const r=ue(),{hook:i}=r;let o=i.getProviders();o||(o=new Map,o.set(n,{value:e,emitter:new Vt}),i.setProviders(o));const a=o.get(n);return ye((()=>{a.emitter.emit("publish",e)}),[e]),a.value=e,s}),{displayName:`Context(${s})`});return n.defaultValue=t,Object.freeze(n),n}function ts(t){const{defaultValue:e}=t,s=ue(),n=ce((()=>({value:null,provider:es(t,s)})),[]),r=Je(),{provider:i}=n,o=i?i.value:e;return ye((()=>{if(i)return i.emitter.on("publish",(t=>{!j(n.value,t)&&r()}))}),[]),n.value=o,o}function es(t,e){let s=e;for(;s;){const e=s.hook?.getProviders();if(e?.has(t))return e.get(t);s=s.parent}return null}const ss=new Map;function ns(t,e){return x((s=>{const n=ce((()=>({isDirty:!1})),[]),r=ss.get(t);if(L(r)&&!n.isDirty){const s=async()=>{ss.set(t,await function(t){return new Promise(((e,s)=>{t().then((t=>{e(t.default)})).catch(s)}))}(t)),N(e)&&e()};n.isDirty=!0,Z(s())}return r?r(s):null}),{displayName:"Lazy"})}function rs(t){if(!U(t)||W(t))return!1;const e=t;for(const t in e)if("current"===t&&e.hasOwnProperty(t))return!0;return!1}function is(t,e){N(t)?t(e):rs(t)&&(t.current=e)}function os(t=null){return ce((()=>({current:t})),[])}const as=oe(x((({slot:t})=>t),{displayName:"Guard"}),(()=>!1)),ls=x((({isOpen:t,slot:e})=>{const{isSSR:s}=he(),n=ue();return ye((()=>{if(s)return;const e=Lt(n,(t=>t));for(const s of e)Tt(s.inst)&&te.toggle(s.el,t)}),[t]),e}),{token:Symbol("shadow"),displayName:"Shadow"}),cs=x((({fallback:t=null,slot:e})=>{const s=ue(),n=Je(),r=s.hook.getIsPending(),i=[r?xe({key:1,slot:t}):null,ls({key:2,isOpen:!r,slot:e})].filter(Boolean);return s.hook.setIsSuspense(!0),s.hook.setUpdate(n),xe({slot:i})}),{displayName:"Suspense"});function us(t,e){return ce((()=>t),e)}function hs(t){const e=Je(),s=ce((()=>({value:N(t)?t():t})),[]),n=us((t=>{const n=Jt(),r=n.getIsBatch(),i=n.getIsForce(),o=function(t){const{get:e,set:s,reset:n,next:r,shouldUpdate:i}=t;return()=>{const t=e(),o=N(r)?r(t):r;return{shouldUpdate:()=>i(t,o),setValue:()=>s(o),resetValue:()=>n(t)}}}({next:t,get:()=>s.value,set:t=>s.value=t,reset:t=>s.value=t,shouldUpdate:(t,e)=>r||i||!j(t,e)});e({getTools:o,setupBatch:r?()=>o().setValue():void 0})}),[]);return[s.value,n]}function ds(t){const e=ce((()=>({fn:t})),[]);return e.fn=t,us(((...t)=>e.fn(...t)),[])}function fs(){const t=ue(),e=Je(),[s,n]=hs(null),r=ds((()=>n(null)));return t.hook.setIsBoundary(!0),t.hook.setCatch(n),t.hook.setUpdate(e),[s,r]}const ps=x((({fallback:t=null,renderFallback:e,onError:s,slot:n})=>{const[r,i]=fs();return Ie((()=>{r&&N(s)&&s(r)}),[r]),r?N(e)?e({error:r,reset:i}):t:n}),{displayName:"ErrorBoundary"});function gs(t){const e=Jt(),s=_e.getLastId();e.setIsTransition(!0);try{if(t(),s===_e.getLastId()){const t=e.getOnTransitionEnd();N(t)&&t((()=>!1)),tt("startTransition must plan a new render!")}}finally{e.setIsTransition(!1)}}function ms(){const[t,e]=hs(!1),s=pe(),n=Jt(),r=ds((t=>{e(!0),n.setOnTransitionEnd((t=>e(t(s())))),gs(t),n.setOnTransitionEnd(null)}));return[!_e.detectIsTransition()&&t,r]}function ks(t){const[e,s]=hs(t);return ye((()=>{gs((()=>s(t)))}),[t]),e}const Is=me(ke.INSERTION);function ys(t,e,s){const n=ce((()=>e()),s||[{}]);t&&is(t,n)}function Es(t,e,s){const n=ce((()=>N(s)?s(e):e),[]),[r,i]=hs(n),o=us((e=>i((s=>t(s,e)))),[]);return[r,o]}function Ts(){return ce((()=>Ss(qt())),[])}let vs=1e6;const Ss=t=>`dark:${t}:${(++vs).toString(36)}`;function bs(t,e,s){const{isSSR:n}=he();n&&!N(s)&&tt("getServerSnapshot was not found!");const[r,i]=hs(n?s():e());return ye((()=>t((()=>i(e())))),[e]),r}function ws(t){const e=Jt();e.setIsBatch(!0),t(),e.setIsBatch(!1),_e.batch()}function Os(t){t()}return e})())); //# sourceMappingURL=dark-core.production.min.js.map