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