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