valyrian.js 7.2.11 → 8.0.0

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