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)

1,293 lines (1,124 loc) 165 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define("DarkCore", [], factory); else if(typeof exports === 'object') exports["DarkCore"] = factory(); else root["DarkCore"] = factory(); })(self, () => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./src/awaiter/awaiter.ts": /*!********************************!*\ !*** ./src/awaiter/awaiter.ts ***! \********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Awaiter": () => (/* binding */ Awaiter) /* harmony export */ }); /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts"); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); class Awaiter { store = new Map(); add(suspense, boundary, promise) { const key = suspense?.hook || boundary?.hook; !this.store.has(key) && this.store.set(key, [null, null, new Set()]); const data = this.store.get(key); data[0] = suspense?.hook || null; data[1] = boundary?.hook || null; data[2].add(promise); } resolve() { for (const [key, data] of this.store) { this.store.delete(key); const [suspenseHook, boundaryHook, promises] = data; let pendings = 0; if (promises.size === 0) continue; if (suspenseHook) { suspenseHook.setIsPeinding(true); suspenseHook.incrementPendings(); pendings = suspenseHook.getPendings(); suspenseHook.update(); } Promise.allSettled(promises).then(res => { const hook = boundaryHook && suspenseHook ? boundaryHook.owner.id < suspenseHook.owner.id ? boundaryHook : suspenseHook : boundaryHook || suspenseHook; if (boundaryHook) { const rejected = res.find(x => x.status === _constants__WEBPACK_IMPORTED_MODULE_0__.REJECTED_STATUS); rejected && boundaryHook.owner.setError((0,_utils__WEBPACK_IMPORTED_MODULE_1__.createError)(rejected.reason)); } if (suspenseHook && pendings === suspenseHook.getPendings()) { suspenseHook.setIsPeinding(false); } hook.update(); }); } } } /***/ }), /***/ "./src/batch/batch.ts": /*!****************************!*\ !*** ./src/batch/batch.ts ***! \****************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "batch": () => (/* binding */ batch) /* harmony export */ }); /* harmony import */ var _scope__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../scope */ "./src/scope/scope.ts"); /* harmony import */ var _scheduler__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../scheduler */ "./src/scheduler/scheduler.ts"); function batch(callback) { const $scope = (0,_scope__WEBPACK_IMPORTED_MODULE_0__.$$scope)(); $scope.setIsBatch(true); callback(); $scope.setIsBatch(false); _scheduler__WEBPACK_IMPORTED_MODULE_1__.scheduler.batch(); } /***/ }), /***/ "./src/boundary/boundary.tsx": /*!***********************************!*\ !*** ./src/boundary/boundary.tsx ***! \***********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "ErrorBoundary": () => (/* binding */ ErrorBoundary), /* harmony export */ "useError": () => (/* binding */ useError) /* harmony export */ }); /* harmony import */ var _internal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../internal */ "./src/internal/internal.ts"); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _use_update__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../use-update */ "./src/use-update/use-update.ts"); /* harmony import */ var _use_effect__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../use-effect */ "./src/use-effect/use-effect.ts"); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../component */ "./src/component/component.ts"); /* harmony import */ var _use_state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../use-state */ "./src/use-state/use-state.ts"); /* harmony import */ var _use_event__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../use-event */ "./src/use-event/use-event.ts"); function useError() { const cursor = (0,_internal__WEBPACK_IMPORTED_MODULE_0__.__useCursor)(); const update = (0,_use_update__WEBPACK_IMPORTED_MODULE_1__.useUpdate)(); const [error, setError] = (0,_use_state__WEBPACK_IMPORTED_MODULE_2__.useState)(null); const reset = (0,_use_event__WEBPACK_IMPORTED_MODULE_3__.useEvent)(() => setError(null)); cursor.hook.setIsBoundary(true); cursor.hook.setCatch(setError); cursor.hook.setUpdate(update); return [error, reset]; } const ErrorBoundary = (0,_component__WEBPACK_IMPORTED_MODULE_4__.component)(({ fallback = null, renderFallback, onError, slot }) => { const [error, reset] = useError(); (0,_use_effect__WEBPACK_IMPORTED_MODULE_5__.useEffect)(() => { if (!error) return; (0,_utils__WEBPACK_IMPORTED_MODULE_6__.detectIsFunction)(onError) && onError(error); }, [error]); return error ? ((0,_utils__WEBPACK_IMPORTED_MODULE_6__.detectIsFunction)(renderFallback) ? renderFallback({ error, reset }) : fallback) : slot; }, { displayName: 'ErrorBoundary', }); /***/ }), /***/ "./src/component/component.ts": /*!************************************!*\ !*** ./src/component/component.ts ***! \************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Component": () => (/* binding */ Component), /* harmony export */ "component": () => (/* binding */ component), /* harmony export */ "detectIsComponent": () => (/* binding */ detectIsComponent), /* harmony export */ "getComponentKey": () => (/* binding */ getComponentKey) /* harmony export */ }); /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts"); class Component { type = null; props = null; token = null; displayName = ''; shouldUpdate = null; children = null; constructor(type, props, token = null, displayName = '') { this.type = type; this.props = props; this.token = token; this.displayName = displayName; } inject(shouldUpdate, token) { this.shouldUpdate = shouldUpdate; this.token = token; return this; } } function component(type, options = {}) { const { token, displayName } = options; const factory = (props = {}) => new Component(type, props, token, displayName); factory.displayName = displayName; return factory; } const detectIsComponent = (x) => x instanceof Component; const getComponentKey = (x) => x.props[_constants__WEBPACK_IMPORTED_MODULE_0__.KEY_ATTR] ?? null; /***/ }), /***/ "./src/component/index.ts": /*!********************************!*\ !*** ./src/component/index.ts ***! \********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Component": () => (/* reexport safe */ _component__WEBPACK_IMPORTED_MODULE_0__.Component), /* harmony export */ "component": () => (/* reexport safe */ _component__WEBPACK_IMPORTED_MODULE_0__.component), /* harmony export */ "detectIsComponent": () => (/* reexport safe */ _component__WEBPACK_IMPORTED_MODULE_0__.detectIsComponent), /* harmony export */ "getComponentKey": () => (/* reexport safe */ _component__WEBPACK_IMPORTED_MODULE_0__.getComponentKey) /* harmony export */ }); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./component */ "./src/component/component.ts"); /***/ }), /***/ "./src/constants.ts": /*!**************************!*\ !*** ./src/constants.ts ***! \**************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "ATTR_BLACK_LIST": () => (/* binding */ ATTR_BLACK_LIST), /* harmony export */ "CLEANUP_HOST_MASK": () => (/* binding */ CLEANUP_HOST_MASK), /* harmony export */ "CREATE_EFFECT_TAG": () => (/* binding */ CREATE_EFFECT_TAG), /* harmony export */ "DELETE_EFFECT_TAG": () => (/* binding */ DELETE_EFFECT_TAG), /* harmony export */ "EFFECT_HOST_MASK": () => (/* binding */ EFFECT_HOST_MASK), /* harmony export */ "FLUSH_MASK": () => (/* binding */ FLUSH_MASK), /* harmony export */ "HOOK_DELIMETER": () => (/* binding */ HOOK_DELIMETER), /* harmony export */ "INDEX_KEY": () => (/* binding */ INDEX_KEY), /* harmony export */ "IS_BOUNDARY_HOOK_MASK": () => (/* binding */ IS_BOUNDARY_HOOK_MASK), /* harmony export */ "IS_PENDING_HOOK_MASK": () => (/* binding */ IS_PENDING_HOOK_MASK), /* harmony export */ "IS_PORTAL_HOOK_MASK": () => (/* binding */ IS_PORTAL_HOOK_MASK), /* harmony export */ "IS_SUSPENSE_HOOK_MASK": () => (/* binding */ IS_SUSPENSE_HOOK_MASK), /* harmony export */ "IS_WIP_HOOK_MASK": () => (/* binding */ IS_WIP_HOOK_MASK), /* harmony export */ "KEY_ATTR": () => (/* binding */ KEY_ATTR), /* harmony export */ "LIB": () => (/* binding */ LIB), /* harmony export */ "MOVE_MASK": () => (/* binding */ MOVE_MASK), /* harmony export */ "REF_ATTR": () => (/* binding */ REF_ATTR), /* harmony export */ "REJECTED_STATUS": () => (/* binding */ REJECTED_STATUS), /* harmony export */ "REPLACER": () => (/* binding */ REPLACER), /* harmony export */ "ROOT": () => (/* binding */ ROOT), /* harmony export */ "SKIP_EFFECT_TAG": () => (/* binding */ SKIP_EFFECT_TAG), /* harmony export */ "STATE_SCRIPT_TYPE": () => (/* binding */ STATE_SCRIPT_TYPE), /* harmony export */ "TaskPriority": () => (/* binding */ TaskPriority), /* harmony export */ "UPDATE_EFFECT_TAG": () => (/* binding */ UPDATE_EFFECT_TAG), /* harmony export */ "VERSION": () => (/* binding */ VERSION), /* harmony export */ "YIELD_INTERVAL": () => (/* binding */ YIELD_INTERVAL) /* harmony export */ }); const VERSION = '1.6.0'; const LIB = '@dark-engine/core'; const ROOT = 'dark:root'; const REPLACER = 'dark:matter'; const INDEX_KEY = 'dark:idx'; const KEY_ATTR = 'key'; const REF_ATTR = 'ref'; const CREATE_EFFECT_TAG = 'C'; const UPDATE_EFFECT_TAG = 'U'; const DELETE_EFFECT_TAG = 'D'; const SKIP_EFFECT_TAG = 'S'; const EFFECT_HOST_MASK = 1; const CLEANUP_HOST_MASK = 2; const FLUSH_MASK = 4; const MOVE_MASK = 8; const IS_WIP_HOOK_MASK = 1; const IS_PORTAL_HOOK_MASK = 2; const IS_SUSPENSE_HOOK_MASK = 4; const IS_BOUNDARY_HOOK_MASK = 8; const IS_PENDING_HOOK_MASK = 16; const HOOK_DELIMETER = ':'; const YIELD_INTERVAL = 6; const STATE_SCRIPT_TYPE = 'text/dark-state'; const REJECTED_STATUS = 'rejected'; var TaskPriority; (function (TaskPriority) { TaskPriority[TaskPriority["LOW"] = 0] = "LOW"; TaskPriority[TaskPriority["NORMAL"] = 1] = "NORMAL"; TaskPriority[TaskPriority["HIGH"] = 2] = "HIGH"; })(TaskPriority || (TaskPriority = {})); const ATTR_BLACK_LIST = { [KEY_ATTR]: true, [REF_ATTR]: true, }; /***/ }), /***/ "./src/context/context.ts": /*!********************************!*\ !*** ./src/context/context.ts ***! \********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "createContext": () => (/* binding */ createContext), /* harmony export */ "useContext": () => (/* binding */ useContext) /* harmony export */ }); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../component */ "./src/component/component.ts"); /* harmony import */ var _use_layout_effect__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../use-layout-effect */ "./src/use-layout-effect/use-layout-effect.ts"); /* harmony import */ var _internal__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../internal */ "./src/internal/internal.ts"); /* harmony import */ var _emitter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../emitter */ "./src/emitter/emitter.ts"); /* harmony import */ var _use_update__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../use-update */ "./src/use-update/use-update.ts"); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _use_memo__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../use-memo */ "./src/use-memo/use-memo.ts"); function createContext(defaultValue, options) { const { displayName = 'Component' } = options || {}; const context = (0,_component__WEBPACK_IMPORTED_MODULE_0__.component)(({ value = defaultValue, slot }) => { const cursor = (0,_internal__WEBPACK_IMPORTED_MODULE_1__.__useCursor)(); const { hook } = cursor; let providers = hook.getProviders(); if (!providers) { providers = new Map(); providers.set(context, { value, emitter: new _emitter__WEBPACK_IMPORTED_MODULE_2__.EventEmitter() }); hook.setProviders(providers); } const provider = providers.get(context); (0,_use_layout_effect__WEBPACK_IMPORTED_MODULE_3__.useLayoutEffect)(() => { provider.emitter.emit('publish', value); }, [value]); provider.value = value; return slot; }, { displayName: `Context(${displayName})` }); context.defaultValue = defaultValue; Object.freeze(context); return context; } function useContext(context) { const { defaultValue } = context; const cursor = (0,_internal__WEBPACK_IMPORTED_MODULE_1__.__useCursor)(); const scope = (0,_use_memo__WEBPACK_IMPORTED_MODULE_4__.useMemo)(() => ({ value: null, provider: getProvider(context, cursor) }), []); const update = (0,_use_update__WEBPACK_IMPORTED_MODULE_5__.useUpdate)(); const { provider } = scope; const value = provider ? provider.value : defaultValue; (0,_use_layout_effect__WEBPACK_IMPORTED_MODULE_3__.useLayoutEffect)(() => { if (!provider) return; return provider.emitter.on('publish', (value) => { !(0,_utils__WEBPACK_IMPORTED_MODULE_6__.detectIsEqual)(scope.value, value) && update(); }); }, []); scope.value = value; return value; } function getProvider(context, fiber) { let $fiber = fiber; while ($fiber) { const providers = $fiber.hook?.getProviders(); if (providers?.has(context)) return providers.get(context); $fiber = $fiber.parent; } return null; } /***/ }), /***/ "./src/emitter/emitter.ts": /*!********************************!*\ !*** ./src/emitter/emitter.ts ***! \********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "EventEmitter": () => (/* binding */ EventEmitter) /* harmony export */ }); class EventEmitter { subscribers = new Map(); on(e, fn) { !this.subscribers.has(e) && this.subscribers.set(e, new Set()); this.subscribers.get(e).add(fn); return () => this.subscribers.has(e) && this.subscribers.get(e).delete(fn); } emit(e, data) { if (!this.subscribers.has(e)) return; const subs = Array.from(this.subscribers.get(e)); for (const sub of subs) sub(data); } kill() { this.subscribers = new Map(); } __getSize(e) { return e ? this.subscribers.get(e)?.size ?? 0 : this.subscribers.size; } } /***/ }), /***/ "./src/emitter/index.ts": /*!******************************!*\ !*** ./src/emitter/index.ts ***! \******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "EventEmitter": () => (/* reexport safe */ _emitter__WEBPACK_IMPORTED_MODULE_0__.EventEmitter) /* harmony export */ }); /* harmony import */ var _emitter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./emitter */ "./src/emitter/emitter.ts"); /***/ }), /***/ "./src/fiber/fiber.ts": /*!****************************!*\ !*** ./src/fiber/fiber.ts ***! \****************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Fiber": () => (/* binding */ Fiber), /* harmony export */ "Hook": () => (/* binding */ Hook), /* harmony export */ "getHook": () => (/* binding */ getHook) /* harmony export */ }); /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants */ "./src/constants.ts"); /* harmony import */ var _view__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../view */ "./src/view/view.ts"); /* harmony import */ var _use_effect__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../use-effect */ "./src/use-effect/use-effect.ts"); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../component */ "./src/component/component.ts"); class Fiber { 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(idx = 0, hook = null) { this.id = Fiber.incrementId(); this.idx = idx; this.hook = hook; } mutate(fiber) { for (const key in fiber) { this[key] = fiber[key]; } return this; } markHost(mask) { this.mask |= mask; this.parent && !(this.parent.mask & mask) && this.parent.markHost(mask); } increment(count = 1) { if (!this.parent) return; this.parent.cec += count; if (!this.parent.el && !this.parent.hook?.getIsWip()) { this.parent.increment(count); } } setError(err) { if (this.hook?.hasCatch()) { this.hook.catch(err); (0,_utils__WEBPACK_IMPORTED_MODULE_0__.logError)(err); } else if (this.parent) { this.parent.setError(err); } else { throw err; } } static incrementId() { return ++Fiber.nextId; } static setNextId(id) { Fiber.nextId = id; } static nextId = 0; } class Hook { idx = 0; values = []; owner = null; mask = 0; providers = null; cleanups = null; catch = null; pendings = 0; update = null; __getMask(mask) { return Boolean(this.mask & mask); } __mark(mask, x) { x ? (this.mask |= mask) : (this.mask &= ~mask); } getIsWip() { return this.__getMask(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_WIP_HOOK_MASK); } setIsWip(x) { this.__mark(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_WIP_HOOK_MASK, x); } getIsPortal() { return this.__getMask(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_PORTAL_HOOK_MASK); } setIsPortal(x) { this.__mark(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_PORTAL_HOOK_MASK, x); } getIsSuspense() { return this.__getMask(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_SUSPENSE_HOOK_MASK); } setIsSuspense(x) { this.__mark(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_SUSPENSE_HOOK_MASK, x); } getIsBoundary() { return this.__getMask(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_BOUNDARY_HOOK_MASK); } setIsBoundary(x) { this.__mark(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_BOUNDARY_HOOK_MASK, x); } getIsPending() { return this.__getMask(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_PENDING_HOOK_MASK); } setIsPeinding(x) { this.__mark(_constants__WEBPACK_IMPORTED_MODULE_1__.IS_PENDING_HOOK_MASK, x); } getProviders() { return this.providers; } setProviders(x) { this.providers = x; } hasCatch() { return (0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectIsFunction)(this.catch); } setCatch(x) { this.catch = x; } setUpdate(x) { this.update = x; } createCleanup(key, create) { this.owner.markHost(_constants__WEBPACK_IMPORTED_MODULE_1__.CLEANUP_HOST_MASK); if (!this.cleanups) this.cleanups = new Map(); this.cleanups.get(key)?.(); this.cleanups.set(key, create()); } incrementPendings() { this.pendings++; } getPendings() { return this.pendings; } drop() { const { values, owner } = this; if (values.length > 0 && owner.mask & _constants__WEBPACK_IMPORTED_MODULE_1__.EFFECT_HOST_MASK) { (0,_use_effect__WEBPACK_IMPORTED_MODULE_2__.dropEffects)(this); } if (this.cleanups) { for (const [_, cleanup] of this.cleanups) cleanup(); this.cleanups.clear(); } } } function getHook(alt, prevInst, nextInst) { if (alt && (0,_view__WEBPACK_IMPORTED_MODULE_3__.detectAreSameComponentTypesWithSameKeys)(prevInst, nextInst)) return alt.hook; if ((0,_component__WEBPACK_IMPORTED_MODULE_4__.detectIsComponent)(nextInst)) return new Hook(); return null; } /***/ }), /***/ "./src/fiber/index.ts": /*!****************************!*\ !*** ./src/fiber/index.ts ***! \****************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Fiber": () => (/* reexport safe */ _fiber__WEBPACK_IMPORTED_MODULE_0__.Fiber), /* harmony export */ "Hook": () => (/* reexport safe */ _fiber__WEBPACK_IMPORTED_MODULE_0__.Hook), /* harmony export */ "getHook": () => (/* reexport safe */ _fiber__WEBPACK_IMPORTED_MODULE_0__.getHook) /* harmony export */ }); /* harmony import */ var _fiber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./fiber */ "./src/fiber/fiber.ts"); /***/ }), /***/ "./src/fragment/fragment.ts": /*!**********************************!*\ !*** ./src/fragment/fragment.ts ***! \**********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Fragment": () => (/* binding */ Fragment), /* harmony export */ "detectIsFragment": () => (/* binding */ detectIsFragment) /* harmony export */ }); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../component */ "./src/component/component.ts"); const $$fragment = Symbol('fragment'); const Fragment = (0,_component__WEBPACK_IMPORTED_MODULE_0__.component)(({ slot }) => slot || null, { token: $$fragment, displayName: 'Fragment' }); const detectIsFragment = (instance) => (0,_component__WEBPACK_IMPORTED_MODULE_0__.detectIsComponent)(instance) && instance.token === $$fragment; /***/ }), /***/ "./src/guard/guard.ts": /*!****************************!*\ !*** ./src/guard/guard.ts ***! \****************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Guard": () => (/* binding */ Guard) /* harmony export */ }); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../component */ "./src/component/component.ts"); /* harmony import */ var _memo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../memo */ "./src/memo/memo.ts"); const Guard = (0,_memo__WEBPACK_IMPORTED_MODULE_0__.memo)((0,_component__WEBPACK_IMPORTED_MODULE_1__.component)(({ slot }) => slot, { displayName: 'Guard' }), () => false); /***/ }), /***/ "./src/hot/hot.ts": /*!************************!*\ !*** ./src/hot/hot.ts ***! \************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "hot": () => (/* binding */ hot) /* harmony export */ }); /* harmony import */ var _scope__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../scope */ "./src/scope/scope.ts"); function hot(update) { if (true) { true && (0,_scope__WEBPACK_IMPORTED_MODULE_0__.$$scope)().setIsHot(true); } update(); } /***/ }), /***/ "./src/internal/index.ts": /*!*******************************!*\ !*** ./src/internal/index.ts ***! \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "__useCursor": () => (/* reexport safe */ _internal__WEBPACK_IMPORTED_MODULE_0__.__useCursor), /* harmony export */ "__useInBoundary": () => (/* reexport safe */ _internal__WEBPACK_IMPORTED_MODULE_0__.__useInBoundary), /* harmony export */ "__useInSuspense": () => (/* reexport safe */ _internal__WEBPACK_IMPORTED_MODULE_0__.__useInSuspense), /* harmony export */ "__useLoc": () => (/* reexport safe */ _internal__WEBPACK_IMPORTED_MODULE_0__.__useLoc), /* harmony export */ "__useSSR": () => (/* reexport safe */ _internal__WEBPACK_IMPORTED_MODULE_0__.__useSSR) /* harmony export */ }); /* harmony import */ var _internal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./internal */ "./src/internal/internal.ts"); /***/ }), /***/ "./src/internal/internal.ts": /*!**********************************!*\ !*** ./src/internal/internal.ts ***! \**********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "__useCursor": () => (/* binding */ useCursor), /* harmony export */ "__useInBoundary": () => (/* binding */ useInBoundary), /* harmony export */ "__useInSuspense": () => (/* binding */ useInSuspense), /* harmony export */ "__useLoc": () => (/* binding */ useLoc), /* harmony export */ "__useSSR": () => (/* binding */ useSSR) /* harmony export */ }); /* harmony import */ var _walk__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../walk */ "./src/walk/walk.ts"); /* harmony import */ var _platform__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../platform */ "./src/platform/platform.ts"); /* harmony import */ var _scope__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../scope */ "./src/scope/scope.ts"); /* harmony import */ var _use_memo__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../use-memo */ "./src/use-memo/use-memo.ts"); function useCursor() { return (0,_scope__WEBPACK_IMPORTED_MODULE_0__.$$scope)().getCursor(); } function useSSR() { const isServer = (0,_platform__WEBPACK_IMPORTED_MODULE_1__.detectIsServer)(); const isHydration = (0,_platform__WEBPACK_IMPORTED_MODULE_1__.detectIsHydration)(); const isSSR = isServer || isHydration; return { isServer, isHydration, isSSR, }; } function useInSuspense() { const cursor = useCursor(); const suspense = (0,_use_memo__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => (0,_walk__WEBPACK_IMPORTED_MODULE_3__.resolveSuspense)(cursor), [cursor]); return Boolean(suspense); } function useInBoundary() { const cursor = useCursor(); const boundary = (0,_use_memo__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => (0,_walk__WEBPACK_IMPORTED_MODULE_3__.resolveBoundary)(cursor), [cursor]); return Boolean(boundary); } function useLoc() { const rootId = (0,_scope__WEBPACK_IMPORTED_MODULE_0__.getRootId)(); const cursor = useCursor(); const { hook } = cursor; const { idx } = hook; const loc = (0,_walk__WEBPACK_IMPORTED_MODULE_3__.createLoc)(rootId, idx, hook); return loc; } /***/ }), /***/ "./src/lazy/lazy.ts": /*!**************************!*\ !*** ./src/lazy/lazy.ts ***! \**************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "lazy": () => (/* binding */ lazy) /* harmony export */ }); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../component */ "./src/component/component.ts"); /* harmony import */ var _use_memo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../use-memo */ "./src/use-memo/use-memo.ts"); const factories = new Map(); function lazy(loader, done) { return (0,_component__WEBPACK_IMPORTED_MODULE_0__.component)(props => { const scope = (0,_use_memo__WEBPACK_IMPORTED_MODULE_1__.useMemo)(() => ({ isDirty: false }), []); const factory = factories.get(loader); if ((0,_utils__WEBPACK_IMPORTED_MODULE_2__.detectIsUndefined)(factory) && !scope.isDirty) { const make = async () => { factories.set(loader, await run(loader)); (0,_utils__WEBPACK_IMPORTED_MODULE_2__.detectIsFunction)(done) && done(); }; scope.isDirty = true; (0,_utils__WEBPACK_IMPORTED_MODULE_2__.throwThis)(make()); } return factory ? factory(props) : null; }, { displayName: 'Lazy' }); } function run(loader) { return new Promise((resolve, reject) => { loader() .then(module => { check(module); resolve(module.default); }) .catch(reject); }); } function check(module) { if (true) { if (!module.default) { (0,_utils__WEBPACK_IMPORTED_MODULE_2__.illegal)('The lazy loaded component should be exported as default!'); } } } /***/ }), /***/ "./src/memo/memo.ts": /*!**************************!*\ !*** ./src/memo/memo.ts ***! \**************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "detectIsMemo": () => (/* binding */ detectIsMemo), /* harmony export */ "memo": () => (/* binding */ memo) /* harmony export */ }); /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../component */ "./src/component/component.ts"); const $$memo = Symbol('memo'); const defaultShouldUpdate = (props, nextProps) => { for (const key in nextProps) { if (key !== 'slot' && nextProps[key] !== props[key]) return true; } return false; }; function memo(factory, shouldUpdate = defaultShouldUpdate) { const memoized = (props) => factory(props).inject(shouldUpdate, $$memo); memoized.displayName = factory.displayName; return memoized; } const detectIsMemo = (instance) => (0,_component__WEBPACK_IMPORTED_MODULE_0__.detectIsComponent)(instance) && instance.token === $$memo; /***/ }), /***/ "./src/platform/index.ts": /*!*******************************!*\ !*** ./src/platform/index.ts ***! \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "detectIsHydration": () => (/* reexport safe */ _platform__WEBPACK_IMPORTED_MODULE_0__.detectIsHydration), /* harmony export */ "detectIsSSR": () => (/* reexport safe */ _platform__WEBPACK_IMPORTED_MODULE_0__.detectIsSSR), /* harmony export */ "detectIsServer": () => (/* reexport safe */ _platform__WEBPACK_IMPORTED_MODULE_0__.detectIsServer), /* harmony export */ "platform": () => (/* reexport safe */ _platform__WEBPACK_IMPORTED_MODULE_0__.platform) /* harmony export */ }); /* harmony import */ var _platform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./platform */ "./src/platform/platform.ts"); /***/ }), /***/ "./src/platform/platform.ts": /*!**********************************!*\ !*** ./src/platform/platform.ts ***! \**********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "detectIsHydration": () => (/* binding */ detectIsHydration), /* harmony export */ "detectIsSSR": () => (/* binding */ detectIsSSR), /* harmony export */ "detectIsServer": () => (/* binding */ detectIsServer), /* harmony export */ "platform": () => (/* binding */ platform) /* harmony export */ }); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _scope__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../scope */ "./src/scope/scope.ts"); const realisation = () => (0,_utils__WEBPACK_IMPORTED_MODULE_0__.illegal)('The function was not installed by renderer!'); const platform = { createElement: realisation, toggle: realisation, raf: realisation, caf: realisation, spawn: realisation, commit: realisation, finishCommit: realisation, detectIsDynamic: realisation, }; const detectIsServer = () => !platform.detectIsDynamic(); const detectIsHydration = () => (0,_scope__WEBPACK_IMPORTED_MODULE_1__.$$scope)().getIsHydration(); const detectIsSSR = () => detectIsServer() || detectIsHydration(); /***/ }), /***/ "./src/reconciler/reconciler.ts": /*!**************************************!*\ !*** ./src/reconciler/reconciler.ts ***! \**************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Reconciler": () => (/* binding */ Reconciler) /* harmony export */ }); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants */ "./src/constants.ts"); /* harmony import */ var _view__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../view */ "./src/view/view.ts"); class Reconciler { store; constructor(store = {}) { this.store = store; } get(id) { return this.store[id]; } reset() { this.store = {}; } fork() { return new Reconciler({ ...this.store }); } reconcile(fiber, alt, $scope) { const { id, inst } = fiber; const areSameTypes = (0,_view__WEBPACK_IMPORTED_MODULE_0__.detectAreSameInstanceTypes)(alt.inst, inst); const nextChildren = inst.children; if (!areSameTypes) { $scope.addDeletion(alt); } else if ((0,_view__WEBPACK_IMPORTED_MODULE_0__.hasChildrenProp)(alt.inst) && nextChildren) { const { prevKeys, nextKeys, prevKeysMap, nextKeysMap, keyedFibersMap } = extractKeys(alt.child, nextChildren); const flush = nextKeys.length === 0; let size = Math.max(prevKeys.length, nextKeys.length); let p = 0; let n = 0; this.createStore(id, keyedFibersMap); for (let i = 0; i < size; i++) { const nextKey = nextKeys[i - n] ?? null; const prevKey = prevKeys[i - p] ?? null; const prevKeyFiber = keyedFibersMap[prevKey] || null; if (nextKey !== prevKey) { if (nextKey !== null && !prevKeysMap[nextKey]) { if (prevKey !== null && !nextKeysMap[prevKey]) { this.replace(id, nextKey); $scope.addDeletion(prevKeyFiber); } else { this.insert(id, nextKey); p++; size++; } } else if (!nextKeysMap[prevKey]) { this.remove(id, prevKey); $scope.addDeletion(prevKeyFiber); flush && (prevKeyFiber.mask |= _constants__WEBPACK_IMPORTED_MODULE_1__.FLUSH_MASK); n++; size++; } else if (nextKeysMap[prevKey] && nextKeysMap[nextKey]) { this.move(id, nextKey); } } else if (nextKey !== null) { this.stable(id, nextKey); } } } } createStore(id, map) { this.store[id] = { map, replace: null, insert: null, remove: null, move: null, stable: null, }; } replace(id, nextKey) { !this.store[id].replace && (this.store[id].replace = {}); this.store[id].replace[nextKey] = true; } insert(id, nextKey) { !this.store[id].insert && (this.store[id].insert = {}); this.store[id].insert[nextKey] = true; } remove(id, prevKey) { !this.store[id].remove && (this.store[id].remove = {}); this.store[id].remove[prevKey] = true; } move(id, nextKey) { !this.store[id].move && (this.store[id].move = {}); this.store[id].move[nextKey] = true; } stable(id, nextKey) { !this.store[id].stable && (this.store[id].stable = {}); this.store[id].stable[nextKey] = true; } } function extractKeys(alt, children) { let nextFiber = alt; let idx = 0; const prevKeys = []; const nextKeys = []; const prevKeysMap = {}; const nextKeysMap = {}; const keyedFibersMap = {}; const usedKeysMap = {}; while (nextFiber || idx < children.length) { if (nextFiber) { const key = (0,_view__WEBPACK_IMPORTED_MODULE_0__.getElementKey)(nextFiber.inst); const prevKey = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.detectIsEmpty)(key) ? (0,_utils__WEBPACK_IMPORTED_MODULE_2__.createIndexKey)(idx) : key; if (!prevKeysMap[prevKey]) { prevKeysMap[prevKey] = true; prevKeys.push(prevKey); } keyedFibersMap[prevKey] = nextFiber; } if (idx < children.length) { const inst = children[idx]; const key = (0,_view__WEBPACK_IMPORTED_MODULE_0__.getElementKey)(inst); const nextKey = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.detectIsEmpty)(key) ? (0,_utils__WEBPACK_IMPORTED_MODULE_2__.createIndexKey)(idx) : key; if (true) { if (usedKeysMap[nextKey]) { (0,_utils__WEBPACK_IMPORTED_MODULE_2__.logError)((0,_utils__WEBPACK_IMPORTED_MODULE_2__.formatErrorMsg)(`The key of node [${nextKey}] already has been used!`), [inst]); } } if (!nextKeysMap[nextKey]) { nextKeysMap[nextKey] = true; nextKeys.push(nextKey); } usedKeysMap[nextKey] = true; } nextFiber = nextFiber ? nextFiber.next : null; idx++; } return { prevKeys, nextKeys, prevKeysMap, nextKeysMap, keyedFibersMap, }; } /***/ }), /***/ "./src/ref/index.ts": /*!**************************!*\ !*** ./src/ref/index.ts ***! \**************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "applyRef": () => (/* reexport safe */ _ref__WEBPACK_IMPORTED_MODULE_0__.applyRef), /* harmony export */ "detectIsMutableRef": () => (/* reexport safe */ _ref__WEBPACK_IMPORTED_MODULE_0__.detectIsMutableRef), /* harmony export */ "useRef": () => (/* reexport safe */ _ref__WEBPACK_IMPORTED_MODULE_0__.useRef) /* harmony export */ }); /* harmony import */ var _ref__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ref */ "./src/ref/ref.ts"); /***/ }), /***/ "./src/ref/ref.ts": /*!************************!*\ !*** ./src/ref/ref.ts ***! \************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "applyRef": () => (/* binding */ applyRef), /* harmony export */ "detectIsMutableRef": () => (/* binding */ detectIsMutableRef), /* harmony export */ "useRef": () => (/* binding */ useRef) /* harmony export */ }); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _use_memo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../use-memo */ "./src/use-memo/use-memo.ts"); function detectIsMutableRef(ref) { if (!(0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectIsObject)(ref) || (0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectIsNull)(ref)) return false; const mutableRef = ref; for (const key in mutableRef) { if (key === 'current' && mutableRef.hasOwnProperty(key)) { return true; } } return false; } function applyRef(ref, current) { if ((0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectIsFunction)(ref)) { ref(current); } else if (detectIsMutableRef(ref)) { ref.current = current; } } function useRef(initialValue = null) { const ref = (0,_use_memo__WEBPACK_IMPORTED_MODULE_1__.useMemo)(() => ({ current: initialValue }), []); return ref; } /***/ }), /***/ "./src/scheduler/index.ts": /*!********************************!*\ !*** ./src/scheduler/index.ts ***! \********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "scheduler": () => (/* reexport safe */ _scheduler__WEBPACK_IMPORTED_MODULE_0__.scheduler) /* harmony export */ }); /* harmony import */ var _scheduler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./scheduler */ "./src/scheduler/scheduler.ts"); /***/ }), /***/ "./src/scheduler/scheduler.ts": /*!************************************!*\ !*** ./src/scheduler/scheduler.ts ***! \************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "scheduler": () => (/* binding */ scheduler) /* harmony export */ }); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts"); /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants */ "./src/constants.ts"); /* harmony import */ var _workloop__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../workloop */ "./src/workloop/workloop.ts"); /* harmony import */ var _emitter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../emitter */ "./src/emitter/emitter.ts"); /* harmony import */ var _platform__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../platform */ "./src/platform/platform.ts"); class MessageChannel extends _emitter__WEBPACK_IMPORTED_MODULE_0__.EventEmitter { port1 = null; port2 = null; constructor() { super(); this.port1 = new MessagePort(this); this.port2 = new MessagePort(this); } } class MessagePort { channel; offs = []; constructor(channel) { this.channel = channel; } on(event, callback) { const off = this.channel.on(event, callback); this.offs.push(off); } postMessage(value) { _platform__WEBPACK_IMPORTED_MODULE_1__.platform.spawn(() => { this.channel.emit('message', value); }); } unref() { this.offs.forEach(x => x()); this.offs = []; } } class Scheduler { queue = { [_constants__WEBPACK_IMPORTED_MODULE_2__.TaskPriority.HIGH]: [], [_constants__WEBPACK_IMPORTED_MODULE_2__.TaskPriority.NORMAL]: [], [_constants__WEBPACK_IMPORTED_MODULE_2__.TaskPriority.LOW]: [], }; batched = []; deadline = 0; lastId = 0; task = null; scheduledCallback = null; isMessageLoopRunning = false; channel = null; port = null; constructor() { this.channel = new MessageChannel(); 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 = false; } shouldYield() { return (0,_utils__WEBPACK_IMPORTED_MODULE_3__.getTime)() >= this.deadline; } schedule(callback, options) { const task = createTask(callback, options); if (options.isBatch) { const { setupBatch: setup } = options; this.batched.push({ task, setup }); return; } this.putAndExecute(task); } putAndExecute(task) { this.lastId = task.getId(); this.put(task); this.execute(); } batch() { const { batched } = this; const size = batched.length; for (let i = 0; i < size; i++) { const { task, setup } = batched[i]; if (i < size - 1) { (0,_utils__WEBPACK_IMPORTED_MODULE_3__.detectIsFunction)(setup) && setup(); } else { this.putAndExecute(task); } } this.batched = []; } getLastId() { return this.lastId; } detectIsTransition() { return this.task.getIsTransition(); } hasNewTask() { const { high, normal, low } = this.getQueues(); return high.length + normal.length + low.length > 0; } retain(fn) { const { high, normal, low } = this.getQueues(); const tasks = [...high, ...normal, ...low]; const { hasHostUpdate, hasChildUpdate } = collectFlags(this.task, tasks); if (hasHostUpdate || hasChildUpdate) { const hasExact = detectHasExact(this.task, tasks); if (hasExact) { this.complete(this.task, true); } else { this.defer(this.task); } this.task.markAsObsolete(); } else { this.task.setOnRestore(fn); this.defer(this.task); } } complete(task, isCanceled) { task.complete(isCanceled); } put(task) { const queue = this.queue[task.getPriority()]; if (task.getIsTransition()) { const base = task.base(); const tasks = queue.filter(x => x.base() !== base); queue.splice(0, queue.length, ...tasks); } queue.push(task); } pick(queue) { if (queue.length === 0) return false; this.task = queue.shift(); this.run(this.task); return true; } run(task) { try { task.run(); task.getForceAsync() ? this.requestCallbackAsync(_workloop__WEBPACK_IMPORTED_MODULE_4__.workLoop) : this.requestCallback(_workloop__