lithent 1.0.0 → 1.0.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 (47) hide show
  1. package/README.md +28 -17
  2. package/dist/lithent.mjs +135 -140
  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/predicator.d.ts +1 -0
  9. package/dist/utils/universalRef.d.ts +6 -6
  10. package/dist/wDom.d.ts +2 -2
  11. package/examples/dist/assets/index.1e9792b7.js +2 -0
  12. package/examples/dist/assets/index.1e9792b7.js.map +1 -0
  13. package/examples/dist/index.html +1 -1
  14. package/examples/src/index.tsx +1 -1
  15. package/examples/src/sharedStore.tsx +1 -1
  16. package/package.json +3 -2
  17. package/src/diff.ts +22 -24
  18. package/src/hook/mountCallback.ts +6 -6
  19. package/src/hook/unmount.ts +7 -7
  20. package/src/hook/useUpdate.ts +6 -6
  21. package/src/render.ts +51 -57
  22. package/src/tests/fragment.tsx +38 -0
  23. package/src/tests/loopWithoutKey.tsx +55 -0
  24. package/src/tests/{example17.tsx → test17.tsx} +1 -1
  25. package/src/types/index.ts +6 -6
  26. package/src/utils/index.ts +7 -5
  27. package/src/utils/predicator.ts +10 -2
  28. package/src/utils/universalRef.ts +23 -28
  29. package/src/wDom.ts +25 -30
  30. package/examples/dist/assets/index.2b484d3b.js +0 -2
  31. package/examples/dist/assets/index.2b484d3b.js.map +0 -1
  32. /package/src/tests/{example1.tsx → test1.tsx} +0 -0
  33. /package/src/tests/{example10.tsx → test10.tsx} +0 -0
  34. /package/src/tests/{example11.tsx → test11.tsx} +0 -0
  35. /package/src/tests/{example12.tsx → test12.tsx} +0 -0
  36. /package/src/tests/{example13.tsx → test13.tsx} +0 -0
  37. /package/src/tests/{example14.tsx → test14.tsx} +0 -0
  38. /package/src/tests/{example15.tsx → test15.tsx} +0 -0
  39. /package/src/tests/{example16.tsx → test16.tsx} +0 -0
  40. /package/src/tests/{example2.tsx → test2.tsx} +0 -0
  41. /package/src/tests/{example3.tsx → test3.tsx} +0 -0
  42. /package/src/tests/{example4.tsx → test4.tsx} +0 -0
  43. /package/src/tests/{example5.tsx → test5.tsx} +0 -0
  44. /package/src/tests/{example6.tsx → test6.tsx} +0 -0
  45. /package/src/tests/{example7.tsx → test7.tsx} +0 -0
  46. /package/src/tests/{example8.tsx → test8.tsx} +0 -0
  47. /package/src/tests/{example9.tsx → test9.tsx} +0 -0
package/README.md CHANGED
@@ -9,7 +9,7 @@ used lightly in a variety of situations.
9
9
  - https://superlucky84.github.io/lithent
10
10
  - (This guide page is written in lithent.)
11
11
 
12
- `(9.62 KiB / gzip: 3.58 KiB)`
12
+ `(9.58 KiB / gzip: 3.63 KiB)`
13
13
 
14
14
 
15
15
  ## 🚩 Table of Contents
@@ -25,18 +25,19 @@ used lightly in a variety of situations.
25
25
  - [With ESM](#with-esm)
26
26
  - [With UMD](#with-umd)
27
27
  - [Develop Guide](#develop-guide)
28
+ - [Test](#test)
28
29
 
29
30
  ## Why use Lithent?
30
31
 
31
32
  ### Lithent have the bare minimum of necessary functionality, with no unnecessary features.
32
33
 
33
- Since 'react' and 'vue', there have been a lot of UI libraries coming out that boast full-stack functionality.
34
+ In a real-world development environment, you may want to use Virtual DOM lightly, with only the bare minimum of core functionality.
34
35
 
35
- However, in the real world of development, there are times when you need to build something using only the bare minimum of key features, rather than a full-stack, full-featured library.
36
+ "Lithent" makes it easy to add, remove, and update virtual domes to specific parts of a pre-drawn SSR page.
36
37
 
37
- Lithent has implemented the bare minimum functionality needed to create and update virtual DOM in general (we only need to know 'render', 'mounter', 'updater', 'renewer', 'mountCallback', and 'updateCallback').
38
+ "Lithent" has implemented the bare minimum functionality needed to create and update virtual DOM in general (we only need to know 'render', 'mounter', 'updater', 'renewer', 'mountCallback', and 'updateCallback').
38
39
 
39
- We provide code in the form of 'helpers' that extend the basic functionality, but using the helpers is only optional and talented users can extend and develop custom helpers for their own projects.
40
+ We provide code in the form of 'helpers' that extend the basic functionality, but using the helpers is only optional and users can extend and develop custom helpers for their own projects.
40
41
 
41
42
  ### Approach with the developer-friendly concept of closures between "component mounter" and "renderer"
42
43
 
@@ -60,10 +61,10 @@ pnpm add lithent
60
61
 
61
62
  #### Or Use CDN
62
63
 
63
- * UMD : https://cdn.jsdelivr.net/npm/lithent@1.0.0/dist/lithent.umd.js
64
- * UMD-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.0.0/helper/dist/lithentHelper.umd.js
65
- * ESM : https://cdn.jsdelivr.net/npm/lithent@1.0.0/dist/lithent.mjs
66
- * ESM-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.0.0/helper/dist/lithentHelper.mjs
64
+ * UMD : https://cdn.jsdelivr.net/npm/lithent@1.0.1/dist/lithent.umd.js
65
+ * UMD-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.0.1/helper/dist/lithentHelper.umd.js
66
+ * ESM : https://cdn.jsdelivr.net/npm/lithent@1.0.1/dist/lithent.mjs
67
+ * ESM-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.0.1/helper/dist/lithentHelper.mjs
67
68
 
68
69
 
69
70
  It's easier to use lithent with JSX or HTM.
@@ -97,15 +98,17 @@ import { state } from 'lithent/helper';
97
98
  import htm from 'htm';
98
99
  const html = htm.bind(h);
99
100
 
100
- const Component = mount((r, _props) => {
101
- const count = state(0, r);
101
+ const Component = mount((renew, _props) => {
102
+ const count = state(0, renew);
102
103
 
103
- const change = () => (count.v += 1);
104
+ const change = () => {
105
+ count.value += 1;
106
+ };
104
107
 
105
108
  // Updater
106
109
  return () => html`
107
110
  <${Fragment}>
108
- <li>count: ${count.v}</li>
111
+ <li>count: ${count.value}</li>
109
112
  <button onClick=${change}>increase</button>
110
113
  <//>
111
114
  `;
@@ -115,14 +118,14 @@ const Component = mount((r, _props) => {
115
118
  // render(`<${Component} />`, document.getElementById('root'), document.getElementById('nextElement'));
116
119
 
117
120
  // appendChild
118
- render(html`<${Component} />`, document.getElementById('root'));
121
+ const destroy = render(html`<${Component} />`, document.getElementById('root'));
119
122
  ```
120
123
 
121
124
  #### With UMD
122
125
 
123
126
  ```html
124
- <script src="https://cdn.jsdelivr.net/npm/lithent@1.0.0/dist/lithent.umd.js"></script>
125
- <!--script src="https://cdn.jsdelivr.net/npm/lithent@1.0.0/helper/dist/lithentHelper.umd.js"></script-->
127
+ <script src="https://cdn.jsdelivr.net/npm/lithent@1.0.1/dist/lithent.umd.js"></script>
128
+ <!--script src="https://cdn.jsdelivr.net/npm/lithent@1.0.1/helper/dist/lithentHelper.umd.js"></script-->
126
129
  <script src="https://cdnjs.cloudflare.com/ajax/libs/htm/3.1.1/htm.js"></script>
127
130
 
128
131
  <div id="root"></div>
@@ -149,7 +152,7 @@ const Component = mount(renew => {
149
152
  `;
150
153
  });
151
154
 
152
- render(html`<${Component} />`, document.getElementById('root'));
155
+ const destroy = render(html`<${Component} />`, document.getElementById('root'));
153
156
  </script>
154
157
  ```
155
158
 
@@ -184,3 +187,11 @@ pnpm build
184
187
  ```bash
185
188
  pnpm dev // or pnpm dev:core
186
189
  ```
190
+
191
+ ## Test
192
+
193
+ ```bash
194
+ // pnpm install
195
+ pnpm test
196
+ ```
197
+
package/dist/lithent.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  const checkPlainWDomType = (wDom) => typeof wDom === "object" && !("resolve" in wDom);
2
2
  const checkPlainType = (wDom, typeName) => checkPlainWDomType(wDom) && wDom.type === typeName;
3
- const checkSameCustomComponent = (newWDom, originalWDom) => newWDom.constructor === (originalWDom == null ? void 0 : originalWDom.constructor);
3
+ const checkSameCustomComponent = (newWDom, originalWDom) => "ctor" in newWDom ? newWDom.ctor === (originalWDom == null ? void 0 : originalWDom.ctor) : newWDom === (originalWDom == null ? void 0 : originalWDom.ctor);
4
4
  const checkSameFragment = (newWDom, originalWDom) => {
5
5
  var _a, _b;
6
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);
@@ -11,7 +11,11 @@ const checkSameTagElement = (newWDom, originalWDom) => {
11
11
  };
12
12
  const checkNormalTypeElement = (newWDom, originalWDom) => {
13
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");
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.compProps) == null ? void 0 : _a.key) != null ? _c : (_b = target == null ? void 0 : target.props) == null ? void 0 : _b.key;
15
19
  };
16
20
  const checkVirtualType = (type) => type && ["fragment", "loop"].includes(type);
17
21
  const checkCustemComponentFunction = (target) => typeof target === "function" && !checkFragmentFunction(target) || typeof target === "object" && "resolve" in target;
@@ -54,7 +58,7 @@ const getParent = (vDom) => {
54
58
  return parentVDom;
55
59
  };
56
60
  const reRender = (vDom, infoVdom) => {
57
- const { componentProps: props, componentChildren: children } = vDom;
61
+ const { compProps: props, compChild: children } = vDom;
58
62
  const { props: infoProps, children: infoChidren } = infoVdom;
59
63
  if (props) {
60
64
  updateProps$1(props, infoProps);
@@ -67,12 +71,13 @@ const reRender = (vDom, infoVdom) => {
67
71
  };
68
72
  const getEventName = (eventKey) => eventKey.replace(/^on(.*)/, (_match, p1) => p1.toLowerCase());
69
73
  const getAttrKey = (keyName) => keyName === "className" ? "class" : keyName;
74
+ const entries = Object.entries;
75
+ const keys = Object.keys;
76
+ const assign = Object.assign;
70
77
  const updateProps$1 = (props, infoProps) => {
71
78
  if (props && infoProps !== props) {
72
- Object.keys(props).forEach((key) => delete props[key]);
73
- Object.entries(infoProps || {}).forEach(
74
- ([key, value]) => props[key] = value
75
- );
79
+ keys(props).forEach((key) => delete props[key]);
80
+ entries(infoProps || {}).forEach(([key, value]) => props[key] = value);
76
81
  }
77
82
  };
78
83
  const updateChildren = (children, infoChidren) => {
@@ -86,12 +91,12 @@ const updateChildren = (children, infoChidren) => {
86
91
  let redrawQueue = [];
87
92
  let redrawQueueTimeout = false;
88
93
  const xmlnsRef = { value: "" };
89
- const componentKeyRef = { value: {} };
94
+ const compKeyRef = { value: {} };
90
95
  const needDiffRef = { value: false };
91
96
  const componentRef = /* @__PURE__ */ new WeakMap();
92
- const componentRender = (componentKey) => () => {
97
+ const componentRender = (compKey) => () => {
93
98
  var _a;
94
- const up = (_a = componentRef.get(componentKey)) == null ? void 0 : _a.up;
99
+ const up = (_a = componentRef.get(compKey)) == null ? void 0 : _a.up;
95
100
  let result = false;
96
101
  if (up) {
97
102
  up();
@@ -99,8 +104,8 @@ const componentRender = (componentKey) => () => {
99
104
  }
100
105
  return result;
101
106
  };
102
- const setComponetRef = (componentKey) => {
103
- componentRef.set(componentKey, {
107
+ const setComponetRef = (compKey) => {
108
+ componentRef.set(compKey, {
104
109
  vd: { value: null },
105
110
  up: () => {
106
111
  },
@@ -112,12 +117,12 @@ const setComponetRef = (componentKey) => {
112
117
  umts: []
113
118
  });
114
119
  };
115
- const getComponentKey = () => componentKeyRef.value;
116
- const getComponentSubInfo = (componentKey, subKey) => componentRef.get(componentKey)[subKey];
117
- const setRedrawAction = (componentKey, exec) => {
118
- componentRef.get(componentKey).up = () => {
120
+ const getComponentKey = () => compKeyRef.value;
121
+ const getComponentSubInfo = (compKey, subKey) => componentRef.get(compKey)[subKey];
122
+ const setRedrawAction = (compKey, exec) => {
123
+ componentRef.get(compKey).up = () => {
119
124
  redrawQueue.push({
120
- componentKey,
125
+ compKey,
121
126
  exec
122
127
  });
123
128
  if (!redrawQueueTimeout) {
@@ -126,14 +131,14 @@ const setRedrawAction = (componentKey, exec) => {
126
131
  }
127
132
  };
128
133
  };
129
- const initUpdateHookState = (componentKey) => componentKeyRef.value = componentKey;
130
- const initMountHookState = (componentKey) => {
131
- componentKeyRef.value = componentKey;
132
- setComponetRef(componentKey);
134
+ const initUpdateHookState = (compKey) => compKeyRef.value = compKey;
135
+ const initMountHookState = (compKey) => {
136
+ compKeyRef.value = compKey;
137
+ setComponetRef(compKey);
133
138
  };
134
139
  const recursiveGetChildKeys = (wDom, result) => {
135
140
  (wDom.children || []).forEach((item) => {
136
- const childComKey = item.componentKey;
141
+ const childComKey = item.compKey;
137
142
  if (childComKey) {
138
143
  result.push(childComKey);
139
144
  }
@@ -144,18 +149,18 @@ const execRedrawQueue = () => {
144
149
  let childItemList = [];
145
150
  redrawQueue.forEach((item) => {
146
151
  var _a, _b;
147
- const childVd = (_b = (_a = componentRef.get(item.componentKey)) == null ? void 0 : _a.vd) == null ? void 0 : _b.value;
152
+ const childVd = (_b = (_a = componentRef.get(item.compKey)) == null ? void 0 : _a.vd) == null ? void 0 : _b.value;
148
153
  if (childVd) {
149
154
  recursiveGetChildKeys(childVd, childItemList);
150
155
  }
151
156
  });
152
157
  const addedKey = [];
153
158
  const result = redrawQueue.reduce((acc, item) => {
154
- const { componentKey } = item;
155
- if (childItemList.includes(componentKey) || addedKey.includes(componentKey)) {
159
+ const { compKey } = item;
160
+ if (childItemList.includes(compKey) || addedKey.includes(compKey)) {
156
161
  return acc;
157
162
  }
158
- addedKey.push(componentKey);
163
+ addedKey.push(compKey);
159
164
  acc.push(item);
160
165
  return acc;
161
166
  }, []);
@@ -172,15 +177,15 @@ const unmount = (effectAction) => {
172
177
  componentRef.get(getComponentKey()).umts.push(effectAction);
173
178
  };
174
179
  const runUnmountQueueFromWDom = (newWDom) => {
175
- const { componentKey } = newWDom;
176
- if (componentKey) {
177
- removeItem(componentKey);
180
+ const { compKey } = newWDom;
181
+ if (compKey) {
182
+ removeItem(compKey);
178
183
  }
179
184
  recursiveRunUnmount(newWDom);
180
185
  };
181
186
  const recursiveRunUnmount = (wDom) => {
182
187
  (wDom.children || []).forEach((item) => {
183
- const childComKey = item.componentKey;
188
+ const childComKey = item.compKey;
184
189
  if (childComKey) {
185
190
  runUnmountQueueFromWDom(item);
186
191
  } else {
@@ -188,12 +193,12 @@ const recursiveRunUnmount = (wDom) => {
188
193
  }
189
194
  });
190
195
  };
191
- const removeItem = (componentKey) => {
192
- const subInfo = componentRef.get(componentKey);
196
+ const removeItem = (compKey) => {
197
+ const subInfo = componentRef.get(compKey);
193
198
  if (subInfo) {
194
199
  subInfo.umts.forEach((effect) => effect());
195
200
  subInfo.umts = [];
196
- componentRef.delete(componentKey);
201
+ componentRef.delete(compKey);
197
202
  }
198
203
  };
199
204
  let mountedQueue = [];
@@ -202,18 +207,18 @@ const execMountedQueue = () => {
202
207
  mountedQueue = [];
203
208
  };
204
209
  const addMountedQueue = (wDom) => {
205
- if (wDom.componentKey) {
210
+ if (wDom.compKey) {
206
211
  mountedQueue.push(wDom);
207
212
  }
208
213
  };
209
214
  const mountCallback = (effectAction) => componentRef.get(getComponentKey()).mts.push(effectAction);
210
215
  const runMountedQueueFromWDom = (newWDom) => {
211
- const { componentKey } = newWDom;
212
- if (componentKey) {
213
- const component = componentRef.get(componentKey);
216
+ const { compKey } = newWDom;
217
+ if (compKey) {
218
+ const component = componentRef.get(compKey);
214
219
  const queue = component == null ? void 0 : component.mts;
215
220
  const sequence = component == null ? void 0 : component.upS;
216
- componentKeyRef.value = componentKey;
221
+ compKeyRef.value = compKey;
217
222
  if (sequence) {
218
223
  sequence.value = 0;
219
224
  }
@@ -242,16 +247,16 @@ const useUpdated = (effectAction, dependencies = () => []) => {
242
247
  upS.value += 1;
243
248
  };
244
249
  const runUpdatedQueueFromWDom = (newWDom) => {
245
- const { componentKey } = newWDom;
246
- if (componentKey) {
247
- const component = componentRef.get(componentKey);
250
+ const { compKey } = newWDom;
251
+ if (compKey) {
252
+ const component = componentRef.get(compKey);
248
253
  const queue = component == null ? void 0 : component.upCB;
249
254
  const sequence = component == null ? void 0 : component.upS;
250
- componentKeyRef.value = componentKey;
255
+ compKeyRef.value = compKey;
251
256
  if (sequence) {
252
257
  sequence.value = 0;
253
258
  }
254
- if (newWDom.constructor && queue) {
259
+ if (newWDom.ctor && queue) {
255
260
  component.upCB = [];
256
261
  queue.forEach((effect) => effect());
257
262
  }
@@ -272,7 +277,7 @@ const render = (wDom, wrapElement, afterElement) => {
272
277
  execMountedQueue();
273
278
  return () => {
274
279
  var _a;
275
- const component = (_a = componentRef.get(wDom.componentProps || {})) == null ? void 0 : _a.vd.value;
280
+ const component = (_a = componentRef.get(wDom.compProps || {})) == null ? void 0 : _a.vd.value;
276
281
  if (component) {
277
282
  runUnmountQueueFromWDom(component);
278
283
  recursiveRemoveEvent(component);
@@ -411,16 +416,14 @@ const typeReplace = (newWDom) => {
411
416
  }
412
417
  };
413
418
  const removeEvent = (oldProps, element) => {
414
- Object.entries(oldProps || {}).forEach(
415
- ([dataKey, dataValue]) => {
416
- if (dataKey.match(/^on/)) {
417
- element.removeEventListener(
418
- getEventName(dataKey),
419
- dataValue
420
- );
421
- }
419
+ entries(oldProps || {}).forEach(([dataKey, dataValue]) => {
420
+ if (dataKey.match(/^on/)) {
421
+ element.removeEventListener(
422
+ getEventName(dataKey),
423
+ dataValue
424
+ );
422
425
  }
423
- );
426
+ });
424
427
  };
425
428
  const typeUpdate = (newWDom) => {
426
429
  var _a;
@@ -448,51 +451,49 @@ const updateText = (newWDom) => {
448
451
  };
449
452
  const updateProps = (props, element, oldProps) => {
450
453
  const originalProps = { ...oldProps };
451
- Object.entries(props || {}).forEach(
452
- ([dataKey, dataValue]) => {
453
- if (dataKey === "key")
454
- ;
455
- else if (dataKey === "innerHTML" && typeof dataValue === "string") {
456
- element.innerHTML = dataValue;
457
- } else if (checkStyleData(dataKey, dataValue)) {
458
- updateStyle(
459
- dataValue,
460
- checkStyleData(dataKey, originalProps.style) ? originalProps.style : {},
461
- element
454
+ entries(props || {}).forEach(([dataKey, dataValue]) => {
455
+ if (dataKey === "key")
456
+ ;
457
+ else if (dataKey === "innerHTML" && typeof dataValue === "string") {
458
+ element.innerHTML = dataValue;
459
+ } else if (checkStyleData(dataKey, dataValue)) {
460
+ updateStyle(
461
+ dataValue,
462
+ checkStyleData(dataKey, originalProps.style) ? originalProps.style : {},
463
+ element
464
+ );
465
+ } else if (checkRefData(dataKey, dataValue)) {
466
+ dataValue.value = element;
467
+ } else if (dataKey.match(/^on/)) {
468
+ updateEvent(
469
+ element,
470
+ dataKey,
471
+ dataValue,
472
+ originalProps[dataKey]
473
+ );
474
+ } else if (checkCheckableElement(element) && dataKey === "checked") {
475
+ element.checked = !!dataValue;
476
+ } else if (checkTextareaElement(element) && dataKey === "value") {
477
+ element.value = dataValue;
478
+ } else if (checkOptionElement(element) && dataKey === "selected") {
479
+ element.selected = !!dataValue;
480
+ } else if (checkNormalAttribute(dataValue)) {
481
+ if (xmlnsRef.value && dataKey !== "xmlns") {
482
+ element.setAttributeNS(
483
+ null,
484
+ getAttrKey(dataKey),
485
+ String(dataValue)
462
486
  );
463
- } else if (checkRefData(dataKey, dataValue)) {
464
- dataValue.value = element;
465
- } else if (dataKey.match(/^on/)) {
466
- updateEvent(
467
- element,
468
- dataKey,
469
- dataValue,
470
- originalProps[dataKey]
487
+ } else {
488
+ element.setAttribute(
489
+ getAttrKey(dataKey),
490
+ String(dataValue)
471
491
  );
472
- } else if (checkCheckableElement(element) && dataKey === "checked") {
473
- element.checked = !!dataValue;
474
- } else if (checkTextareaElement(element) && dataKey === "value") {
475
- element.value = dataValue;
476
- } else if (checkOptionElement(element) && dataKey === "selected") {
477
- element.selected = !!dataValue;
478
- } else if (checkNormalAttribute(dataValue)) {
479
- if (xmlnsRef.value && dataKey !== "xmlns") {
480
- element.setAttributeNS(
481
- null,
482
- getAttrKey(dataKey),
483
- String(dataValue)
484
- );
485
- } else {
486
- element.setAttribute(
487
- getAttrKey(dataKey),
488
- String(dataValue)
489
- );
490
- }
491
492
  }
492
- delete originalProps[dataKey];
493
493
  }
494
- );
495
- Object.keys(originalProps).forEach(
494
+ delete originalProps[dataKey];
495
+ });
496
+ keys(originalProps).forEach(
496
497
  (dataKey) => element.removeAttribute(dataKey)
497
498
  );
498
499
  };
@@ -550,11 +551,11 @@ const updateStyle = (style, oldStyle, element) => {
550
551
  const originalStyle = { ...oldStyle };
551
552
  const elementStyle = element == null ? void 0 : element.style;
552
553
  if (elementStyle) {
553
- Object.entries(style).forEach(([styleKey, dataValue]) => {
554
+ entries(style).forEach(([styleKey, dataValue]) => {
554
555
  elementStyle[styleKey] = dataValue;
555
556
  delete originalStyle[styleKey];
556
557
  });
557
- Object.entries(originalStyle).forEach(
558
+ entries(originalStyle).forEach(
558
559
  ([styleKey]) => elementStyle[styleKey] = ""
559
560
  );
560
561
  }
@@ -576,27 +577,29 @@ const makeNewWDomTree = (newWDom, originalWDom) => remakeNewWDom(
576
577
  );
577
578
  const remakeNewWDom = (newWDom, isSameType, originalWDom) => {
578
579
  const remakeWDom = generalize(newWDom, isSameType, originalWDom);
579
- remakeWDom.children = remakeChildrenForDiff(
580
+ const param = [
580
581
  remakeWDom,
581
582
  isSameType,
582
583
  originalWDom
583
- );
584
- const needRerender = addReRenderTypeProperty(
585
- remakeWDom,
586
- isSameType,
587
- originalWDom
588
- );
584
+ ];
585
+ const needRerender = addReRenderTypeProperty(...param);
586
+ remakeWDom.children = remakeChildrenForDiff(...param);
589
587
  remakeWDom.needRerender = needRerender;
588
+ inheritPropForRender(remakeWDom, originalWDom, needRerender);
589
+ return remakeWDom;
590
+ };
591
+ const inheritPropForRender = (remakeWDom, originalWDom, needRerender) => {
590
592
  if (needRerender !== "A" && originalWDom) {
591
593
  remakeWDom.el = originalWDom.el;
592
594
  }
593
- if (needRerender && ["D", "R", "SR"].includes(needRerender) && (originalWDom == null ? void 0 : originalWDom.componentKey)) {
594
- runUnmountQueueFromWDom(originalWDom);
595
- recursiveRemoveEvent(originalWDom);
596
- remakeWDom.oldChildren = originalWDom.children;
595
+ if (needRerender && ["D", "R", "SR"].includes(needRerender)) {
596
+ if (originalWDom == null ? void 0 : originalWDom.compKey) {
597
+ runUnmountQueueFromWDom(originalWDom);
598
+ recursiveRemoveEvent(originalWDom);
599
+ }
600
+ remakeWDom.oldChildren = originalWDom == null ? void 0 : originalWDom.children;
597
601
  }
598
602
  remakeWDom.oldProps = originalWDom == null ? void 0 : originalWDom.props;
599
- return remakeWDom;
600
603
  };
601
604
  const addReRenderTypeProperty = (newWDom, isSameType, originalWDom) => {
602
605
  const existOriginalWDom = originalWDom && originalWDom.type;
@@ -675,10 +678,6 @@ const diffLoopChildren = (newWDom, originalWDom) => {
675
678
  const findSameKeyOriginalItem = (item, originalChildren) => originalChildren.find(
676
679
  (orignalChildItem) => getKey(orignalChildItem) === getKey(item)
677
680
  );
678
- const getKey = (target) => {
679
- var _a, _b, _c;
680
- 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;
681
- };
682
681
  const updateCallback = (effectAction, dependencies = () => []) => {
683
682
  const updateReqs = componentRef.get(getComponentKey()).upR;
684
683
  updateReqs.push(() => useUpdated(effectAction, dependencies));
@@ -727,67 +726,63 @@ const reRenderCustomComponent = (tag, props, children, originalWDom) => {
727
726
  };
728
727
  const makeWDomResolver = (tag, props, children) => {
729
728
  const tagName = tag.name;
730
- const constructor = tag;
731
- const resolve = (componentKey = props) => {
732
- initMountHookState(componentKey);
729
+ const ctor = tag;
730
+ const resolve = (compKey = props) => {
731
+ initMountHookState(compKey);
733
732
  const component = tag(props, children);
734
- const componentMaker = component(
735
- componentRender(componentKey),
736
- props,
737
- children
738
- );
733
+ const componentMaker = component(componentRender(compKey), props, children);
739
734
  const customNode = makeCustomNode(
740
735
  componentMaker,
741
- componentKey,
736
+ compKey,
742
737
  tag,
743
738
  props,
744
739
  children
745
740
  );
746
741
  const originalWDom = customNode;
747
742
  setRedrawAction(
748
- componentKey,
743
+ compKey,
749
744
  () => reRenderCustomComponent(tag, props, children, originalWDom)
750
745
  );
751
- getComponentSubInfo(componentKey, "vd").value = customNode;
746
+ getComponentSubInfo(compKey, "vd").value = customNode;
752
747
  return customNode;
753
748
  };
754
- return { tagName, constructor, props, children, resolve };
749
+ return { tagName, ctor, props, children, resolve };
755
750
  };
756
- const makeCustomNode = (componentMaker, componentKey, tag, props, children) => {
751
+ const makeCustomNode = (componentMaker, compKey, tag, props, children) => {
757
752
  const customNode = componentMaker(props);
758
753
  addComponentProps(
759
754
  customNode,
760
- componentKey,
755
+ compKey,
761
756
  tag,
762
757
  props,
763
758
  children,
764
- makeReRender(componentMaker, componentKey, tag, props, children)
759
+ makeReRender(componentMaker, compKey, tag, props, children)
765
760
  );
766
761
  return customNode;
767
762
  };
768
- const makeReRender = (componentMaker, componentKey, tag, props, children) => {
769
- const reRender2 = () => wDomMaker(componentMaker, componentKey, tag, props, children, reRender2);
763
+ const makeReRender = (componentMaker, compKey, tag, props, children) => {
764
+ const reRender2 = () => wDomMaker(componentMaker, compKey, tag, props, children, reRender2);
770
765
  return reRender2;
771
766
  };
772
- const wDomMaker = (componentMaker, componentKey, tag, props, children, reRender2) => {
773
- initUpdateHookState(componentKey);
767
+ const wDomMaker = (componentMaker, compKey, tag, props, children, reRender2) => {
768
+ initUpdateHookState(compKey);
774
769
  runUpdateCallback();
775
770
  const originalWDom = componentMaker(props);
776
771
  setRedrawAction(
777
- componentKey,
772
+ compKey,
778
773
  () => reRenderCustomComponent(tag, props, children, originalWDom)
779
774
  );
780
- addComponentProps(originalWDom, componentKey, tag, props, children, reRender2);
781
- getComponentSubInfo(componentKey, "vd").value = originalWDom;
775
+ addComponentProps(originalWDom, compKey, tag, props, children, reRender2);
776
+ getComponentSubInfo(compKey, "vd").value = originalWDom;
782
777
  return originalWDom;
783
778
  };
784
- const addComponentProps = (wDom, componentKey, tag, props, children, reRender2) => {
785
- Object.assign(wDom, {
786
- componentProps: props,
787
- componentChildren: children,
788
- constructor: tag,
779
+ const addComponentProps = (wDom, compKey, tag, props, children, reRender2) => {
780
+ assign(wDom, {
781
+ compProps: props,
782
+ compChild: children,
783
+ ctor: tag,
789
784
  tagName: tag.name,
790
- componentKey,
785
+ compKey,
791
786
  reRender: reRender2
792
787
  });
793
788
  };