lithent 1.9.3 → 1.10.2

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