@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,242 lines (1,081 loc) • 187 kB
JavaScript
(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/atom/atom.ts":
/*!**************************!*\
!*** ./src/atom/atom.ts ***!
\**************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "ReadableAtom": () => (/* binding */ ReadableAtom),
/* harmony export */ "WritableAtom": () => (/* binding */ WritableAtom),
/* harmony export */ "atom": () => (/* binding */ atom),
/* harmony export */ "computed": () => (/* binding */ computed),
/* harmony export */ "detectIsAtom": () => (/* binding */ detectIsAtom),
/* harmony export */ "detectIsReadableAtom": () => (/* binding */ detectIsReadableAtom),
/* harmony export */ "detectIsWritableAtom": () => (/* binding */ detectIsWritableAtom),
/* harmony export */ "useAtom": () => (/* binding */ useAtom),
/* harmony export */ "useComputed": () => (/* binding */ useComputed),
/* harmony export */ "useStore": () => (/* binding */ useStore)
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts");
/* harmony import */ var _use_update__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../use-update */ "./src/workloop/workloop.ts");
/* harmony import */ var _use_update__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../use-update */ "./src/use-update/use-update.ts");
/* harmony import */ var _use_layout_effect__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../use-layout-effect */ "./src/use-layout-effect/use-layout-effect.ts");
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
/* harmony import */ var _scope__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../scope */ "./src/scope/scope.ts");
/* harmony import */ var _use_state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../use-state */ "./src/use-state/use-state.ts");
/* harmony import */ var _emitter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../emitter */ "./src/emitter/emitter.ts");
/* harmony import */ var _use_memo__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../use-memo */ "./src/use-memo/use-memo.ts");
/* harmony import */ var _batch__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../batch */ "./src/batch/batch.ts");
class Atom {
value;
connections1;
connections2;
subjects;
emitter;
constructor(value) {
this.value = value;
}
val(fn, key) {
try {
this.__connect(fn, key);
}
catch (err) {
if (true) {
(0,_utils__WEBPACK_IMPORTED_MODULE_0__.logError)((0,_utils__WEBPACK_IMPORTED_MODULE_0__.formatErrorMsg)(`Illegal invocation atom.val() outside render process!`));
}
}
return this.value;
}
get() {
return this.value;
}
on(fn) {
!this.emitter && (this.emitter = new _emitter__WEBPACK_IMPORTED_MODULE_1__.EventEmitter());
return this.emitter.on('data', fn);
}
kill() {
if (this.connections1) {
for (const [hook, [_, __, ___, key]] of this.connections1) {
this.off(hook, key);
}
}
if (this.connections2) {
for (const [key, [_, hook]] of this.connections2) {
this.off(hook, key);
}
}
this.connections1 = null;
this.connections2 = null;
this.emitter = null;
this.subjects = null;
}
toString() {
return String(this.value);
}
toJSON() {
return this.value;
}
valueOf() {
return this.value;
}
__connect(fn, key) {
const rootId = (0,_scope__WEBPACK_IMPORTED_MODULE_2__.getRootId)();
const cursor = (0,_scope__WEBPACK_IMPORTED_MODULE_2__.$$scope)().getCursor();
const { hook } = cursor;
const disconnect = () => this.off(hook, key);
hook.setAtom(this, disconnect);
cursor.markHost(_constants__WEBPACK_IMPORTED_MODULE_3__.ATOM_HOST_MASK);
if ((0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectIsEmpty)(key)) {
!this.connections1 && (this.connections1 = new Map());
this.connections1.set(hook, [rootId, hook, fn, key]);
}
else {
!this.connections2 && (this.connections2 = new Map());
this.connections2.set(key, [rootId, hook, fn, key]);
}
return disconnect;
}
__addSubject(atom$) {
!this.subjects && (this.subjects = new Set());
this.subjects.add(atom$);
}
__removeSubject(atom$) {
return this.subjects && this.subjects.delete(atom$);
}
__getSize() {
const size1 = this.connections1 ? this.connections1.size : 0;
const size2 = this.connections2 ? this.connections2.size : 0;
const size3 = this.subjects ? this.subjects.size : 0;
const size4 = this.emitter ? this.emitter.__getSize() : 0;
return size1 + size2 + size3 + size4;
}
setValue(value) {
const prev = this.value;
const next = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectIsFunction)(value) ? value(this.value) : value;
const data = { prev, next };
const make = (tuple, prev, next) => {
const [rootId, hook, shouldUpdate, key] = tuple;
const fn = shouldUpdate || _utils__WEBPACK_IMPORTED_MODULE_0__.trueFn;
if (fn(prev, next, key)) {
const update = (0,_use_update__WEBPACK_IMPORTED_MODULE_4__.createUpdate)(rootId, hook);
if (this.__getSize() === 1) {
const tools = (0,_use_state__WEBPACK_IMPORTED_MODULE_5__.createTools)({
next,
get: () => prev,
set: () => (this.value = next),
reset: () => (this.value = prev),
});
update(tools);
}
else {
update();
}
}
};
this.value = next;
if (this.connections1) {
for (const [_, tuple] of this.connections1) {
make(tuple, prev, next);
}
}
if (this.connections2) {
if (this.connections2.has(next)) {
make(this.connections2.get(next), prev, next);
this.connections2.has(prev) && make(this.connections2.get(prev), prev, next);
}
}
this.emitter && this.emitter.emit('data', data);
this.subjects && this.subjects.forEach(x => x.__notify());
}
off(hook, key) {
hook.removeAtom(this);
this.connections1 && this.connections1.delete(hook);
this.connections2 && this.connections2.delete(key);
}
}
class WritableAtom extends Atom {
set(value) {
super.setValue(value);
}
}
class ReadableAtom extends Atom {
deps$ = [];
fn = null;
values = [];
constructor(deps$, fn) {
const values = ReadableAtom.values(deps$);
super(ReadableAtom.compute(fn, values));
this.deps$ = deps$;
this.fn = fn;
this.values = values;
deps$.forEach(x => x.__addSubject(this));
}
__notify() {
const values = ReadableAtom.values(this.deps$);
if ((0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectAreDepsDifferent)(this.values, values)) {
super.setValue(ReadableAtom.compute(this.fn, values));
}
this.values = values;
}
kill() {
super.kill();
this.deps$.forEach(x => x.__removeSubject(this));
this.deps$ = [];
this.fn = null;
}
static compute(fn, values) {
return fn(...values);
}
static values(deps$) {
return deps$.map(x => x.get());
}
}
const detectIsAtom = (x) => x instanceof Atom;
const detectIsWritableAtom = (x) => x instanceof WritableAtom;
const detectIsReadableAtom = (x) => x instanceof ReadableAtom;
const atom = (value) => new WritableAtom(value);
const computed = (deps$, fn) => new ReadableAtom(deps$, fn);
function useAtom(value) {
const atom$ = (0,_use_memo__WEBPACK_IMPORTED_MODULE_6__.useMemo)(() => atom(value), []);
(0,_use_layout_effect__WEBPACK_IMPORTED_MODULE_7__.useLayoutEffect)(() => () => atom$.kill(), []);
return atom$;
}
function useComputed(deps$, fn) {
const atom$ = (0,_use_memo__WEBPACK_IMPORTED_MODULE_6__.useMemo)(() => computed(deps$, fn), []);
(0,_use_layout_effect__WEBPACK_IMPORTED_MODULE_7__.useLayoutEffect)(() => () => atom$.kill(), []);
return atom$;
}
function useStore(atoms$) {
const forceUpdate = (0,_use_update__WEBPACK_IMPORTED_MODULE_8__.useUpdate)();
const update = () => (0,_batch__WEBPACK_IMPORTED_MODULE_9__.batch)(forceUpdate);
(0,_use_layout_effect__WEBPACK_IMPORTED_MODULE_7__.useLayoutEffect)(() => {
const offs = atoms$.map(x => x.on(update));
return () => offs.forEach(x => x());
}, [...atoms$]);
return atoms$.map(x => x.get());
}
/***/ }),
/***/ "./src/atom/index.ts":
/*!***************************!*\
!*** ./src/atom/index.ts ***!
\***************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "ReadableAtom": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.ReadableAtom),
/* harmony export */ "WritableAtom": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.WritableAtom),
/* harmony export */ "atom": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.atom),
/* harmony export */ "computed": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.computed),
/* harmony export */ "detectIsAtom": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.detectIsAtom),
/* harmony export */ "detectIsReadableAtom": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.detectIsReadableAtom),
/* harmony export */ "detectIsWritableAtom": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.detectIsWritableAtom),
/* harmony export */ "useAtom": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.useAtom),
/* harmony export */ "useComputed": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.useComputed),
/* harmony export */ "useStore": () => (/* reexport safe */ _atom__WEBPACK_IMPORTED_MODULE_0__.useStore)
/* harmony export */ });
/* harmony import */ var _atom__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./atom */ "./src/atom/atom.ts");
/***/ }),
/***/ "./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 */ "addBatch": () => (/* binding */ addBatch),
/* harmony export */ "batch": () => (/* binding */ batch)
/* harmony export */ });
/* harmony import */ var _scope__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../scope */ "./src/scope/scope.ts");
function batch(callback) {
const $scope = (0,_scope__WEBPACK_IMPORTED_MODULE_0__.$$scope)();
$scope.setIsBatch(true);
callback();
$scope.setIsBatch(false);
}
function addBatch(hook, callback, change) {
const $scope = (0,_scope__WEBPACK_IMPORTED_MODULE_0__.$$scope)();
if ($scope.getIsTransition()) {
callback();
}
else {
const batch = hook.getBatch() || { timer: null, changes: [] };
hook.setBatch(batch);
batch.changes.push(change);
batch.timer && clearTimeout(batch.timer);
batch.timer = setTimeout(() => {
batch.changes.splice(-1);
batch.changes.forEach(x => x());
hook.setBatch(null);
callback();
});
}
}
/***/ }),
/***/ "./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 */ "$$inject": () => (/* binding */ $$inject),
/* harmony export */ "Component": () => (/* binding */ Component),
/* harmony export */ "component": () => (/* binding */ component),
/* harmony export */ "detectIsComponent": () => (/* binding */ detectIsComponent),
/* harmony export */ "getComponentKey": () => (/* binding */ getComponentKey),
/* harmony export */ "hasComponentFlag": () => (/* binding */ hasComponentFlag)
/* harmony export */ });
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
const $$inject = Symbol('inject');
class Component {
type = null;
props = null;
token = null;
displayName = null;
shouldUpdate = null;
children = null;
constructor(type, token, props, shouldUpdate, displayName) {
this.type = type;
this.props = props;
token && (this.token = token);
shouldUpdate && (this.shouldUpdate = shouldUpdate);
displayName && (this.displayName = displayName);
}
}
function component(type, options = {}) {
const { token: $token, displayName } = options;
const factory = (props = {}) => {
const { token = $token, shouldUpdate } = factory[$$inject] || defaultInject;
return new Component(type, token, props, shouldUpdate, displayName);
};
factory.displayName = displayName;
return factory;
}
const defaultInject = {};
const detectIsComponent = (x) => x instanceof Component;
const getComponentKey = (x) => x.props[_constants__WEBPACK_IMPORTED_MODULE_0__.KEY_ATTR] ?? null;
const hasComponentFlag = (inst, flag) => Boolean(inst.props[flag]);
/***/ }),
/***/ "./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 */ "$$inject": () => (/* reexport safe */ _component__WEBPACK_IMPORTED_MODULE_0__.$$inject),
/* 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 */ "hasComponentFlag": () => (/* reexport safe */ _component__WEBPACK_IMPORTED_MODULE_0__.hasComponentFlag)
/* 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 */ "ATOM_HOST_MASK": () => (/* binding */ ATOM_HOST_MASK),
/* harmony export */ "ATTR_BLACK_LIST": () => (/* binding */ ATTR_BLACK_LIST),
/* 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 */ "FLAGS": () => (/* binding */ FLAGS),
/* harmony export */ "FLUSH_MASK": () => (/* binding */ FLUSH_MASK),
/* harmony export */ "Flag": () => (/* binding */ Flag),
/* 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.5.1';
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 ATOM_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 = {}));
var Flag;
(function (Flag) {
Flag["SKIP_SCAN_OPT"] = "__skipScanOpt";
Flag["MEMO_SLOT_OPT"] = "__memoSlotOpt";
Flag["STATIC_SLOT_OPT"] = "__staticSlotOpt";
})(Flag || (Flag = {}));
const FLAGS = {
__skipScanOpt: true,
__memoSlotOpt: true,
__staticSlotOpt: true,
};
const ATTR_BLACK_LIST = {
[KEY_ATTR]: true,
[REF_ATTR]: true,
[Flag.SKIP_SCAN_OPT]: true,
[Flag.MEMO_SLOT_OPT]: true,
[Flag.STATIC_SLOT_OPT]: 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) {
this.subscribers.has(e) && this.subscribers.get(e).forEach(x => x(data));
}
kill() {
this.subscribers = new Map();
}
__getSize() {
return 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;
atoms = null;
batch = 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;
}
setAtom(atom, cb) {
!this.atoms && (this.atoms = new Map());
this.atoms.set(atom, cb);
}
removeAtom(atom) {
this.atoms.delete(atom);
}
getBatch() {
return this.batch;
}
setBatch(x) {
this.batch = x;
}
hasCatch() {
return (0,_utils__WEBPACK_IMPORTED_MODULE_0__.detectIsFunction)(this.catch);
}
setCatch(x) {
this.catch = x;
}
setUpdate(x) {
this.update = x;
}
incrementPendings() {
this.pendings++;
}
getPendings() {
return this.pendings;
}
drop() {
const { atoms, 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 (atoms) {
for (const [_, cleanup] of atoms)
cleanup();
this.atoms = null;
}
}
}
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) {
factory[_component__WEBPACK_IMPORTED_MODULE_0__.$$inject] = {
token: $$memo,
shouldUpdate,
};
return factory;
}
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_3__ = __webpack_require__(/*! ../utils */ "./src/utils/utils.ts");
/* harmony import */ var _walk__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../walk */ "./src/walk/walk.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 && !(0,_view__WEBPACK_IMPORTED_MODULE_0__.hasElementFlag)(inst, _constants__WEBPACK_IMPORTED_MODULE_1__.Flag.SKIP_SCAN_OPT)) {
const { prevKeys, nextKeys, prevKeysMap, nextKeysMap, keyedFibersMap } = extractKeys(alt.child, nextChildren);
const flush = nextKeys.length === 0;
let size = Math.max(prevKeys.l