lithent 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lithent.mjs CHANGED
@@ -1,24 +1,64 @@
1
- const k = (e) => typeof e == "object" && !("resolve" in e), x = (e, t) => k(e) && e.type === t, pe = (e, t) => "ctor" in e ? e.ctor === (t == null ? void 0 : t.ctor) : e === (t == null ? void 0 : t.ctor), he = (e, t) => {
2
- var s, c;
3
- return k(e) && (t == null ? void 0 : t.type) === "fragment" && ((s = t == null ? void 0 : t.children) == null ? void 0 : s.length) === ((c = e == null ? void 0 : e.children) == null ? void 0 : c.length);
4
- }, ie = (e, t) => {
5
- var s, c;
6
- return k(e) && (t == null ? void 0 : t.type) === "element" && (t == null ? void 0 : t.tag) === e.tag && ((s = t == null ? void 0 : t.children) == null ? void 0 : s.length) === ((c = e == null ? void 0 : e.children) == null ? void 0 : c.length);
7
- }, U = (e, t) => k(e) && (t == null ? void 0 : t.type) === e.type && (e.type !== "loop" || e.type === "loop" && C(i((e.children || [])[0])) && C(i((t.children || [])[0]))), i = (e) => {
8
- var t, s;
9
- return ((t = e == null ? void 0 : e.compProps) == null ? void 0 : t.key) ?? ((s = e == null ? void 0 : e.props) == null ? void 0 : s.key);
10
- }, y = (e) => e && ["fragment", "loop"].includes(e), T = (e) => typeof e == "function" && !H(e) || typeof e == "object" && "resolve" in e, H = (e) => typeof e == "function" && e === re, J = (e) => k(e) && !e.type, C = (e) => e != null, z = (e, t) => e === "style" && typeof t == "object", ve = (e, t) => e === "ref" && typeof t == "object", ye = (e) => e.nodeType === 1 && e.tagName === "OPTION", Ce = (e) => e.nodeType === 1 && e.tagName === "TEXTAREA", ae = (e) => e.nodeType === 1 && ["radio", "checkbox"].includes(e.type), ke = (e) => {
11
- let t = "et";
12
- return T(e) ? t = "c" : x(e, "fragment") ? t = "f" : x(e, "element") ? t = "e" : x(e, "loop") ? t = "l" : x(e, "text") ? t = "t" : J(e) && (t = "et"), t;
13
- }, Re = {
14
- c: pe,
15
- l: U,
16
- t: U,
17
- e: ie,
18
- f: he,
19
- et: U
20
- }, p = (e) => e.getParent && e.getParent(), a = Object.entries, Y = Object.keys, S = Object.assign, v = { value: "" }, R = { value: {} }, A = { value: !1 }, u = /* @__PURE__ */ new WeakMap(), Ee = (e) => {
21
- u.set(e, {
1
+ const checkPlainWDomType = (wDom) => typeof wDom === "object" && !("resolve" in wDom);
2
+ const checkPlainType = (wDom, typeName) => checkPlainWDomType(wDom) && wDom.type === typeName;
3
+ const checkSameCustomComponent = (newWDom, originalWDom) => "ctor" in newWDom ? newWDom.ctor === (originalWDom == null ? void 0 : originalWDom.ctor) : newWDom === (originalWDom == null ? void 0 : originalWDom.ctor);
4
+ const checkSameFragment = (newWDom, originalWDom) => {
5
+ var _a, _b;
6
+ return checkPlainWDomType(newWDom) && (originalWDom == null ? void 0 : originalWDom.type) === "fragment" && ((_a = originalWDom == null ? void 0 : originalWDom.children) == null ? void 0 : _a.length) === ((_b = newWDom == null ? void 0 : newWDom.children) == null ? void 0 : _b.length);
7
+ };
8
+ const checkSameTagElement = (newWDom, originalWDom) => {
9
+ var _a, _b;
10
+ return checkPlainWDomType(newWDom) && (originalWDom == null ? void 0 : originalWDom.type) === "element" && (originalWDom == null ? void 0 : originalWDom.tag) === newWDom.tag && ((_a = originalWDom == null ? void 0 : originalWDom.children) == null ? void 0 : _a.length) === ((_b = newWDom == null ? void 0 : newWDom.children) == null ? void 0 : _b.length);
11
+ };
12
+ const checkNormalTypeElement = (newWDom, originalWDom) => checkPlainWDomType(newWDom) && (originalWDom == null ? void 0 : originalWDom.type) === newWDom.type && (newWDom.type !== "loop" || newWDom.type === "loop" && checkExisty(getKey((newWDom.children || [])[0])) && checkExisty(getKey((originalWDom.children || [])[0])));
13
+ const getKey = (target) => {
14
+ var _a, _b;
15
+ return ((_a = target == null ? void 0 : target.compProps) == null ? void 0 : _a.key) ?? ((_b = target == null ? void 0 : target.props) == null ? void 0 : _b.key);
16
+ };
17
+ const checkVirtualType = (type) => type && ["fragment", "loop"].includes(type);
18
+ const checkCustemComponentFunction = (target) => typeof target === "function" && !checkFragmentFunction(target) || typeof target === "object" && "resolve" in target;
19
+ const checkFragmentFunction = (target) => typeof target === "function" && target === Fragment;
20
+ const checkEmptyElement = (wDom) => checkPlainWDomType(wDom) && !wDom.type;
21
+ const checkExisty = (value) => value !== null && value !== void 0;
22
+ const checkStyleData = (dataKey, dataValue) => dataKey === "style" && typeof dataValue === "object";
23
+ const checkRefData = (dataKey, dataValue) => dataKey === "ref" && typeof dataValue === "object";
24
+ const checkOptionElement = (element) => element.nodeType === 1 && element.tagName === "OPTION";
25
+ const checkTextareaElement = (element) => element.nodeType === 1 && element.tagName === "TEXTAREA";
26
+ const checkCheckableElement = (element) => element.nodeType === 1 && ["radio", "checkbox"].includes(element.type);
27
+ const getWDomType = (wDom) => {
28
+ let result = "et";
29
+ if (checkCustemComponentFunction(wDom)) {
30
+ result = "c";
31
+ } else if (checkPlainType(wDom, "fragment")) {
32
+ result = "f";
33
+ } else if (checkPlainType(wDom, "element")) {
34
+ result = "e";
35
+ } else if (checkPlainType(wDom, "loop")) {
36
+ result = "l";
37
+ } else if (checkPlainType(wDom, "text")) {
38
+ result = "t";
39
+ } else if (checkEmptyElement(wDom)) {
40
+ result = "et";
41
+ }
42
+ return result;
43
+ };
44
+ const checkSameWDomWithOriginal = {
45
+ c: checkSameCustomComponent,
46
+ l: checkNormalTypeElement,
47
+ t: checkNormalTypeElement,
48
+ e: checkSameTagElement,
49
+ f: checkSameFragment,
50
+ et: checkNormalTypeElement
51
+ };
52
+ const getParent = (vDom) => vDom.getParent && vDom.getParent();
53
+ const entries = Object.entries;
54
+ const keys = Object.keys;
55
+ const assign = Object.assign;
56
+ const xmlnsRef = { value: "" };
57
+ const compKeyRef = { value: {} };
58
+ const needDiffRef = { value: false };
59
+ const componentRef = /* @__PURE__ */ new WeakMap();
60
+ const setComponetRef = (compKey) => {
61
+ componentRef.set(compKey, {
22
62
  vd: { value: null },
23
63
  up: () => {
24
64
  },
@@ -29,377 +69,770 @@ const k = (e) => typeof e == "object" && !("resolve" in e), x = (e, t) => k(e) &
29
69
  mts: [],
30
70
  umts: []
31
71
  });
32
- }, E = () => R.value, Z = (e, t) => u.get(e)[t], xe = (e) => R.value = e, Pe = (e) => {
33
- R.value = e, Ee(e);
34
- }, Te = (e) => {
35
- u.get(E()).umts.push(e);
36
- }, Q = (e) => {
37
- const { compKey: t } = e;
38
- t && Se(t), K(e);
39
- }, K = (e) => {
40
- (e.children || []).forEach((t) => {
41
- t.compKey ? Q(t) : K(t);
72
+ };
73
+ const getComponentKey = () => compKeyRef.value;
74
+ const getComponentSubInfo = (compKey, subKey) => componentRef.get(compKey)[subKey];
75
+ const initUpdateHookState = (compKey) => compKeyRef.value = compKey;
76
+ const initMountHookState = (compKey) => {
77
+ compKeyRef.value = compKey;
78
+ setComponetRef(compKey);
79
+ };
80
+ const unmount = (effectAction) => {
81
+ componentRef.get(getComponentKey()).umts.push(effectAction);
82
+ };
83
+ const runUnmountQueueFromWDom = (newWDom) => {
84
+ const { compKey } = newWDom;
85
+ if (compKey) {
86
+ removeItem(compKey);
87
+ }
88
+ recursiveRunUnmount(newWDom);
89
+ };
90
+ const recursiveRunUnmount = (wDom) => {
91
+ (wDom.children || []).forEach((item) => {
92
+ const childComKey = item.compKey;
93
+ if (childComKey) {
94
+ runUnmountQueueFromWDom(item);
95
+ } else {
96
+ recursiveRunUnmount(item);
97
+ }
42
98
  });
43
- }, Se = (e) => {
44
- const t = u.get(e);
45
- t && (t.umts.forEach((s) => s()), t.umts = [], u.delete(e));
46
- };
47
- let O = [];
48
- const B = () => {
49
- O.forEach((e) => be(e)), O = [];
50
- }, Ne = (e) => {
51
- e.compKey && O.push(e);
52
- }, rt = (e) => u.get(E()).mts.push(e), be = (e) => {
53
- const { compKey: t } = e;
54
- if (t) {
55
- const s = u.get(t), c = s == null ? void 0 : s.mts, n = s == null ? void 0 : s.upS;
56
- R.value = t, n && (n.value = 0), c && (s.mts = [], c.forEach((r) => {
57
- const o = r();
58
- o && Te(o);
59
- }));
60
- }
61
- }, G = (e, t = () => []) => {
62
- const s = u.get(E()), { upD: c, upS: n } = s, r = c[n.value];
63
- if (r && Ue(r, t())) {
64
- const o = e();
65
- o && s.upCB.push(o);
66
- }
67
- c[n.value] = t(), n.value += 1;
68
- }, Fe = (e) => {
69
- const { compKey: t } = e;
70
- if (t) {
71
- const s = u.get(t), c = s == null ? void 0 : s.upCB, n = s == null ? void 0 : s.upS;
72
- R.value = t, n && (n.value = 0), e.ctor && c && (s.upCB = [], c.forEach((r) => r()));
73
- }
74
- }, Ue = (e, t) => e.length ? e.some((s, c) => s !== t[c]) : !0, X = (e) => e === "className" ? "class" : e, V = (e) => e.replace(/^on(.*)/, (t, s) => s.toLowerCase()), g = () => new DocumentFragment(), $ = (e) => document.createElement(e), ot = (e, t, s) => {
75
- t ?? (t = document.body), e.isRoot = !0, e.wrapElement = t;
76
- const c = N(e);
77
- return s ? (e.afterElement = s, t.insertBefore(c, s)) : t.appendChild(c), B(), () => {
78
- var r;
79
- const n = (r = u.get(e.compProps || {})) == null ? void 0 : r.vd.value;
80
- n && (Q(n), I(n), Ae(n));
99
+ };
100
+ const removeItem = (compKey) => {
101
+ const subInfo = componentRef.get(compKey);
102
+ if (subInfo) {
103
+ subInfo.umts.forEach((effect) => effect());
104
+ subInfo.umts = [];
105
+ componentRef.delete(compKey);
106
+ }
107
+ };
108
+ let mountedQueue = [];
109
+ const execMountedQueue = () => {
110
+ mountedQueue.forEach((item) => runMountedQueueFromWDom(item));
111
+ mountedQueue = [];
112
+ };
113
+ const addMountedQueue = (wDom) => {
114
+ if (wDom.compKey) {
115
+ mountedQueue.push(wDom);
116
+ }
117
+ };
118
+ const mountCallback = (effectAction) => componentRef.get(getComponentKey()).mts.push(effectAction);
119
+ const runMountedQueueFromWDom = (newWDom) => {
120
+ const { compKey } = newWDom;
121
+ if (compKey) {
122
+ const component = componentRef.get(compKey);
123
+ const queue = component == null ? void 0 : component.mts;
124
+ const sequence = component == null ? void 0 : component.upS;
125
+ compKeyRef.value = compKey;
126
+ if (sequence) {
127
+ sequence.value = 0;
128
+ }
129
+ if (queue) {
130
+ component.mts = [];
131
+ queue.forEach((effect) => {
132
+ const callback = effect();
133
+ if (callback) {
134
+ unmount(callback);
135
+ }
136
+ });
137
+ }
138
+ }
139
+ };
140
+ const useUpdated = (effectAction, dependencies = () => []) => {
141
+ const component = componentRef.get(getComponentKey());
142
+ const { upD, upS } = component;
143
+ const def = upD[upS.value];
144
+ if (def && checkNeedPushQueue(def, dependencies())) {
145
+ const callback = effectAction();
146
+ if (callback) {
147
+ component.upCB.push(callback);
148
+ }
149
+ }
150
+ upD[upS.value] = dependencies();
151
+ upS.value += 1;
152
+ };
153
+ const runUpdatedQueueFromWDom = (newWDom) => {
154
+ const { compKey } = newWDom;
155
+ if (compKey) {
156
+ const component = componentRef.get(compKey);
157
+ const queue = component == null ? void 0 : component.upCB;
158
+ const sequence = component == null ? void 0 : component.upS;
159
+ compKeyRef.value = compKey;
160
+ if (sequence) {
161
+ sequence.value = 0;
162
+ }
163
+ if (newWDom.ctor && queue) {
164
+ component.upCB = [];
165
+ queue.forEach((effect) => effect());
166
+ }
167
+ }
168
+ };
169
+ const checkNeedPushQueue = (originalDefs, newDefs) => !originalDefs.length ? true : originalDefs.some((def, index) => def !== newDefs[index]);
170
+ const getAttrKey = (keyName) => keyName === "className" ? "class" : keyName;
171
+ const getEventName = (eventKey) => eventKey.replace(/^on(.*)/, (_match, p1) => p1.toLowerCase());
172
+ const DF = () => new DocumentFragment();
173
+ const CE = (t) => document.createElement(t);
174
+ const render = (wDom, wrapElement, afterElement) => {
175
+ wrapElement ?? (wrapElement = document.body);
176
+ wDom.isRoot = true;
177
+ wDom.wrapElement = wrapElement;
178
+ const Dom = wDomToDom(wDom);
179
+ if (afterElement) {
180
+ wDom.afterElement = afterElement;
181
+ wrapElement.insertBefore(Dom, afterElement);
182
+ } else {
183
+ wrapElement.appendChild(Dom);
184
+ }
185
+ execMountedQueue();
186
+ return () => {
187
+ var _a;
188
+ const component = (_a = componentRef.get(wDom.compProps || {})) == null ? void 0 : _a.vd.value;
189
+ if (component) {
190
+ runUnmountQueueFromWDom(component);
191
+ recursiveRemoveEvent(component);
192
+ rootDelete(component);
193
+ }
81
194
  };
82
- }, m = (e) => {
83
- const { needRerender: t } = e;
84
- t && t !== "N" && {
85
- A: q,
86
- D: j,
87
- R: Le,
88
- U: Me,
89
- SR: D,
90
- SU: Oe
91
- }[t](e);
92
- }, I = (e) => {
93
- e.props && e.el && te(e.props, e.el), (e.children || []).forEach((t) => {
94
- I(t);
195
+ };
196
+ const wDomUpdate = (newWDomTree) => {
197
+ const { needRerender } = newWDomTree;
198
+ if (needRerender && needRerender !== "N") {
199
+ ({
200
+ A: typeAdd,
201
+ D: typeDelete,
202
+ R: typeReplace,
203
+ U: typeUpdate,
204
+ SR: typeSortedReplace,
205
+ SU: typeSortedUpdate
206
+ })[needRerender](newWDomTree);
207
+ delete newWDomTree.needRerender;
208
+ }
209
+ };
210
+ const recursiveRemoveEvent = (originalWDom) => {
211
+ if (originalWDom.props && originalWDom.el) {
212
+ removeEvent(originalWDom.props, originalWDom.el);
213
+ }
214
+ (originalWDom.children || []).forEach((childItem) => {
215
+ recursiveRemoveEvent(childItem);
95
216
  });
96
- }, Ae = (e) => {
97
- w(e, e.wrapElement);
98
- }, j = (e) => {
99
- e.oldProps && e.el && te(e.oldProps, e.el), w(
100
- e,
101
- b(p(e))
217
+ };
218
+ const rootDelete = (newWDom) => {
219
+ deleteRealDom(newWDom, newWDom.wrapElement);
220
+ };
221
+ const typeDelete = (newWDom) => {
222
+ if (newWDom.oldProps && newWDom.el) {
223
+ removeEvent(newWDom.oldProps, newWDom.el);
224
+ }
225
+ deleteRealDom(
226
+ newWDom,
227
+ findRealParentElement(getParent(newWDom))
102
228
  );
103
- }, w = (e, t) => {
104
- var s, c;
105
- t && e.el && (((s = e.el) == null ? void 0 : s.nodeType) === 1 ? t.removeChild(e.el) : ((c = e.el) == null ? void 0 : c.nodeType) === 11 && W(e, t), delete e.el);
106
- }, W = (e, t) => {
107
- ((e == null ? void 0 : e.oldChildren) || (e == null ? void 0 : e.children) || []).forEach((s) => {
108
- var c, n;
109
- ((c = s.el) == null ? void 0 : c.nodeType) === 1 ? t.removeChild(s == null ? void 0 : s.el) : ((n = s.el) == null ? void 0 : n.nodeType) === 11 && W(s, t);
229
+ };
230
+ const deleteRealDom = (newWDom, parent) => {
231
+ var _a, _b;
232
+ if (parent && newWDom.el) {
233
+ if (((_a = newWDom.el) == null ? void 0 : _a.nodeType) === 1) {
234
+ parent.removeChild(newWDom.el);
235
+ } else if (((_b = newWDom.el) == null ? void 0 : _b.nodeType) === 11) {
236
+ findChildWithRemoveElement(newWDom, parent);
237
+ }
238
+ delete newWDom.el;
239
+ }
240
+ };
241
+ const findChildWithRemoveElement = (newWDom, parent) => {
242
+ ((newWDom == null ? void 0 : newWDom.oldChildren) || (newWDom == null ? void 0 : newWDom.children) || []).forEach((item) => {
243
+ var _a, _b;
244
+ if (((_a = item.el) == null ? void 0 : _a.nodeType) === 1) {
245
+ parent.removeChild(item == null ? void 0 : item.el);
246
+ } else if (((_b = item.el) == null ? void 0 : _b.nodeType) === 11) {
247
+ findChildWithRemoveElement(item, parent);
248
+ }
110
249
  });
111
- }, D = (e) => {
112
- j(e), q(e);
113
- }, Oe = (e) => {
114
- j(e), q(e, e.el);
115
- }, q = (e, t) => {
116
- t || (t = N(e));
117
- const s = p(e);
118
- if (s.type) {
119
- const c = b(s), r = s.type === "loop" ? L(s, p(s)) : L(e, s);
120
- t && c && (r ? c.insertBefore(t, r) : c.appendChild(t), B());
121
- }
122
- }, L = (e, t) => {
123
- const s = t.children || [], n = s.indexOf(e) + 1, r = s.slice(n), o = ee(r), l = t.type || "";
124
- if (o)
125
- return o;
126
- if (!t.isRoot && y(l))
127
- return L(t, p(t));
128
- if (t.isRoot && y(l) && t.afterElement)
129
- return t.afterElement;
130
- }, ee = (e) => e.reduce(
131
- (t, s) => {
132
- const c = s.type, n = s.el, r = c && y(c);
133
- return t || (r ? ee(s.children || []) : n && n.nodeType !== 11 ? n : t);
250
+ };
251
+ const typeSortedReplace = (newWDom) => {
252
+ typeDelete(newWDom);
253
+ typeAdd(newWDom);
254
+ };
255
+ const typeSortedUpdate = (newWDom) => {
256
+ typeDelete(newWDom);
257
+ typeAdd(newWDom, newWDom.el);
258
+ };
259
+ const typeAdd = (newWDom, newElement) => {
260
+ if (!newElement) {
261
+ newElement = wDomToDom(newWDom);
262
+ }
263
+ const parentWDom = getParent(newWDom);
264
+ if (parentWDom.type) {
265
+ const parentEl = findRealParentElement(parentWDom);
266
+ const isLoop = parentWDom.type === "loop";
267
+ const nextEl = isLoop && parentWDom.needRerender ? startFindNextBrotherElement(parentWDom, getParent(parentWDom)) : startFindNextBrotherElement(newWDom, parentWDom);
268
+ if (newElement && parentEl) {
269
+ if (nextEl) {
270
+ parentEl.insertBefore(newElement, nextEl);
271
+ } else {
272
+ parentEl.appendChild(newElement);
273
+ }
274
+ execMountedQueue();
275
+ }
276
+ }
277
+ };
278
+ const startFindNextBrotherElement = (wDom, parentWDom) => {
279
+ const brothers = parentWDom.children || [];
280
+ const index = brothers.indexOf(wDom);
281
+ const nextIndex = index + 1;
282
+ const candidiateBrothers = brothers.slice(nextIndex);
283
+ const finedNextEl = findChildFragmentNextElement(candidiateBrothers);
284
+ const parentType = parentWDom.type || "";
285
+ if (finedNextEl) {
286
+ return finedNextEl;
287
+ }
288
+ if (!parentWDom.isRoot && checkVirtualType(parentType)) {
289
+ return startFindNextBrotherElement(parentWDom, getParent(parentWDom));
290
+ } else if (parentWDom.isRoot && checkVirtualType(parentType) && parentWDom.afterElement) {
291
+ return parentWDom.afterElement;
292
+ }
293
+ return void 0;
294
+ };
295
+ const findChildFragmentNextElement = (candidiateBrothers) => candidiateBrothers.reduce(
296
+ (targetEl, bItem) => {
297
+ const type = bItem.type;
298
+ const el = bItem.el;
299
+ const isFragment = type && checkVirtualType(type);
300
+ if (targetEl) {
301
+ return targetEl;
302
+ } else if (isFragment) {
303
+ return findChildFragmentNextElement(bItem.children || []);
304
+ } else if (el && el.nodeType !== 11) {
305
+ return el;
306
+ }
307
+ return targetEl;
134
308
  },
135
309
  void 0
136
- ), Le = (e) => {
137
- const t = p(e), s = e.el;
138
- if (t.type && s)
139
- if (s.nodeType === 11)
140
- D(e);
141
- else {
142
- const c = b(t), n = N(e);
143
- c && c.replaceChild(n, s), B();
310
+ );
311
+ const typeReplace = (newWDom) => {
312
+ const parentWDom = getParent(newWDom);
313
+ const orignalElement = newWDom.el;
314
+ if (parentWDom.type && orignalElement) {
315
+ if (orignalElement.nodeType === 11) {
316
+ typeSortedReplace(newWDom);
317
+ } else {
318
+ const parentElement = findRealParentElement(parentWDom);
319
+ const newElement = wDomToDom(newWDom);
320
+ if (parentElement) {
321
+ parentElement.replaceChild(newElement, orignalElement);
322
+ }
323
+ execMountedQueue();
324
+ }
325
+ }
326
+ };
327
+ const removeEvent = (oldProps, element) => {
328
+ entries(oldProps || {}).forEach(([dataKey, dataValue]) => {
329
+ if (dataKey.match(/^on/)) {
330
+ element.removeEventListener(
331
+ getEventName(dataKey),
332
+ dataValue
333
+ );
144
334
  }
145
- }, te = (e, t) => {
146
- a(e || {}).forEach(([s, c]) => {
147
- s.match(/^on/) && t.removeEventListener(
148
- V(s),
149
- c
150
- );
151
335
  });
152
- }, Me = (e) => {
153
- var s;
154
- const t = e.el;
155
- if (e.type === "text") {
156
- Qe(e);
336
+ };
337
+ const typeUpdate = (newWDom) => {
338
+ var _a;
339
+ const element = newWDom.el;
340
+ if (newWDom.type === "text") {
341
+ updateText(newWDom);
157
342
  return;
158
343
  }
159
- if (t) {
160
- const { oldProps: c, props: n } = e;
161
- se(n, t, c), delete e.oldProps, e.tag === "input" && (t.value = String(((s = e == null ? void 0 : e.props) == null ? void 0 : s.value) || ""));
162
- }
163
- (e.children || []).forEach((c) => m(c)), Fe(e);
164
- }, Qe = (e) => {
165
- const t = e.el;
166
- t && (t.nodeValue = String(e.text));
167
- }, se = (e, t, s) => {
168
- const c = { ...s };
169
- a(e || {}).forEach(([n, r]) => {
170
- let o = !0;
171
- n === "key" || (n === "innerHTML" && typeof r == "string" ? t.innerHTML = r : z(n, r) ? qe(
172
- r,
173
- z(n, c.style) ? c.style : {},
174
- t
175
- ) : ve(n, r) ? r.value = t : n.match(/^on/) ? je(
176
- t,
177
- n,
178
- r,
179
- c[n]
180
- ) : ae(t) && n === "checked" ? t.checked = !!r : Ce(t) && n === "value" ? t.value = r : ye(t) && n === "selected" ? t.selected = !!r : n && ([o, r] = Be(r), o && (v.value && n !== "xmlns" ? t.setAttributeNS(
181
- null,
182
- X(n),
183
- r
184
- ) : t.setAttribute(
185
- X(n),
186
- r
187
- )))), o && delete c[n];
188
- }), Y(c).forEach(
189
- (n) => t.removeAttribute(n)
344
+ if (element) {
345
+ const { oldProps, props } = newWDom;
346
+ updateProps$1(props, element, oldProps);
347
+ delete newWDom.oldProps;
348
+ if (newWDom.tag === "input") {
349
+ element.value = String(((_a = newWDom == null ? void 0 : newWDom.props) == null ? void 0 : _a.value) || "");
350
+ }
351
+ }
352
+ (newWDom.children || []).forEach((childItem) => wDomUpdate(childItem));
353
+ runUpdatedQueueFromWDom(newWDom);
354
+ };
355
+ const updateText = (newWDom) => {
356
+ const element = newWDom.el;
357
+ if (element) {
358
+ element.nodeValue = String(newWDom.text);
359
+ }
360
+ };
361
+ const updateProps$1 = (props, element, oldProps) => {
362
+ const originalProps = { ...oldProps };
363
+ entries(props || {}).forEach(([dataKey, dataValue]) => {
364
+ let chkRemoveProp = true;
365
+ if (dataKey === "key")
366
+ ;
367
+ else if (dataKey === "innerHTML" && typeof dataValue === "string") {
368
+ element.innerHTML = dataValue;
369
+ } else if (checkStyleData(dataKey, dataValue)) {
370
+ updateStyle(
371
+ dataValue,
372
+ checkStyleData(dataKey, originalProps.style) ? originalProps.style : {},
373
+ element
374
+ );
375
+ } else if (checkRefData(dataKey, dataValue)) {
376
+ dataValue.value = element;
377
+ } else if (dataKey.match(/^on/)) {
378
+ updateEvent(
379
+ element,
380
+ dataKey,
381
+ dataValue,
382
+ originalProps[dataKey]
383
+ );
384
+ } else if (checkCheckableElement(element) && dataKey === "checked") {
385
+ element.checked = !!dataValue;
386
+ } else if (checkTextareaElement(element) && dataKey === "value") {
387
+ element.value = dataValue;
388
+ } else if (checkOptionElement(element) && dataKey === "selected") {
389
+ element.selected = !!dataValue;
390
+ } else if (dataKey) {
391
+ [chkRemoveProp, dataValue] = makeAttrDataValue(dataValue);
392
+ if (chkRemoveProp) {
393
+ if (xmlnsRef.value && dataKey !== "xmlns") {
394
+ element.setAttributeNS(
395
+ null,
396
+ getAttrKey(dataKey),
397
+ dataValue
398
+ );
399
+ } else {
400
+ element.setAttribute(
401
+ getAttrKey(dataKey),
402
+ dataValue
403
+ );
404
+ }
405
+ }
406
+ }
407
+ if (chkRemoveProp) {
408
+ delete originalProps[dataKey];
409
+ }
410
+ });
411
+ keys(originalProps).forEach(
412
+ (dataKey) => element.removeAttribute(dataKey)
190
413
  );
191
- }, Be = (e) => {
192
- let t = !0;
193
- return typeof e == "boolean" && (e || (t = !1), e = ""), [t, String(e)];
194
- }, N = (e) => {
195
- let t;
196
- const { type: s, tag: c, text: n, props: r, children: o = [] } = e, l = y(s);
197
- return c === "svg" && (v.value = String(r == null ? void 0 : r.xmlns)), l ? t = g() : s === "element" && c ? t = v.value ? document.createElementNS(v.value, c) : $(c) : s === "text" && C(n) ? t = document.createTextNode(String(n)) : t = $("e"), Ie(o, t), se(r, t), e.el = t, Ne(e), c === "svg" && (v.value = ""), t;
198
- }, Ie = (e, t) => {
199
- const s = e.reduce(
200
- (c, n) => (n.type && c.appendChild(N(n)), c),
201
- g()
414
+ };
415
+ const makeAttrDataValue = (dataValue) => {
416
+ let allowSetAttr = true;
417
+ if (typeof dataValue === "boolean") {
418
+ if (!dataValue) {
419
+ allowSetAttr = false;
420
+ }
421
+ dataValue = "";
422
+ }
423
+ return [allowSetAttr, String(dataValue)];
424
+ };
425
+ const wDomToDom = (wDom) => {
426
+ let element;
427
+ const { type, tag, text, props, children = [] } = wDom;
428
+ const isVirtualType = checkVirtualType(type);
429
+ if (tag === "svg") {
430
+ xmlnsRef.value = String(props == null ? void 0 : props.xmlns);
431
+ }
432
+ if (isVirtualType) {
433
+ element = DF();
434
+ } else if (type === "element" && tag) {
435
+ element = xmlnsRef.value ? document.createElementNS(xmlnsRef.value, tag) : CE(tag);
436
+ } else if (type === "text" && checkExisty(text)) {
437
+ element = document.createTextNode(String(text));
438
+ } else {
439
+ element = CE("e");
440
+ }
441
+ wDomChildrenToDom(children, element);
442
+ updateProps$1(props, element);
443
+ wDom.el = element;
444
+ addMountedQueue(wDom);
445
+ if (tag === "svg") {
446
+ xmlnsRef.value = "";
447
+ }
448
+ return element;
449
+ };
450
+ const wDomChildrenToDom = (children, parentElement) => {
451
+ const elementChildren = children.reduce(
452
+ (acc, childItem) => {
453
+ if (childItem.type) {
454
+ acc.appendChild(wDomToDom(childItem));
455
+ }
456
+ return acc;
457
+ },
458
+ DF()
202
459
  );
203
- t && s.hasChildNodes() && t.appendChild(s);
204
- }, je = (e, t, s, c) => {
205
- const n = V(t);
206
- c !== s && (c && e.removeEventListener(n, c), s && e.addEventListener(n, s));
207
- }, qe = (e, t, s) => {
208
- const c = { ...t }, n = s == null ? void 0 : s.style;
209
- n && (a(e).forEach(([r, o]) => {
210
- n[r] = o, delete c[r];
211
- }), a(c).forEach(
212
- ([r]) => n[r] = ""
213
- ));
214
- }, b = (e) => {
215
- const t = y(e.type);
216
- return e.isRoot && t ? e.wrapElement : t ? b(p(e)) : e.el;
217
- }, F = (e, t) => _e(
218
- e,
219
- Re[ke(e)](e, t),
220
- t
221
- ), _e = (e, t, s) => {
222
- const c = Je(e, t, s), n = [
223
- c,
224
- t,
225
- s
226
- ], r = Ge(...n);
227
- return c.children = Ye(...n), c.needRerender = r, ze(c, s, r), c;
228
- }, ze = (e, t, s) => {
229
- s !== "A" && t && (e.el = t.el), s && ["D", "R", "SR"].includes(s) && (t != null && t.compKey && (Q(t), I(t)), e.oldChildren = t == null ? void 0 : t.children), e.oldProps = t == null ? void 0 : t.props;
230
- }, Ge = (e, t, s) => {
231
- const c = s && s.type, n = J(e), o = !!e.getParent && p(e).type, l = i(e), h = o === "loop" && C(l), d = e.type === "text" && t && e.text === (s == null ? void 0 : s.text);
232
- let f;
233
- return n ? f = "D" : d ? f = "N" : c ? t ? f = h ? "SU" : "U" : f = h ? "SR" : "R" : f = "A", f;
234
- }, Xe = (e, t) => {
235
- e && t !== e && (Y(e).forEach((s) => delete e[s]), a(t || {}).forEach(([s, c]) => e[s] = c));
236
- }, $e = (e, t) => {
237
- e && t !== e && (e.splice(0, e.length), t && t.forEach((s) => e.push(s)));
238
- }, He = (e, t) => {
239
- const { compProps: s, compChild: c } = e, { props: n, children: r } = t;
240
- return s && Xe(s, n), c && $e(c, r), e.reRender && e.reRender();
241
- }, Je = (e, t, s) => T(e) ? t && s ? He(s, e) : e.resolve() : e, Ye = (e, t, s) => t && s ? Ke(e, s) : Ze(e), Ze = (e) => (e.children || []).map(
242
- (t) => S(F(t), { getParent: () => e })
243
- ), Ke = (e, t) => e.type === "loop" && C(i((e.children || [])[0])) ? Ve(e, t) : (e.children || []).map(
244
- (s, c) => S(F(s, (t.children || [])[c]), {
245
- getParent: () => e
460
+ if (parentElement && elementChildren.hasChildNodes()) {
461
+ parentElement.appendChild(elementChildren);
462
+ }
463
+ };
464
+ const updateEvent = (element, eventKey, newEventHandler, oldEventHandler) => {
465
+ const eventName = getEventName(eventKey);
466
+ if (oldEventHandler !== newEventHandler) {
467
+ if (oldEventHandler) {
468
+ element.removeEventListener(eventName, oldEventHandler);
469
+ }
470
+ if (newEventHandler) {
471
+ element.addEventListener(eventName, newEventHandler);
472
+ }
473
+ }
474
+ };
475
+ const updateStyle = (style, oldStyle, element) => {
476
+ const originalStyle = { ...oldStyle };
477
+ const elementStyle = element == null ? void 0 : element.style;
478
+ if (elementStyle) {
479
+ entries(style).forEach(([styleKey, dataValue]) => {
480
+ elementStyle[styleKey] = dataValue;
481
+ delete originalStyle[styleKey];
482
+ });
483
+ entries(originalStyle).forEach(
484
+ ([styleKey]) => elementStyle[styleKey] = ""
485
+ );
486
+ }
487
+ };
488
+ const findRealParentElement = (vDom) => {
489
+ const isVirtualType = checkVirtualType(vDom.type);
490
+ if (vDom.isRoot && isVirtualType) {
491
+ return vDom.wrapElement;
492
+ }
493
+ if (!isVirtualType) {
494
+ return vDom.el;
495
+ }
496
+ return findRealParentElement(getParent(vDom));
497
+ };
498
+ const makeNewWDomTree = (newWDom, originalWDom) => remakeNewWDom(
499
+ newWDom,
500
+ checkSameWDomWithOriginal[getWDomType(newWDom)](newWDom, originalWDom),
501
+ originalWDom
502
+ );
503
+ const remakeNewWDom = (newWDom, isSameType, originalWDom) => {
504
+ const remakeWDom = generalize(newWDom, isSameType, originalWDom);
505
+ const param = [
506
+ remakeWDom,
507
+ isSameType,
508
+ originalWDom
509
+ ];
510
+ const needRerender = addReRenderTypeProperty(...param);
511
+ remakeWDom.children = remakeChildrenForDiff(...param);
512
+ remakeWDom.needRerender = needRerender;
513
+ inheritPropForRender(remakeWDom, originalWDom, needRerender);
514
+ return remakeWDom;
515
+ };
516
+ const inheritPropForRender = (remakeWDom, originalWDom, needRerender) => {
517
+ if (needRerender !== "A" && originalWDom) {
518
+ remakeWDom.el = originalWDom.el;
519
+ }
520
+ if (needRerender && ["D", "R", "SR"].includes(needRerender)) {
521
+ if (originalWDom == null ? void 0 : originalWDom.compKey) {
522
+ runUnmountQueueFromWDom(originalWDom);
523
+ recursiveRemoveEvent(originalWDom);
524
+ }
525
+ remakeWDom.oldChildren = originalWDom == null ? void 0 : originalWDom.children;
526
+ }
527
+ remakeWDom.oldProps = originalWDom == null ? void 0 : originalWDom.props;
528
+ };
529
+ const addReRenderTypeProperty = (newWDom, isSameType, originalWDom) => {
530
+ var _a;
531
+ const existOriginalWDom = originalWDom && originalWDom.type;
532
+ const isEmptyElement = checkEmptyElement(newWDom);
533
+ const isRoot = newWDom.isRoot;
534
+ const origParentType = !isRoot && originalWDom && ((_a = getParent(originalWDom)) == null ? void 0 : _a.type);
535
+ const key = getKey(newWDom);
536
+ const isKeyCheckedWDom = origParentType === "loop" && checkExisty(key);
537
+ const isSameText = newWDom.type === "text" && isSameType && newWDom.text === (originalWDom == null ? void 0 : originalWDom.text);
538
+ let result;
539
+ if (isEmptyElement) {
540
+ result = "D";
541
+ } else if (isSameText) {
542
+ result = "N";
543
+ } else if (!existOriginalWDom) {
544
+ result = "A";
545
+ } else if (isSameType) {
546
+ result = isKeyCheckedWDom ? "SU" : "U";
547
+ } else {
548
+ result = isKeyCheckedWDom ? "SR" : "R";
549
+ }
550
+ return result;
551
+ };
552
+ const updateProps = (props, infoProps) => {
553
+ if (props && infoProps !== props) {
554
+ keys(props).forEach((key) => delete props[key]);
555
+ entries(infoProps || {}).forEach(([key, value]) => props[key] = value);
556
+ }
557
+ };
558
+ const updateChildren = (children, infoChidren) => {
559
+ if (children && infoChidren !== children) {
560
+ children.splice(0, children.length);
561
+ if (infoChidren) {
562
+ infoChidren.forEach((childrenItem) => children.push(childrenItem));
563
+ }
564
+ }
565
+ };
566
+ const runUpdate = (vDom, infoVdom) => {
567
+ const { compProps: props, compChild: children } = vDom;
568
+ const { props: infoProps, children: infoChidren } = infoVdom;
569
+ if (props) {
570
+ updateProps(props, infoProps);
571
+ }
572
+ if (children) {
573
+ updateChildren(children, infoChidren);
574
+ }
575
+ const newVDom = vDom.reRender && vDom.reRender();
576
+ return newVDom;
577
+ };
578
+ const generalize = (newWDom, isSameType, originalWDom) => {
579
+ if (checkCustemComponentFunction(newWDom)) {
580
+ return isSameType && originalWDom ? runUpdate(originalWDom, newWDom) : newWDom.resolve();
581
+ }
582
+ return newWDom;
583
+ };
584
+ const remakeChildrenForDiff = (newWDom, isSameType, originalWDom) => isSameType && originalWDom ? remakeChildrenForUpdate(newWDom, originalWDom) : remakeChildrenForAdd(newWDom);
585
+ const remakeChildrenForAdd = (newWDom) => (newWDom.children || []).map(
586
+ (item) => assign(makeNewWDomTree(item), { getParent: () => newWDom })
587
+ );
588
+ const remakeChildrenForUpdate = (newWDom, originalWDom) => newWDom.type === "loop" && checkExisty(getKey((newWDom.children || [])[0])) ? remakeChildrenForLoopUpdate(newWDom, originalWDom) : (newWDom.children || []).map(
589
+ (item, index) => assign(makeNewWDomTree(item, (originalWDom.children || [])[index]), {
590
+ getParent: () => newWDom
246
591
  })
247
- ), Ve = (e, t) => {
248
- const [s, c] = ge(
249
- e,
250
- t
592
+ );
593
+ const remakeChildrenForLoopUpdate = (newWDom, originalWDom) => {
594
+ const [remakedChildren, unUsedChildren] = diffLoopChildren(
595
+ newWDom,
596
+ originalWDom
251
597
  );
252
- return c.map((n) => {
253
- const r = n.el;
254
- r != null && r.parentNode && r.parentNode.removeChild(r);
255
- }), s;
256
- }, ge = (e, t) => {
257
- const s = [...e.children || []], c = [...t.children || []];
258
- return [s.map((r) => {
259
- const o = me(r, c), l = F(r, o);
260
- return o && c.splice(c.indexOf(o), 1), l.getParent = () => e, l;
261
- }), c];
262
- }, me = (e, t) => t.find(
263
- (s) => i(s) === i(e)
598
+ unUsedChildren.map((unusedItem) => typeDelete(unusedItem));
599
+ return remakedChildren;
600
+ };
601
+ const diffLoopChildren = (newWDom, originalWDom) => {
602
+ const newChildren = [...newWDom.children || []];
603
+ const originalChildren = [...originalWDom.children || []];
604
+ const remakedChildren = newChildren.map((item) => {
605
+ const originalItem = findSameKeyOriginalItem(item, originalChildren);
606
+ const childItem = makeNewWDomTree(item, originalItem);
607
+ if (originalItem) {
608
+ originalChildren.splice(originalChildren.indexOf(originalItem), 1);
609
+ }
610
+ childItem.getParent = () => newWDom;
611
+ return childItem;
612
+ });
613
+ return [remakedChildren, originalChildren];
614
+ };
615
+ const findSameKeyOriginalItem = (item, originalChildren) => originalChildren.find(
616
+ (orignalChildItem) => getKey(orignalChildItem) === getKey(item)
264
617
  );
265
- let P = [], M = !1;
266
- const ce = (e, t) => {
267
- u.get(e).up = () => {
268
- P.push({
269
- compKey: e,
270
- exec: t
271
- }), M || (M = !0, queueMicrotask(We));
618
+ let redrawQueue = [];
619
+ let redrawQueueTimeout = false;
620
+ const setRedrawAction = (compKey, exec) => {
621
+ componentRef.get(compKey).up = () => {
622
+ redrawQueue.push({
623
+ compKey,
624
+ exec
625
+ });
626
+ if (!redrawQueueTimeout) {
627
+ redrawQueueTimeout = true;
628
+ queueMicrotask(execRedrawQueue);
629
+ }
272
630
  };
273
- }, we = (e) => () => {
274
- var c;
275
- const t = (c = u.get(e)) == null ? void 0 : c.up;
276
- let s = !1;
277
- return t && (t(), s = !0), s;
278
- }, ne = (e, t) => {
279
- (e.children || []).forEach((s) => {
280
- const c = s.compKey;
281
- c && t.push(c), ne(s, t);
631
+ };
632
+ const componentUpdate = (compKey) => () => {
633
+ var _a;
634
+ const up = (_a = componentRef.get(compKey)) == null ? void 0 : _a.up;
635
+ let result = false;
636
+ if (up) {
637
+ up();
638
+ result = true;
639
+ }
640
+ return result;
641
+ };
642
+ const recursiveGetChildKeys = (wDom, result) => {
643
+ (wDom.children || []).forEach((item) => {
644
+ const childComKey = item.compKey;
645
+ if (childComKey) {
646
+ result.push(childComKey);
647
+ }
648
+ recursiveGetChildKeys(item, result);
282
649
  });
283
- }, We = () => {
284
- let e = [];
285
- P.forEach((c) => {
286
- var r, o;
287
- const n = (o = (r = u.get(c.compKey)) == null ? void 0 : r.vd) == null ? void 0 : o.value;
288
- n && ne(n, e);
650
+ };
651
+ const execRedrawQueue = () => {
652
+ let childItemList = [];
653
+ redrawQueue.forEach((item) => {
654
+ var _a, _b;
655
+ const childVd = (_b = (_a = componentRef.get(item.compKey)) == null ? void 0 : _a.vd) == null ? void 0 : _b.value;
656
+ if (childVd) {
657
+ recursiveGetChildKeys(childVd, childItemList);
658
+ }
289
659
  });
290
- const t = [], s = P.reduce((c, n) => {
291
- const { compKey: r } = n;
292
- return e.includes(r) || t.includes(r) || (t.push(r), c.push(n)), c;
660
+ const addedKey = [];
661
+ const result = redrawQueue.reduce((acc, item) => {
662
+ const { compKey } = item;
663
+ if (childItemList.includes(compKey) || addedKey.includes(compKey)) {
664
+ return acc;
665
+ }
666
+ addedKey.push(compKey);
667
+ acc.push(item);
668
+ return acc;
293
669
  }, []);
294
- for (; s.length; ) {
295
- const c = s.shift();
296
- c && c.exec();
297
- }
298
- P = [], M = !1;
299
- }, ut = (e, t = () => []) => {
300
- u.get(E()).upR.push(() => G(e, t)), G(e, t);
301
- }, De = () => {
302
- var t;
303
- const e = (t = u.get(E())) == null ? void 0 : t.upR;
304
- e != null && e.length && e.forEach((s) => s());
305
- }, re = (e, ...t) => ({
670
+ while (result.length) {
671
+ const action = result.shift();
672
+ if (action) {
673
+ action.exec();
674
+ }
675
+ }
676
+ redrawQueue = [];
677
+ redrawQueueTimeout = false;
678
+ };
679
+ const updateCallback = (effectAction, dependencies = () => []) => {
680
+ const updateReqs = componentRef.get(getComponentKey()).upR;
681
+ updateReqs.push(() => useUpdated(effectAction, dependencies));
682
+ useUpdated(effectAction, dependencies);
683
+ };
684
+ const runUpdateCallback = () => {
685
+ var _a;
686
+ const updateReqs = (_a = componentRef.get(getComponentKey())) == null ? void 0 : _a.upR;
687
+ if (updateReqs == null ? void 0 : updateReqs.length) {
688
+ updateReqs.forEach((callback) => callback());
689
+ }
690
+ };
691
+ const Fragment = (_props, ...children) => ({
306
692
  type: "fragment",
307
- children: t
308
- }), lt = (e, t, ...s) => {
309
- const c = { value: void 0 }, n = t || {}, r = fe(c, s), o = ct(e, n, r);
310
- return T(o) || (c.value = o), o;
311
- }, ft = (e) => (t, s) => e, oe = (e, t, s, c) => {
312
- var f;
313
- A.value = !0;
314
- const n = ue(e, t, s), r = F(n, c), { isRoot: o, getParent: l, wrapElement: h, afterElement: d } = c;
315
- if (r.getParent = l, !o && l) {
316
- const _ = ((f = l()) == null ? void 0 : f.children) || [], de = _.indexOf(c);
317
- _.splice(de, 1, r);
318
- } else
319
- r.isRoot = !0, r.wrapElement = h, r.afterElement = d;
320
- A.value = !1, m(r);
321
- }, ue = (e, t, s) => ({ tagName: e.name, ctor: e, props: t, children: s, resolve: (o = t) => {
322
- Pe(o);
323
- const h = e(t, s)(we(o), t, s), d = et(
324
- h,
325
- o,
326
- e,
327
- t,
328
- s
329
- ), f = d;
330
- return ce(
331
- o,
332
- () => oe(e, t, s, f)
333
- ), Z(o, "vd").value = d, d;
334
- } }), et = (e, t, s, c, n) => {
335
- const r = e(c);
336
- if (r.reRender)
693
+ children
694
+ });
695
+ const h = (tag, props, ...children) => {
696
+ const nodeParentPointer = { value: void 0 };
697
+ const newProps = props || {};
698
+ const newChildren = remakeChildren(nodeParentPointer, children);
699
+ const node = makeNode(tag, newProps, newChildren);
700
+ if (!checkCustemComponentFunction(node)) {
701
+ nodeParentPointer.value = node;
702
+ }
703
+ return node;
704
+ };
705
+ const mount = (component) => (_props, _children) => component;
706
+ const reRenderCustomComponent = (tag, props, children, originalWDom) => {
707
+ var _a;
708
+ needDiffRef.value = true;
709
+ const newWDom = makeWDomResolver(tag, props, children);
710
+ const newWDomTree = makeNewWDomTree(newWDom, originalWDom);
711
+ const { isRoot, getParent: getParent2, wrapElement, afterElement } = originalWDom;
712
+ newWDomTree.getParent = getParent2;
713
+ if (!isRoot && getParent2) {
714
+ const brothers = ((_a = getParent2()) == null ? void 0 : _a.children) || [];
715
+ const index = brothers.indexOf(originalWDom);
716
+ brothers.splice(index, 1, newWDomTree);
717
+ } else {
718
+ newWDomTree.isRoot = true;
719
+ newWDomTree.wrapElement = wrapElement;
720
+ newWDomTree.afterElement = afterElement;
721
+ }
722
+ needDiffRef.value = false;
723
+ wDomUpdate(newWDomTree);
724
+ };
725
+ const makeWDomResolver = (tag, props, children) => {
726
+ const tagName = tag.name;
727
+ const ctor = tag;
728
+ const resolve = (compKey = props) => {
729
+ initMountHookState(compKey);
730
+ const component = tag(props, children);
731
+ const componentMaker = component(componentUpdate(compKey), props, children);
732
+ const customNode = makeCustomNode(
733
+ componentMaker,
734
+ compKey,
735
+ tag,
736
+ props,
737
+ children
738
+ );
739
+ const originalWDom = customNode;
740
+ setRedrawAction(
741
+ compKey,
742
+ () => reRenderCustomComponent(tag, props, children, originalWDom)
743
+ );
744
+ getComponentSubInfo(compKey, "vd").value = customNode;
745
+ return customNode;
746
+ };
747
+ return { tagName, ctor, props, children, resolve };
748
+ };
749
+ const makeCustomNode = (componentMaker, compKey, tag, props, children) => {
750
+ const customNode = componentMaker(props);
751
+ if (customNode.reRender) {
337
752
  throw new Error(
338
753
  'Avoid the case where the first element of a component is a component. Instead of "mount(()=>()=><Component />)" replace it with something like "mount(()=>()=><Fragment><Component /></Fragment>)".'
339
754
  );
340
- return le(
341
- r,
342
- t,
343
- s,
344
- c,
345
- n,
346
- tt(e, t, s, c, n)
347
- ), r;
348
- }, tt = (e, t, s, c, n) => {
349
- const r = () => st(e, t, s, c, n, r);
350
- return r;
351
- }, st = (e, t, s, c, n, r) => {
352
- xe(t), De();
353
- const o = e(c);
354
- return ce(
355
- t,
356
- () => oe(s, c, n, o)
357
- ), le(o, t, s, c, n, r), Z(t, "vd").value = o, o;
358
- }, le = (e, t, s, c, n, r) => {
359
- S(e, {
360
- compProps: c,
361
- compChild: n,
362
- ctor: s,
363
- tagName: s.name,
364
- compKey: t,
365
- reRender: r
755
+ }
756
+ addComponentProps(
757
+ customNode,
758
+ compKey,
759
+ tag,
760
+ props,
761
+ children,
762
+ makeReRender(componentMaker, compKey, tag, props, children)
763
+ );
764
+ return customNode;
765
+ };
766
+ const makeReRender = (componentMaker, compKey, tag, props, children) => {
767
+ const reRender = () => wDomMaker(componentMaker, compKey, tag, props, children, reRender);
768
+ return reRender;
769
+ };
770
+ const wDomMaker = (componentMaker, compKey, tag, props, children, reRender) => {
771
+ initUpdateHookState(compKey);
772
+ runUpdateCallback();
773
+ const originalWDom = componentMaker(props);
774
+ setRedrawAction(
775
+ compKey,
776
+ () => reRenderCustomComponent(tag, props, children, originalWDom)
777
+ );
778
+ addComponentProps(originalWDom, compKey, tag, props, children, reRender);
779
+ getComponentSubInfo(compKey, "vd").value = originalWDom;
780
+ return originalWDom;
781
+ };
782
+ const addComponentProps = (wDom, compKey, tag, props, children, reRender) => {
783
+ assign(wDom, {
784
+ compProps: props,
785
+ compChild: children,
786
+ ctor: tag,
787
+ tagName: tag.name,
788
+ compKey,
789
+ reRender
366
790
  });
367
- }, ct = (e, t, s) => {
368
- if (H(e))
369
- return re(t, ...s);
370
- if (T(e)) {
371
- const c = ue(e, t, s);
372
- return A.value ? c : c.resolve();
791
+ };
792
+ const makeNode = (tag, props, children) => {
793
+ if (checkFragmentFunction(tag)) {
794
+ return Fragment(props, ...children);
795
+ } else if (checkCustemComponentFunction(tag)) {
796
+ const componetMakeResolver = makeWDomResolver(tag, props, children);
797
+ return needDiffRef.value ? componetMakeResolver : componetMakeResolver.resolve();
373
798
  }
374
799
  return {
375
800
  type: "element",
376
- tag: e,
377
- props: t,
378
- children: s
801
+ tag,
802
+ props,
803
+ children
379
804
  };
380
- }, fe = (e, t) => t.map(
381
- (s) => S(nt(s), { getParent: () => e.value })
382
- ), nt = (e) => {
383
- if (e == null || e === !1)
805
+ };
806
+ const remakeChildren = (nodeParentPointer, children) => children.map(
807
+ (item) => assign(makeChildrenItem(item), { getParent: () => nodeParentPointer.value })
808
+ );
809
+ const makeChildrenItem = (item) => {
810
+ if (item === null || item === void 0 || item === false) {
384
811
  return { type: null };
385
- if (Array.isArray(e)) {
386
- const t = { value: void 0 }, c = {
812
+ } else if (Array.isArray(item)) {
813
+ const nodeParentPointer = { value: void 0 };
814
+ const children = remakeChildren(nodeParentPointer, item);
815
+ const node = {
387
816
  type: "loop",
388
- children: fe(t, e)
817
+ children
389
818
  };
390
- return t.value = c, c;
391
- } else if (typeof e == "string" || typeof e == "number")
392
- return { type: "text", text: e };
393
- return e;
394
- }, dt = (e) => ({ value: e }), pt = () => Promise.resolve();
819
+ nodeParentPointer.value = node;
820
+ return node;
821
+ } else if (typeof item === "string" || typeof item === "number") {
822
+ return { type: "text", text: item };
823
+ }
824
+ return item;
825
+ };
826
+ const ref = (initValue) => ({ value: initValue });
827
+ const nextTick = () => Promise.resolve();
395
828
  export {
396
- re as Fragment,
397
- lt as h,
398
- ft as mount,
399
- rt as mountCallback,
400
- pt as nextTick,
401
- dt as ref,
402
- ot as render,
403
- ut as updateCallback
829
+ Fragment,
830
+ h,
831
+ mount,
832
+ mountCallback,
833
+ nextTick,
834
+ ref,
835
+ render,
836
+ updateCallback
404
837
  };
405
838
  //# sourceMappingURL=lithent.mjs.map