valyrian.js 7.2.11 → 7.2.12

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 (64) hide show
  1. package/dist/dataset/index.d.ts +2 -2
  2. package/dist/dataset/index.d.ts.map +1 -1
  3. package/dist/dataset/index.js +21 -21
  4. package/dist/dataset/index.js.map +2 -2
  5. package/dist/dataset/index.mjs +22 -22
  6. package/dist/dataset/index.mjs.map +2 -2
  7. package/dist/hooks/index.d.ts.map +1 -1
  8. package/dist/hooks/index.js +17 -32
  9. package/dist/hooks/index.js.map +3 -3
  10. package/dist/hooks/index.mjs +17 -32
  11. package/dist/hooks/index.mjs.map +3 -3
  12. package/dist/index.d.ts +49 -53
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +378 -326
  15. package/dist/index.js.map +3 -3
  16. package/dist/index.min.js +1 -1
  17. package/dist/index.min.js.map +1 -1
  18. package/dist/index.mjs +378 -326
  19. package/dist/index.mjs.map +3 -3
  20. package/dist/node/index.js +101 -78
  21. package/dist/node/index.js.map +2 -2
  22. package/dist/node/index.mjs +101 -78
  23. package/dist/node/index.mjs.map +2 -2
  24. package/dist/node/utils/tree-adapter.d.ts +5 -0
  25. package/dist/node/utils/tree-adapter.d.ts.map +1 -1
  26. package/dist/proxy-signal/index.js +10 -10
  27. package/dist/proxy-signal/index.js.map +2 -2
  28. package/dist/proxy-signal/index.mjs +10 -10
  29. package/dist/proxy-signal/index.mjs.map +2 -2
  30. package/dist/request/index.js +16 -16
  31. package/dist/request/index.js.map +2 -2
  32. package/dist/request/index.mjs +16 -16
  33. package/dist/request/index.mjs.map +2 -2
  34. package/dist/router/index.d.ts.map +1 -1
  35. package/dist/router/index.js +21 -20
  36. package/dist/router/index.js.map +2 -2
  37. package/dist/router/index.mjs +21 -20
  38. package/dist/router/index.mjs.map +2 -2
  39. package/dist/signal/index.d.ts +7 -18
  40. package/dist/signal/index.d.ts.map +1 -1
  41. package/dist/signal/index.js +29 -48
  42. package/dist/signal/index.js.map +3 -3
  43. package/dist/signal/index.mjs +31 -50
  44. package/dist/signal/index.mjs.map +3 -3
  45. package/dist/store/index.js +2 -2
  46. package/dist/store/index.js.map +2 -2
  47. package/dist/store/index.mjs +2 -2
  48. package/dist/store/index.mjs.map +2 -2
  49. package/lib/dataset/index.ts +25 -25
  50. package/lib/hooks/index.ts +25 -54
  51. package/lib/index.ts +465 -715
  52. package/lib/node/index.ts +2 -2
  53. package/lib/node/utils/icons.ts +5 -5
  54. package/lib/node/utils/inline.ts +17 -17
  55. package/lib/node/utils/sw.ts +3 -3
  56. package/lib/node/utils/tree-adapter.ts +81 -52
  57. package/lib/proxy-signal/index.ts +10 -10
  58. package/lib/request/index.ts +16 -16
  59. package/lib/router/index.ts +21 -20
  60. package/lib/signal/index.ts +56 -131
  61. package/lib/store/index.ts +2 -2
  62. package/package.json +10 -3
  63. package/lib/index.d.ts +0 -0
  64. package/lib/interfaces.ts.bak +0 -141
package/dist/index.mjs CHANGED
@@ -1,164 +1,116 @@
1
1
  // lib/index.ts
2
- var textTag = "#text";
3
2
  var isNodeJs = Boolean(typeof process !== "undefined" && process.versions && process.versions.node);
4
- function createDomElement(tag, isSVG = false) {
5
- return isSVG ? document.createElementNS("http://www.w3.org/2000/svg", tag) : document.createElement(tag);
6
- }
7
- var Vnode = function Vnode2(tag, props, children) {
8
- this.tag = tag;
9
- this.props = props;
10
- this.children = children;
11
- };
12
- function isComponent(component) {
13
- return Boolean(
14
- component && (typeof component === "function" || typeof component === "object" && "view" in component)
15
- );
16
- }
17
- var isVnode = (object) => {
18
- return object instanceof Vnode;
3
+ var Vnode = class {
4
+ constructor(tag, props, children, dom, isSVG) {
5
+ this.tag = tag;
6
+ this.props = props;
7
+ this.children = children;
8
+ this.dom = dom;
9
+ this.isSVG = isSVG;
10
+ }
19
11
  };
12
+ var isComponent = (component) => Boolean(typeof component === "function" || component && typeof component === "object" && "view" in component);
13
+ var isVnode = (object) => object instanceof Vnode;
20
14
  var isVnodeComponent = (object) => {
21
15
  return isVnode(object) && isComponent(object.tag);
22
16
  };
17
+ function v(tagOrComponent, props, ...children) {
18
+ return new Vnode(tagOrComponent, props, children);
19
+ }
20
+ v.fragment = (_, ...children) => children;
23
21
  function domToVnode(dom) {
24
22
  if (dom.nodeType === 3) {
25
- let vnode2 = new Vnode(textTag, {}, [dom.nodeValue]);
26
- vnode2.dom = dom;
27
- return vnode2;
23
+ return dom.nodeValue;
28
24
  }
29
- let children = [];
30
- for (let i = 0, l = dom.childNodes.length; i < l; i++) {
31
- let childDom = dom.childNodes[i];
32
- if (childDom.nodeType === 1 || childDom.nodeType === 3) {
33
- children.push(domToVnode(childDom));
25
+ if (dom.nodeType === 1) {
26
+ const tag = dom.nodeName.toLowerCase();
27
+ const props = {};
28
+ const children = [];
29
+ for (let i = 0, l = dom.childNodes.length; i < l; i++) {
30
+ const childDom = dom.childNodes[i];
31
+ if (childDom.nodeType === 3) {
32
+ children.push(childDom.nodeValue);
33
+ } else if (childDom.nodeType === 1) {
34
+ const childVnode = domToVnode(childDom);
35
+ children.push(childVnode);
36
+ }
34
37
  }
38
+ const attributes = dom.attributes;
39
+ for (let i = 0, l = attributes.length; i < l; i++) {
40
+ const attr = attributes[i];
41
+ props[attr.nodeName] = attr.nodeValue;
42
+ }
43
+ return new Vnode(tag, props, children, dom, tag === "svg");
35
44
  }
36
- let props = {};
37
- for (let i = 0, l = dom.attributes.length; i < l; i++) {
38
- let attr = dom.attributes[i];
39
- props[attr.nodeName] = attr.nodeValue;
40
- }
41
- let vnode = new Vnode(dom.tagName.toLowerCase(), props, children);
42
- vnode.dom = dom;
43
- return vnode;
44
45
  }
45
46
  function trust(htmlString) {
46
- let div = createDomElement("div");
47
+ const div = document.createElement("div");
47
48
  div.innerHTML = htmlString.trim();
48
- return [].map.call(div.childNodes, (item) => domToVnode(item));
49
+ return Array.from(div.childNodes).map(domToVnode);
49
50
  }
50
51
  var mainComponent = null;
51
52
  var mainVnode = null;
52
53
  var isMounted = false;
53
54
  var current = {
54
55
  vnode: null,
55
- oldVnode: null,
56
56
  component: null,
57
57
  event: null
58
58
  };
59
- var reservedProps = {
60
- key: true,
61
- state: true,
62
- "v-keep": true,
63
- // Built in directives
64
- "v-if": true,
65
- "v-unless": true,
66
- "v-for": true,
67
- "v-show": true,
68
- "v-class": true,
69
- "v-html": true,
70
- "v-model": true,
71
- "v-create": true,
72
- "v-update": true,
73
- "v-cleanup": true
74
- };
59
+ var reservedProps = /* @__PURE__ */ new Set([
60
+ "key",
61
+ "state",
62
+ "v-keep",
63
+ "v-text",
64
+ "v-if",
65
+ "v-for",
66
+ "v-show",
67
+ "v-class",
68
+ "v-html",
69
+ "v-model",
70
+ "v-create",
71
+ "v-update",
72
+ "v-cleanup"
73
+ ]);
75
74
  var onCleanupSet = /* @__PURE__ */ new Set();
76
75
  var onMountSet = /* @__PURE__ */ new Set();
77
76
  var onUpdateSet = /* @__PURE__ */ new Set();
78
77
  var onUnmountSet = /* @__PURE__ */ new Set();
79
- function onMount(callback) {
80
- if (!isMounted) {
81
- onMountSet.add(callback);
82
- }
83
- }
84
- function onUpdate(callback) {
85
- onUpdateSet.add(callback);
86
- }
87
- function onCleanup(callback) {
88
- onCleanupSet.add(callback);
89
- }
90
- function onUnmount(callback) {
91
- if (!isMounted) {
92
- onUnmountSet.add(callback);
93
- }
94
- }
95
- function callSet(set) {
96
- for (let callback of set) {
78
+ var onMount = (callback) => !isMounted && onMountSet.add(callback);
79
+ var onUpdate = (callback) => onUpdateSet.add(callback);
80
+ var onCleanup = (callback) => onCleanupSet.add(callback);
81
+ var onUnmount = (callback) => !isMounted && onUnmountSet.add(callback);
82
+ var callSet = (set) => {
83
+ for (const callback of set) {
97
84
  callback();
98
85
  }
99
86
  set.clear();
100
- }
101
- var eventListenerNames = {};
102
- function eventListener(e) {
103
- current.event = e;
104
- let dom = e.target;
105
- let name = `v-on${e.type}`;
106
- while (dom) {
107
- if (dom[name]) {
108
- dom[name](e, dom);
109
- if (!e.defaultPrevented) {
110
- update();
87
+ };
88
+ var handleVIf = (shouldRender) => {
89
+ return (value, vnode) => {
90
+ const bool = shouldRender !== Boolean(value);
91
+ if (bool) {
92
+ const parentNode = vnode.dom?.parentNode;
93
+ if (parentNode) {
94
+ const newdom = document.createTextNode("");
95
+ parentNode.replaceChild(newdom, vnode.dom);
111
96
  }
112
- return;
97
+ return false;
113
98
  }
114
- dom = dom.parentNode;
115
- }
116
- current.event = null;
117
- }
118
- var hideDirective = (test) => (bool, vnode, oldnode) => {
119
- let value = test ? bool : !bool;
120
- if (value) {
121
- let newdom = document.createTextNode("");
122
- if (oldnode && oldnode.dom && oldnode.dom.parentNode) {
123
- oldnode.dom.parentNode.replaceChild(newdom, oldnode.dom);
124
- }
125
- vnode.tag = "#text";
126
- vnode.children = [];
127
- vnode.props = {};
128
- vnode.dom = newdom;
129
- return false;
130
- }
99
+ };
131
100
  };
132
101
  var directives = {
133
- // The "v-if" directive hides an element if the given condition is false
134
- "v-if": hideDirective(false),
135
- // The "v-unless" directive hides an element if the given condition is true
136
- "v-unless": hideDirective(true),
137
- // The "v-for" directive creates a loop and applies a callback function to each item in the loop
138
- "v-for": (set, vnode) => {
139
- let newChildren = [];
140
- let callback = vnode.children[0];
141
- for (let i = 0, l = set.length; i < l; i++) {
142
- newChildren.push(callback(set[i], i));
143
- }
144
- vnode.children = newChildren;
145
- },
146
- // The "v-show" directive shows or hides an element by setting the "display" style property
147
- "v-show": (bool, vnode) => {
102
+ "v-if": handleVIf(true),
103
+ "v-unless": handleVIf(false),
104
+ "v-show": (value, vnode) => {
105
+ const bool = Boolean(value);
148
106
  vnode.dom.style.display = bool ? "" : "none";
149
107
  },
150
- // The "v-class" directive adds or removes class names from an element based on a condition
151
- "v-class": (classes, vnode) => {
152
- for (let name in classes) {
153
- vnode.dom.classList.toggle(name, classes[name]);
154
- }
155
- },
156
- // The "v-html" directive sets the inner HTML of an element to the given HTML string
157
- "v-html": (html, vnode) => {
158
- vnode.children = [trust(html)];
108
+ "v-html": (value, vnode) => {
109
+ vnode.children = [trust(value)];
159
110
  },
160
111
  // The "v-model" directive binds the value of an input element to a model property
161
- "v-model": ([model, property, event], vnode, oldVnode) => {
112
+ "v-model": (val, vnode) => {
113
+ let [model, property, event] = val;
162
114
  let value;
163
115
  let handler = (e) => model[property] = e.target.value;
164
116
  if (vnode.tag === "input") {
@@ -167,10 +119,10 @@ var directives = {
167
119
  case "checkbox": {
168
120
  if (Array.isArray(model[property])) {
169
121
  handler = (e) => {
170
- let val = e.target.value;
171
- let idx = model[property].indexOf(val);
122
+ const val2 = e.target.value;
123
+ const idx = model[property].indexOf(val2);
172
124
  if (idx === -1) {
173
- model[property].push(val);
125
+ model[property].push(val2);
174
126
  } else {
175
127
  model[property].splice(idx, 1);
176
128
  }
@@ -204,29 +156,29 @@ var directives = {
204
156
  event = event || "onclick";
205
157
  if (vnode.props.multiple) {
206
158
  handler = (e) => {
207
- let val = e.target.value;
159
+ const val2 = e.target.value;
208
160
  if (e.ctrlKey) {
209
- let idx = model[property].indexOf(val);
161
+ const idx = model[property].indexOf(val2);
210
162
  if (idx === -1) {
211
- model[property].push(val);
163
+ model[property].push(val2);
212
164
  } else {
213
165
  model[property].splice(idx, 1);
214
166
  }
215
167
  } else {
216
168
  model[property].splice(0, model[property].length);
217
- model[property].push(val);
169
+ model[property].push(val2);
218
170
  }
219
171
  };
220
172
  vnode.children.forEach((child) => {
221
173
  if (child.tag === "option") {
222
- let value2 = "value" in child.props ? child.props.value : child.children.join("").trim();
174
+ const value2 = "value" in child.props ? child.props.value : child.children.join("").trim();
223
175
  child.props.selected = model[property].indexOf(value2) !== -1;
224
176
  }
225
177
  });
226
178
  } else {
227
179
  vnode.children.forEach((child) => {
228
180
  if (child.tag === "option") {
229
- let value2 = "value" in child.props ? child.props.value : child.children.join("").trim();
181
+ const value2 = "value" in child.props ? child.props.value : child.children.join("").trim();
230
182
  child.props.selected = value2 === model[property];
231
183
  }
232
184
  });
@@ -235,7 +187,7 @@ var directives = {
235
187
  event = event || "oninput";
236
188
  vnode.children = [model[property]];
237
189
  }
238
- let prevHandler = vnode.props[event];
190
+ const prevHandler = vnode.props[event];
239
191
  sharedSetAttribute(
240
192
  event,
241
193
  (e) => {
@@ -244,266 +196,368 @@ var directives = {
244
196
  prevHandler(e);
245
197
  }
246
198
  },
247
- vnode,
248
- oldVnode
199
+ vnode
249
200
  );
250
201
  },
251
- // The "v-create" directive is called when a new virtual node is created.
252
- // The provided callback function is called with the new virtual node as an argument.
253
- // This directive is only called once per virtual node, when it is first created.
254
- // eslint-disable-next-line no-unused-vars
255
- "v-create": (callback, vnode, oldVnode) => {
256
- if (!oldVnode) {
257
- let cleanup = callback(vnode);
202
+ "v-create": (callback, vnode, oldProps) => {
203
+ if (!oldProps) {
204
+ const cleanup = callback(vnode);
258
205
  if (typeof cleanup === "function") {
259
206
  onCleanup(cleanup);
260
207
  }
261
208
  }
262
209
  },
263
- // The "v-update" directive is called when an existing virtual node is updated.
264
- // The provided callback function is called with the new and old virtual nodes as arguments.
265
- // This directive is only called once per virtual node update.
266
- "v-update": (callback, vnode, oldVnode) => {
267
- if (oldVnode) {
268
- let cleanup = callback(vnode, oldVnode);
210
+ "v-update": (callback, vnode, oldProps) => {
211
+ if (oldProps) {
212
+ const cleanup = callback(vnode, oldProps);
269
213
  if (typeof cleanup === "function") {
270
214
  onCleanup(cleanup);
271
215
  }
272
216
  }
273
217
  },
274
- // The "v-cleanup" directive is called when the update is cleaned up.
275
- // The provided callback function is called with the old virtual node as an argument.
276
- // This directive is only called once per virtual node, when the update is cleaned up.
277
- "v-cleanup": (callback, vnode, oldVnode) => {
278
- onCleanup(() => callback(vnode, oldVnode));
218
+ "v-cleanup": (callback, vnode) => {
219
+ onCleanup(() => callback(vnode));
220
+ },
221
+ "v-class": (value, vnode) => {
222
+ if (typeof value === "string") {
223
+ vnode.dom.className = value;
224
+ } else if (Array.isArray(value)) {
225
+ vnode.dom.className = value.join(" ");
226
+ } else if (typeof value === "object") {
227
+ const classList = vnode.dom.classList;
228
+ for (const name in value) {
229
+ const val = typeof value[name] === "function" ? value[name]() : value[name];
230
+ classList.toggle(name, val);
231
+ }
232
+ }
233
+ },
234
+ // Frequent used properties
235
+ class(value, vnode) {
236
+ if (vnode.dom.className !== value) {
237
+ vnode.dom.className = value;
238
+ }
239
+ },
240
+ className(value, vnode) {
241
+ directives.class(value, vnode, null);
242
+ },
243
+ id: (value, vnode) => {
244
+ vnode.dom.id = value;
245
+ },
246
+ style: (value, vnode) => {
247
+ if (typeof value === "string") {
248
+ vnode.dom.style = value;
249
+ } else if (typeof value === "object") {
250
+ vnode.dom.style = "";
251
+ const domStyle = vnode.dom.style;
252
+ for (const name in value) {
253
+ domStyle[name] = value[name];
254
+ }
255
+ }
279
256
  }
280
257
  };
281
258
  function directive(name, directive2) {
282
- let directiveName = `v-${name}`;
259
+ const directiveName = `v-${name}`;
283
260
  directives[directiveName] = directive2;
284
- reservedProps[directiveName] = true;
261
+ reservedProps.add(directiveName);
285
262
  }
286
- function sharedSetAttribute(name, value, newVnode, oldVnode) {
263
+ var eventListenerNames = /* @__PURE__ */ new Set();
264
+ function eventListener(e) {
265
+ current.event = e;
266
+ let dom = e.target;
267
+ const name = `on${e.type}`;
268
+ while (dom) {
269
+ const oldProps = dom.props;
270
+ if (oldProps && oldProps[name]) {
271
+ oldProps[name](e, dom);
272
+ if (!e.defaultPrevented) {
273
+ update();
274
+ }
275
+ return;
276
+ }
277
+ dom = dom.parentNode;
278
+ }
279
+ current.event = null;
280
+ }
281
+ function sharedSetAttribute(name, value, newVnode) {
282
+ const newVnodeDom = newVnode.dom;
287
283
  if (typeof value === "function") {
288
- if (name in eventListenerNames === false) {
284
+ if (!eventListenerNames.has(name)) {
289
285
  mainVnode.dom.addEventListener(name.slice(2), eventListener);
290
- eventListenerNames[name] = true;
286
+ eventListenerNames.add(name);
291
287
  }
292
- newVnode.dom[`v-${name}`] = value;
293
288
  return;
294
289
  }
295
- if (name in newVnode.dom && newVnode.isSVG === false) {
296
- if (newVnode.dom[name] != value) {
297
- newVnode.dom[name] = value;
298
- }
290
+ if (name in newVnodeDom) {
291
+ newVnodeDom[name] = value;
299
292
  return;
300
293
  }
301
- if (!oldVnode || value !== oldVnode.props[name]) {
302
- if (value === false) {
303
- newVnode.dom.removeAttribute(name);
304
- } else {
305
- newVnode.dom.setAttribute(name, value);
306
- }
294
+ if (value === false) {
295
+ newVnodeDom.removeAttribute(name);
296
+ } else {
297
+ newVnodeDom.setAttribute(name, value);
307
298
  }
308
299
  }
309
- function setAttribute(name, value, newVnode, oldVnode) {
310
- if (name in reservedProps) {
311
- return;
300
+ function setAttribute(name, value, newVnode) {
301
+ if (!reservedProps.has(name)) {
302
+ newVnode.props[name] = value;
303
+ sharedSetAttribute(name, value, newVnode);
312
304
  }
313
- newVnode.props[name] = value;
314
- sharedSetAttribute(name, value, newVnode, oldVnode);
315
305
  }
316
- function updateAttributes(newVnode, oldVnode) {
317
- if (oldVnode) {
318
- for (let name in oldVnode.props) {
319
- if (name in newVnode.props === false && name in eventListenerNames === false && name in reservedProps === false) {
320
- if (name in newVnode.dom && newVnode.isSVG === false) {
321
- newVnode.dom[name] = null;
322
- } else {
323
- newVnode.dom.removeAttribute(name);
324
- }
306
+ function removeAttributes(vnode, oldProps) {
307
+ if (!oldProps) {
308
+ return;
309
+ }
310
+ const vnodeDom = vnode.dom;
311
+ const vnodeProps = vnode.props;
312
+ for (const name in oldProps) {
313
+ if (name in vnodeProps === false && !eventListenerNames.has(name) && !reservedProps.has(name)) {
314
+ if (name in vnodeDom) {
315
+ vnodeDom[name] = null;
316
+ } else {
317
+ vnodeDom.removeAttribute(name);
325
318
  }
326
319
  }
327
320
  }
328
- for (let name in newVnode.props) {
329
- if (name in reservedProps) {
330
- if (name in directives && directives[name](newVnode.props[name], newVnode, oldVnode) === false) {
321
+ }
322
+ function addProperties(vnode, oldProps) {
323
+ const vnodeProps = vnode.props;
324
+ for (const name in vnodeProps) {
325
+ if (directives[name]) {
326
+ if (directives[name](vnodeProps[name], vnode, oldProps) === false) {
331
327
  break;
332
328
  }
333
329
  continue;
334
330
  }
335
- sharedSetAttribute(name, newVnode.props[name], newVnode, oldVnode);
331
+ if (reservedProps.has(name)) {
332
+ continue;
333
+ }
334
+ sharedSetAttribute(name, vnodeProps[name], vnode);
336
335
  }
337
336
  }
338
- function patch(newVnode, oldVnode) {
339
- if (newVnode.children.length === 0) {
340
- newVnode.dom.textContent = "";
341
- return;
342
- }
343
- let newTree = newVnode.children;
344
- let oldTree = oldVnode?.children || [];
345
- let oldTreeLength = oldTree.length;
346
- if (oldTreeLength && newTree[0] instanceof Vnode && "key" in newTree[0].props && "key" in oldTree[0].props) {
347
- let newTreeLength = newTree.length;
348
- let oldKeyedList = {};
349
- for (let i = 0; i < oldTreeLength; i++) {
350
- oldKeyedList[oldTree[i].props.key] = i;
351
- }
352
- let newKeyedList = {};
353
- for (let i = 0; i < newTreeLength; i++) {
354
- newKeyedList[newTree[i].props.key] = i;
355
- }
356
- for (let i = 0; i < newTreeLength; i++) {
357
- let newChild = newTree[i];
358
- let oldChild = oldTree[oldKeyedList[newChild.props.key]];
359
- let shouldPatch = true;
360
- if (oldChild) {
361
- newChild.dom = oldChild.dom;
362
- if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
363
- newChild.children = oldChild.children;
364
- shouldPatch = false;
365
- } else {
366
- updateAttributes(newChild, oldChild);
367
- }
368
- } else {
369
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
370
- updateAttributes(newChild);
337
+ function updateAttributes(newVnode, oldProps) {
338
+ removeAttributes(newVnode, oldProps);
339
+ addProperties(newVnode, oldProps);
340
+ }
341
+ function createElement(tag, isSVG) {
342
+ return isSVG ? document.createElementNS("http://www.w3.org/2000/svg", tag) : document.createElement(tag);
343
+ }
344
+ function flatTree(newVnode, children) {
345
+ current.vnode = newVnode;
346
+ let i = 0;
347
+ while (i < children.length) {
348
+ const newChild = children[i];
349
+ if (newChild == null) {
350
+ children.splice(i, 1);
351
+ continue;
352
+ }
353
+ if (Array.isArray(newChild)) {
354
+ children.splice(i, 1, ...newChild);
355
+ continue;
356
+ }
357
+ if (newChild instanceof Vnode) {
358
+ if (newChild.props === null) {
359
+ newChild.props = {};
371
360
  }
372
- if (!newVnode.dom.childNodes[i]) {
373
- newVnode.dom.appendChild(newChild.dom);
374
- } else if (newVnode.dom.childNodes[i] !== newChild.dom) {
375
- newVnode.dom.replaceChild(newChild.dom, newVnode.dom.childNodes[i]);
361
+ if (typeof newChild.tag !== "string") {
362
+ const component = newChild.tag;
363
+ current.component = newChild.tag;
364
+ children[i] = ("view" in component ? component.view : component).bind(component)(
365
+ newChild.props,
366
+ newChild.children
367
+ );
368
+ continue;
369
+ } else {
370
+ newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
376
371
  }
377
- shouldPatch && patch(newChild, oldChild);
378
372
  }
379
- for (let i = newTreeLength; i < oldTreeLength; i++) {
380
- if (!newKeyedList[oldTree[i].props.key]) {
381
- oldTree[i].dom.parentNode && oldTree[i].dom.parentNode.removeChild(oldTree[i].dom);
382
- }
373
+ i++;
374
+ }
375
+ return children;
376
+ }
377
+ function handleVFor(newVnode) {
378
+ if ("v-for" in newVnode.props) {
379
+ const set = newVnode.props["v-for"];
380
+ const children = [];
381
+ const callback = newVnode.children[0];
382
+ children.length = set.length;
383
+ for (let i = 0, l = set.length; i < l; i++) {
384
+ children[i] = callback(set[i], i);
383
385
  }
386
+ return children;
387
+ }
388
+ return [...newVnode.children];
389
+ }
390
+ function createNewElement(newChild, newVnode, oldChild) {
391
+ const dom = createElement(newChild.tag, newChild.isSVG);
392
+ if (oldChild) {
393
+ newVnode.dom.replaceChild(dom, oldChild);
394
+ } else {
395
+ newVnode.dom.appendChild(dom);
396
+ }
397
+ newChild.dom = dom;
398
+ addProperties(newChild, null);
399
+ newChild.dom.props = newChild.props;
400
+ if ("v-text" in newChild.props) {
401
+ newChild.dom.textContent = newChild.props["v-text"];
384
402
  return;
385
403
  }
386
- if (newTree.length === 0) {
387
- newVnode.dom.textContent = "";
404
+ const children = flatTree(newChild, handleVFor(newChild));
405
+ if (children.length === 0) {
406
+ newChild.dom.textContent = "";
388
407
  return;
389
408
  }
390
- current.vnode = newVnode;
391
- current.oldVnode = oldVnode;
392
- for (let i = 0; i < newTree.length; i++) {
393
- let newChild = newTree[i];
394
- if (newChild instanceof Vnode) {
395
- if (typeof newChild.tag !== "string") {
396
- current.component = newChild.tag;
397
- newTree.splice(
398
- i--,
399
- 1,
400
- ("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
401
- newChild.props,
402
- ...newChild.children
403
- )
404
- );
405
- }
409
+ for (let i = 0, l = children.length; i < l; i++) {
410
+ if (children[i] instanceof Vnode === false) {
411
+ newChild.dom.appendChild(document.createTextNode(children[i]));
406
412
  continue;
407
413
  }
408
- if (Array.isArray(newChild)) {
409
- newTree.splice(i--, 1, ...newChild);
410
- continue;
414
+ createNewElement(children[i], newChild, null);
415
+ }
416
+ }
417
+ function patchKeyed(newVnode, children) {
418
+ const oldTree = [...Array.from(newVnode.dom.childNodes)];
419
+ const childNodes = newVnode.dom.childNodes;
420
+ const oldKeyedList = {};
421
+ const newKeyedList = {};
422
+ for (let i = 0, l = oldTree.length; i < l; i++) {
423
+ const oldProps = oldTree[i].props;
424
+ if (oldProps) {
425
+ oldKeyedList[oldProps.key] = i;
411
426
  }
412
- if (newChild === null || newChild === void 0) {
413
- newTree.splice(i--, 1);
427
+ if (i < children.length && children[i] instanceof Vnode) {
428
+ newKeyedList[children[i].props.key] = i;
429
+ }
430
+ }
431
+ for (let i = 0, l = children.length; i < l; i++) {
432
+ const newChild = children[i];
433
+ const oldChild = oldTree[oldKeyedList[newChild.props.key]];
434
+ if (!oldChild) {
435
+ createNewElement(newChild, newVnode, childNodes[i]);
414
436
  continue;
415
437
  }
416
- newTree[i] = new Vnode(textTag, {}, [newChild]);
438
+ newChild.dom = oldChild;
439
+ const currentChild = childNodes[i];
440
+ if (!currentChild) {
441
+ newVnode.dom.appendChild(oldChild);
442
+ } else if (currentChild !== oldChild) {
443
+ newVnode.dom.replaceChild(oldChild, currentChild);
444
+ }
445
+ if ("v-keep" in newChild.props === false || oldChild.props["v-keep"] !== newChild.props["v-keep"]) {
446
+ updateAttributes(newChild, oldChild.props);
447
+ oldChild.props = newChild.props;
448
+ if ("v-text" in newChild.props) {
449
+ if (oldChild.textContent != newChild.props["v-text"]) {
450
+ oldChild.textContent = newChild.props["v-text"];
451
+ }
452
+ continue;
453
+ }
454
+ patch(newChild);
455
+ }
456
+ }
457
+ for (let i = children.length, l = childNodes.length; i < l; i++) {
458
+ childNodes[i]?.remove();
459
+ }
460
+ }
461
+ function patch(newVnode) {
462
+ const children = flatTree(newVnode, handleVFor(newVnode));
463
+ const dom = newVnode.dom;
464
+ if (children.length === 0) {
465
+ if (dom.childNodes.length) {
466
+ dom.textContent = "";
467
+ }
468
+ return;
469
+ }
470
+ const oldDomChildren = dom.childNodes;
471
+ const oldChildrenLength = oldDomChildren.length;
472
+ if (oldChildrenLength > 0) {
473
+ const firstOldProps = oldDomChildren[0].props;
474
+ const firstVnode = children[0];
475
+ if (firstOldProps && firstVnode instanceof Vnode && "key" in firstVnode.props && "key" in firstOldProps) {
476
+ patchKeyed(newVnode, children);
477
+ return;
478
+ }
417
479
  }
418
- for (let i = 0; i < newTree.length; i++) {
419
- let newChild = newTree[i];
420
- if (newChild.tag === textTag) {
421
- if (i >= oldTreeLength) {
422
- newChild.dom = document.createTextNode(newChild.children[0]);
423
- newVnode.dom.appendChild(newChild.dom);
480
+ const childrenLength = children.length;
481
+ if (oldChildrenLength === 0) {
482
+ for (let i = 0; i < childrenLength; i++) {
483
+ if (children[i] instanceof Vnode === false) {
484
+ dom.appendChild(document.createTextNode(children[i]));
424
485
  continue;
425
486
  }
426
- let oldChild2 = oldTree[i];
427
- if (oldChild2.tag !== textTag) {
428
- newChild.dom = document.createTextNode(newChild.children[0]);
429
- newVnode.dom.replaceChild(newChild.dom, oldChild2.dom);
487
+ createNewElement(children[i], newVnode, null);
488
+ }
489
+ return;
490
+ }
491
+ for (let i = 0; i < childrenLength; i++) {
492
+ const oldChild = oldDomChildren[i];
493
+ const newChild = children[i];
494
+ if (!oldChild) {
495
+ createNewElement(newChild, newVnode, null);
496
+ continue;
497
+ }
498
+ if (newChild instanceof Vnode === false) {
499
+ if (oldChild.nodeType !== 3) {
500
+ newVnode.dom.replaceChild(document.createTextNode(newChild), oldChild);
430
501
  continue;
431
502
  }
432
- newChild.dom = oldChild2.dom;
433
- if (newChild.children[0] != oldChild2.dom.textContent) {
434
- oldChild2.dom.textContent = newChild.children[0];
503
+ if (oldChild.nodeValue != newChild) {
504
+ oldChild.nodeValue = newChild;
435
505
  }
436
506
  continue;
437
507
  }
438
- newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
439
- if (i >= oldTreeLength) {
440
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
441
- updateAttributes(newChild);
442
- newVnode.dom.appendChild(newChild.dom);
443
- patch(newChild);
444
- continue;
508
+ if ("v-keep" in newChild.props) {
509
+ if (oldChild.props && oldChild.props["v-keep"] === newChild.props["v-keep"]) {
510
+ continue;
511
+ }
512
+ const nextOldChild = oldDomChildren[i + 1];
513
+ if (nextOldChild && nextOldChild.props && nextOldChild.props["v-keep"] === newChild.props["v-keep"]) {
514
+ oldChild.remove();
515
+ continue;
516
+ }
445
517
  }
446
- let oldChild = oldTree[i];
447
- if (newChild.tag !== oldChild.tag) {
448
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
449
- updateAttributes(newChild);
450
- newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
451
- patch(newChild);
518
+ if (newChild.tag !== oldChild.nodeName.toLowerCase()) {
519
+ createNewElement(newChild, newVnode, oldChild);
452
520
  continue;
453
521
  }
454
- newChild.dom = oldChild.dom;
455
- if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
456
- newChild.children = oldChild.children;
522
+ newChild.dom = oldChild;
523
+ updateAttributes(newChild, oldChild.props || null);
524
+ oldChild.props = newChild.props;
525
+ if ("v-text" in newChild.props) {
526
+ if (newChild.dom.textContent != newChild.props["v-text"]) {
527
+ newChild.dom.textContent = newChild.props["v-text"];
528
+ }
457
529
  continue;
458
530
  }
459
- updateAttributes(newChild, oldChild);
460
- patch(newChild, oldChild);
531
+ patch(newChild);
461
532
  }
462
- for (let i = newTree.length; i < oldTreeLength; i++) {
463
- newVnode.dom.removeChild(oldTree[i].dom);
464
- }
465
- }
466
- function update() {
467
- if (mainVnode) {
468
- callSet(onCleanupSet);
469
- let oldMainVnode = mainVnode;
470
- mainVnode = new Vnode(oldMainVnode.tag, oldMainVnode.props, [mainComponent]);
471
- mainVnode.dom = oldMainVnode.dom;
472
- mainVnode.isSVG = oldMainVnode.isSVG;
473
- patch(mainVnode, oldMainVnode);
474
- callSet(isMounted ? onUpdateSet : onMountSet);
475
- isMounted = true;
476
- current.vnode = null;
477
- current.oldVnode = null;
478
- current.component = null;
479
- if (isNodeJs) {
480
- return mainVnode.dom.innerHTML;
481
- }
533
+ for (let i = childrenLength, l = oldDomChildren.length; i < l; i++) {
534
+ oldDomChildren[i]?.remove();
482
535
  }
483
536
  }
484
- function updateVnode(vnode, oldVnode) {
537
+ function updateVnode(vnode) {
485
538
  callSet(onCleanupSet);
486
- patch(vnode, oldVnode);
487
- oldVnode.tag = vnode.tag;
488
- oldVnode.props = { ...vnode.props };
489
- oldVnode.children = [...vnode.children];
490
- oldVnode.dom = vnode.dom;
491
- oldVnode.isSVG = vnode.isSVG;
539
+ vnode.props = vnode.props || {};
540
+ patch(vnode);
492
541
  callSet(isMounted ? onUpdateSet : onMountSet);
493
542
  isMounted = true;
494
543
  current.vnode = null;
495
- current.oldVnode = null;
496
544
  current.component = null;
497
545
  if (isNodeJs) {
498
546
  return vnode.dom.innerHTML;
499
547
  }
500
548
  }
549
+ function update() {
550
+ if (mainVnode) {
551
+ mainVnode.children = [mainComponent];
552
+ return updateVnode(mainVnode);
553
+ }
554
+ }
501
555
  function unmount() {
502
556
  if (mainVnode) {
503
- mainComponent = new Vnode(() => null, {}, []);
504
- let result = update();
557
+ mainComponent = v(() => null, {});
558
+ const result = update();
505
559
  callSet(onUnmountSet);
506
- for (let name in eventListenerNames) {
560
+ for (const name in eventListenerNames) {
507
561
  mainVnode.dom.removeEventListener(name.slice(2).toLowerCase(), eventListener);
508
562
  Reflect.deleteProperty(eventListenerNames, name);
509
563
  }
@@ -511,28 +565,26 @@ function unmount() {
511
565
  mainVnode = null;
512
566
  isMounted = false;
513
567
  current.vnode = null;
514
- current.oldVnode = null;
515
568
  current.component = null;
569
+ current.event = null;
516
570
  return result;
517
571
  }
518
572
  }
519
573
  function mount(dom, component) {
520
- let container = typeof dom === "string" ? isNodeJs ? createDomElement(dom, dom === "svg") : document.querySelectorAll(dom)[0] : dom;
521
- let vnodeComponent = isVnodeComponent(component) ? component : isComponent(component) ? new Vnode(component, {}, []) : new Vnode(() => component, {}, []);
522
- if (mainComponent && mainComponent.tag !== vnodeComponent.tag) {
523
- unmount();
574
+ const container = typeof dom === "string" ? isNodeJs ? createElement(dom, dom === "svg") : document.querySelector(dom) : dom;
575
+ if (isComponent(component)) {
576
+ mainComponent = new Vnode(component, {}, []);
577
+ } else if (isVnodeComponent(component)) {
578
+ mainComponent = component;
579
+ } else {
580
+ mainComponent = new Vnode(() => component, {}, []);
524
581
  }
525
- mainComponent = vnodeComponent;
526
582
  mainVnode = domToVnode(container);
527
583
  return update();
528
584
  }
529
- var v = (tagOrComponent, props = {}, ...children) => {
530
- return new Vnode(tagOrComponent, props || {}, children);
531
- };
532
- v.fragment = (_, ...children) => children;
533
585
  export {
534
586
  Vnode,
535
- createDomElement,
587
+ createElement,
536
588
  current,
537
589
  directive,
538
590
  directives,