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