@ryupold/vode 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vode.mjs CHANGED
@@ -1,26 +1,19 @@
1
1
  // src/vode.ts
2
2
  var globals = {
3
- currentViewTransition: undefined,
4
- requestAnimationFrame: window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : (cb) => cb(),
5
- startViewTransition: document.startViewTransition ? document.startViewTransition.bind(document) : null
3
+ currentViewTransition: void 0,
4
+ requestAnimationFrame: !!window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : ((cb) => cb()),
5
+ startViewTransition: !!document.startViewTransition ? document.startViewTransition.bind(document) : null
6
6
  };
7
- function vode(tag, props, ...children) {
8
- if (!tag)
9
- throw new Error("first argument to vode() must be a tag name or a vode");
10
- if (Array.isArray(tag))
11
- return tag;
12
- else if (props)
13
- return [tag, props, ...children];
14
- else
15
- return [tag, ...children];
7
+ function vode(tag2, props2, ...children2) {
8
+ if (!tag2) throw new Error("first argument to vode() must be a tag name or a vode");
9
+ if (Array.isArray(tag2)) return tag2;
10
+ else if (props2) return [tag2, props2, ...children2];
11
+ else return [tag2, ...children2];
16
12
  }
17
13
  function app(container, state, dom, ...initialPatches) {
18
- if (!container?.parentElement)
19
- throw new Error("first argument to app() must be a valid HTMLElement inside the <html></html> document");
20
- if (!state || typeof state !== "object")
21
- throw new Error("second argument to app() must be a state object");
22
- if (typeof dom !== "function")
23
- throw new Error("third argument to app() must be a function that returns a vode");
14
+ if (!container?.parentElement) throw new Error("first argument to app() must be a valid HTMLElement inside the <html></html> document");
15
+ if (!state || typeof state !== "object") throw new Error("second argument to app() must be a state object");
16
+ if (typeof dom !== "function") throw new Error("third argument to app() must be a function that returns a vode");
24
17
  const _vode = {};
25
18
  _vode.syncRenderer = globals.requestAnimationFrame;
26
19
  _vode.asyncRenderer = globals.startViewTransition;
@@ -32,8 +25,7 @@ function app(container, state, dom, ...initialPatches) {
32
25
  configurable: true,
33
26
  writable: false,
34
27
  value: async (action, isAsync) => {
35
- if (!action || typeof action !== "function" && typeof action !== "object")
36
- return;
28
+ if (!action || typeof action !== "function" && typeof action !== "object") return;
37
29
  _vode.stats.patchCount++;
38
30
  if (action?.next) {
39
31
  const generator = action;
@@ -71,7 +63,8 @@ function app(container, state, dom, ...initialPatches) {
71
63
  _vode.qAsync = null;
72
64
  try {
73
65
  globals.currentViewTransition?.skipTransition();
74
- } catch {}
66
+ } catch {
67
+ }
75
68
  _vode.stats.syncRenderPatchCount++;
76
69
  _vode.renderSync();
77
70
  }
@@ -102,8 +95,7 @@ function app(container, state, dom, ...initialPatches) {
102
95
  _vode.stats.lastSyncRenderTime = Date.now() - sw;
103
96
  _vode.stats.syncRenderCount++;
104
97
  _vode.isRendering = false;
105
- if (_vode.qSync)
106
- _vode.renderSync();
98
+ if (_vode.qSync) _vode.renderSync();
107
99
  }
108
100
  }
109
101
  const sr = renderDom.bind(null, false);
@@ -113,8 +105,7 @@ function app(container, state, dom, ...initialPatches) {
113
105
  configurable: true,
114
106
  writable: false,
115
107
  value: () => {
116
- if (_vode.isRendering || !_vode.qSync)
117
- return;
108
+ if (_vode.isRendering || !_vode.qSync) return;
118
109
  _vode.isRendering = true;
119
110
  _vode.state = mergeState(_vode.state, _vode.qSync, true);
120
111
  _vode.qSync = null;
@@ -126,11 +117,9 @@ function app(container, state, dom, ...initialPatches) {
126
117
  configurable: true,
127
118
  writable: false,
128
119
  value: async () => {
129
- if (_vode.isAnimating || !_vode.qAsync)
130
- return;
120
+ if (_vode.isAnimating || !_vode.qAsync) return;
131
121
  await globals.currentViewTransition?.updateCallbackDone;
132
- if (_vode.isAnimating || !_vode.qAsync || document.hidden)
133
- return;
122
+ if (_vode.isAnimating || !_vode.qAsync || document.hidden) return;
134
123
  _vode.isAnimating = true;
135
124
  const sw = Date.now();
136
125
  try {
@@ -143,15 +132,21 @@ function app(container, state, dom, ...initialPatches) {
143
132
  _vode.stats.asyncRenderCount++;
144
133
  _vode.isAnimating = false;
145
134
  }
146
- if (_vode.qAsync)
147
- _vode.renderAsync();
135
+ if (_vode.qAsync) _vode.renderAsync();
148
136
  }
149
137
  });
150
138
  _vode.patch = state.patch;
151
139
  _vode.state = state;
152
140
  const root = container;
153
141
  root._vode = _vode;
154
- _vode.vode = render(state, _vode.patch, container.parentElement, Array.from(container.parentElement.children).indexOf(container), hydrate(container, true), dom(state));
142
+ _vode.vode = render(
143
+ state,
144
+ _vode.patch,
145
+ container.parentElement,
146
+ Array.from(container.parentElement.children).indexOf(container),
147
+ hydrate(container, true),
148
+ dom(state)
149
+ );
155
150
  for (const effect of initialPatches) {
156
151
  _vode.patch(effect);
157
152
  }
@@ -159,9 +154,8 @@ function app(container, state, dom, ...initialPatches) {
159
154
  }
160
155
  function defuse(container) {
161
156
  if (container?._vode) {
162
- let clearEvents = function(av) {
163
- if (!av?.node)
164
- return;
157
+ let clearEvents2 = function(av) {
158
+ if (!av?.node) return;
165
159
  const p = props(av);
166
160
  if (p) {
167
161
  for (const key in p) {
@@ -173,75 +167,72 @@ function defuse(container) {
173
167
  }
174
168
  const kids = children(av);
175
169
  if (kids) {
176
- for (let child of kids) {
177
- clearEvents(child);
170
+ for (let child2 of kids) {
171
+ clearEvents2(child2);
178
172
  }
179
173
  }
180
174
  };
175
+ var clearEvents = clearEvents2;
181
176
  const v = container._vode;
182
177
  delete container["_vode"];
183
- Object.defineProperty(v.state, "patch", { value: undefined });
184
- Object.defineProperty(v, "renderSync", { value: () => {} });
185
- Object.defineProperty(v, "renderAsync", { value: () => {} });
186
- clearEvents(v.vode);
178
+ Object.defineProperty(v.state, "patch", { value: void 0 });
179
+ Object.defineProperty(v, "renderSync", { value: () => {
180
+ } });
181
+ Object.defineProperty(v, "renderAsync", { value: () => {
182
+ } });
183
+ clearEvents2(v.vode);
187
184
  }
188
185
  }
189
186
  function hydrate(element, prepareForRender) {
190
187
  if (element?.nodeType === Node.TEXT_NODE) {
191
188
  if (element.nodeValue?.trim() !== "")
192
189
  return prepareForRender ? element : element.nodeValue;
193
- return;
190
+ return void 0;
194
191
  } else if (element.nodeType === Node.COMMENT_NODE) {
195
- return;
192
+ return void 0;
196
193
  } else if (element.nodeType === Node.ELEMENT_NODE) {
197
- const tag = element.tagName.toLowerCase();
198
- const root = [tag];
199
- if (prepareForRender)
200
- root.node = element;
194
+ const tag2 = element.tagName.toLowerCase();
195
+ const root = [tag2];
196
+ if (prepareForRender) root.node = element;
201
197
  if (element?.hasAttributes()) {
202
- const props = {};
198
+ const props2 = {};
203
199
  const attr = element.attributes;
204
200
  for (let a of attr) {
205
- props[a.name] = a.value;
201
+ props2[a.name] = a.value;
206
202
  }
207
- root.push(props);
203
+ root.push(props2);
208
204
  }
209
205
  if (element.hasChildNodes()) {
210
206
  const remove = [];
211
- for (let child of element.childNodes) {
212
- const wet = child && hydrate(child, prepareForRender);
213
- if (wet)
214
- root.push(wet);
215
- else if (child && prepareForRender)
216
- remove.push(child);
207
+ for (let child2 of element.childNodes) {
208
+ const wet = child2 && hydrate(child2, prepareForRender);
209
+ if (wet) root.push(wet);
210
+ else if (child2 && prepareForRender) remove.push(child2);
217
211
  }
218
- for (let child of remove) {
219
- child.remove();
212
+ for (let child2 of remove) {
213
+ child2.remove();
220
214
  }
221
215
  }
222
216
  return root;
223
217
  } else {
224
- return;
218
+ return void 0;
225
219
  }
226
220
  }
227
221
  function memo(compare, componentOrProps) {
228
- if (!compare || !Array.isArray(compare))
229
- throw new Error("first argument to memo() must be an array of values to compare");
230
- if (typeof componentOrProps !== "function")
231
- throw new Error("second argument to memo() must be a function that returns a vode or props object");
222
+ if (!compare || !Array.isArray(compare)) throw new Error("first argument to memo() must be an array of values to compare");
223
+ if (typeof componentOrProps !== "function") throw new Error("second argument to memo() must be a function that returns a vode or props object");
232
224
  componentOrProps.__memo = compare;
233
225
  return componentOrProps;
234
226
  }
235
227
  function createState(state) {
236
- if (!state || typeof state !== "object")
237
- throw new Error("createState() must be called with a state object");
228
+ if (!state || typeof state !== "object") throw new Error("createState() must be called with a state object");
238
229
  return state;
239
230
  }
240
231
  function createPatch(p) {
241
232
  return p;
242
233
  }
243
234
  function tag(v) {
244
- return v ? Array.isArray(v) ? v[0] : typeof v === "string" || v.nodeType === Node.TEXT_NODE ? "#text" : undefined : undefined;
235
+ return !!v ? Array.isArray(v) ? v[0] : typeof v === "string" || v.nodeType === Node.TEXT_NODE ? "#text" : void 0 : void 0;
245
236
  }
246
237
  function props(vode2) {
247
238
  if (Array.isArray(vode2) && vode2.length > 1 && vode2[1] && !Array.isArray(vode2[1])) {
@@ -249,7 +240,7 @@ function props(vode2) {
249
240
  return vode2[1];
250
241
  }
251
242
  }
252
- return;
243
+ return void 0;
253
244
  }
254
245
  function children(vode2) {
255
246
  const start = childrenStart(vode2);
@@ -260,23 +251,19 @@ function children(vode2) {
260
251
  }
261
252
  function childCount(vode2) {
262
253
  const start = childrenStart(vode2);
263
- if (start < 0)
264
- return 0;
254
+ if (start < 0) return 0;
265
255
  return vode2.length - start;
266
256
  }
267
257
  function child(vode2, index) {
268
258
  const start = childrenStart(vode2);
269
- if (start > 0)
270
- return vode2[index + start];
271
- else
272
- return;
259
+ if (start > 0) return vode2[index + start];
260
+ else return void 0;
273
261
  }
274
262
  function childrenStart(vode2) {
275
263
  return props(vode2) ? vode2.length > 2 ? 2 : -1 : Array.isArray(vode2) && vode2.length > 1 ? 1 : -1;
276
264
  }
277
265
  function mergeState(target, source, allowDeletion) {
278
- if (!source)
279
- return target;
266
+ if (!source) return target;
280
267
  for (const key in source) {
281
268
  const value = source[key];
282
269
  if (value && typeof value === "object") {
@@ -287,12 +274,9 @@ function mergeState(target, source, allowDeletion) {
287
274
  } else if (value instanceof Date && targetValue !== value) {
288
275
  target[key] = new Date(value);
289
276
  } else {
290
- if (Array.isArray(targetValue))
291
- target[key] = mergeState({}, value, allowDeletion);
292
- else if (typeof targetValue === "object")
293
- mergeState(target[key], value, allowDeletion);
294
- else
295
- target[key] = mergeState({}, value, allowDeletion);
277
+ if (Array.isArray(targetValue)) target[key] = mergeState({}, value, allowDeletion);
278
+ else if (typeof targetValue === "object") mergeState(target[key], value, allowDeletion);
279
+ else target[key] = mergeState({}, value, allowDeletion);
296
280
  }
297
281
  } else if (Array.isArray(value)) {
298
282
  target[key] = [...value];
@@ -301,7 +285,7 @@ function mergeState(target, source, allowDeletion) {
301
285
  } else {
302
286
  target[key] = mergeState({}, value, allowDeletion);
303
287
  }
304
- } else if (value === undefined && allowDeletion) {
288
+ } else if (value === void 0 && allowDeletion) {
305
289
  delete target[key];
306
290
  } else {
307
291
  target[key] = value;
@@ -321,7 +305,7 @@ function render(state, patch, parent, childIndex, oldVode, newVode, xmlns) {
321
305
  if (isNoVode) {
322
306
  oldNode?.onUnmount && patch(oldNode.onUnmount(oldNode));
323
307
  oldNode?.remove();
324
- return;
308
+ return void 0;
325
309
  }
326
310
  const isText = !isNoVode && isTextVode(newVode);
327
311
  const isNode = !isNoVode && isNaturalVode(newVode);
@@ -356,13 +340,17 @@ function render(state, patch, parent, childIndex, oldVode, newVode, xmlns) {
356
340
  if (isNode && (!oldNode || oldIsText || oldVode[0] !== newVode[0])) {
357
341
  const newvode = newVode;
358
342
  if (1 in newvode) {
359
- newvode[1] = remember(state, newvode[1], undefined);
343
+ newvode[1] = remember(state, newvode[1], void 0);
360
344
  }
361
345
  const properties = props(newVode);
362
346
  xmlns = properties?.xmlns || xmlns;
363
347
  const newNode = xmlns ? document.createElementNS(xmlns, newVode[0]) : document.createElement(newVode[0]);
364
348
  newVode.node = newNode;
365
- patchProperties(state, patch, newNode, undefined, properties);
349
+ patchProperties(state, patch, newNode, void 0, properties);
350
+ if (!!properties && "catch" in properties) {
351
+ newVode.node["catch"] = null;
352
+ newVode.node.removeAttribute("catch");
353
+ }
366
354
  if (oldNode) {
367
355
  oldNode.onUnmount && patch(oldNode.onUnmount(oldNode));
368
356
  oldNode.replaceWith(newNode);
@@ -375,9 +363,9 @@ function render(state, patch, parent, childIndex, oldVode, newVode, xmlns) {
375
363
  }
376
364
  const newChildren = children(newVode);
377
365
  if (newChildren) {
378
- for (let i = 0;i < newChildren.length; i++) {
366
+ for (let i = 0; i < newChildren.length; i++) {
379
367
  const child2 = newChildren[i];
380
- const attached = render(state, patch, newNode, i, undefined, child2, xmlns);
368
+ const attached = render(state, patch, newNode, i, void 0, child2, xmlns);
381
369
  newVode[properties ? i + 2 : i + 1] = attached;
382
370
  }
383
371
  }
@@ -388,28 +376,26 @@ function render(state, patch, parent, childIndex, oldVode, newVode, xmlns) {
388
376
  newVode.node = oldNode;
389
377
  const newvode = newVode;
390
378
  const oldvode = oldVode;
391
- let hasProps = false;
379
+ const properties = props(newVode);
380
+ let hasProps = !!properties;
381
+ const oldProps = props(oldVode);
392
382
  if (newvode[1]?.__memo) {
393
383
  const prev = newvode[1];
394
384
  newvode[1] = remember(state, newvode[1], oldvode[1]);
395
385
  if (prev !== newvode[1]) {
396
- const properties = props(newVode);
397
- patchProperties(state, patch, oldNode, props(oldVode), properties);
398
- hasProps = !!properties;
386
+ patchProperties(state, patch, oldNode, oldProps, properties);
399
387
  }
400
388
  } else {
401
- const properties = props(newVode);
402
- patchProperties(state, patch, oldNode, props(oldVode), properties);
403
- hasProps = !!properties;
404
- if (hasProps && "catch" in properties) {
405
- newVode.node["catch"] = null;
406
- newVode.node.removeAttribute("catch");
407
- }
389
+ patchProperties(state, patch, oldNode, oldProps, properties);
390
+ }
391
+ if (!!properties?.catch && oldProps?.catch !== properties.catch) {
392
+ newVode.node["catch"] = null;
393
+ newVode.node.removeAttribute("catch");
408
394
  }
409
395
  const newKids = children(newVode);
410
396
  const oldKids = children(oldVode);
411
397
  if (newKids) {
412
- for (let i = 0;i < newKids.length; i++) {
398
+ for (let i = 0; i < newKids.length; i++) {
413
399
  const child2 = newKids[i];
414
400
  const oldChild = oldKids && oldKids[i];
415
401
  const attached = render(state, patch, oldNode, i, oldChild, child2, xmlns);
@@ -420,8 +406,8 @@ function render(state, patch, parent, childIndex, oldVode, newVode, xmlns) {
420
406
  }
421
407
  if (oldKids) {
422
408
  const newKidsCount = newKids ? newKids.length : 0;
423
- for (let i = oldKids.length - 1;i >= newKidsCount; i--) {
424
- render(state, patch, oldNode, i, oldKids[i], undefined, xmlns);
409
+ for (let i = oldKids.length - 1; i >= newKidsCount; i--) {
410
+ render(state, patch, oldNode, i, oldKids[i], void 0, xmlns);
425
411
  }
426
412
  }
427
413
  return newVode;
@@ -430,12 +416,20 @@ function render(state, patch, parent, childIndex, oldVode, newVode, xmlns) {
430
416
  const catchVode = props(newVode)?.catch;
431
417
  if (catchVode) {
432
418
  const handledVode = typeof catchVode === "function" ? catchVode(state, error) : catchVode;
433
- return render(state, patch, parent, childIndex, hydrate(newVode?.node || oldVode?.node, true), handledVode, xmlns);
419
+ return render(
420
+ state,
421
+ patch,
422
+ parent,
423
+ childIndex,
424
+ hydrate(newVode?.node || oldVode?.node, true),
425
+ handledVode,
426
+ xmlns
427
+ );
434
428
  } else {
435
429
  throw error;
436
430
  }
437
431
  }
438
- return;
432
+ return void 0;
439
433
  }
440
434
  function isNaturalVode(x) {
441
435
  return Array.isArray(x) && x.length > 0 && typeof x[0] === "string";
@@ -450,14 +444,13 @@ function remember(state, present, past) {
450
444
  const pastMemo = past?.__memo;
451
445
  if (Array.isArray(presentMemo) && Array.isArray(pastMemo) && presentMemo.length === pastMemo.length) {
452
446
  let same = true;
453
- for (let i = 0;i < presentMemo.length; i++) {
447
+ for (let i = 0; i < presentMemo.length; i++) {
454
448
  if (presentMemo[i] !== pastMemo[i]) {
455
449
  same = false;
456
450
  break;
457
451
  }
458
452
  }
459
- if (same)
460
- return past;
453
+ if (same) return past;
461
454
  }
462
455
  const newRender = unwrap(present, state);
463
456
  if (typeof newRender === "object") {
@@ -473,17 +466,14 @@ function unwrap(c, s) {
473
466
  }
474
467
  }
475
468
  function patchProperties(s, patch, node, oldProps, newProps) {
476
- if (!newProps && !oldProps)
477
- return;
469
+ if (!newProps && !oldProps) return;
478
470
  if (oldProps) {
479
471
  for (const key in oldProps) {
480
472
  const oldValue = oldProps[key];
481
473
  const newValue = newProps?.[key];
482
474
  if (oldValue !== newValue) {
483
- if (newProps)
484
- newProps[key] = patchProperty(s, patch, node, key, oldValue, newValue);
485
- else
486
- patchProperty(s, patch, node, key, oldValue, undefined);
475
+ if (newProps) newProps[key] = patchProperty(s, patch, node, key, oldValue, newValue);
476
+ else patchProperty(s, patch, node, key, oldValue, void 0);
487
477
  }
488
478
  }
489
479
  }
@@ -491,13 +481,13 @@ function patchProperties(s, patch, node, oldProps, newProps) {
491
481
  for (const key in newProps) {
492
482
  if (!(key in oldProps)) {
493
483
  const newValue = newProps[key];
494
- newProps[key] = patchProperty(s, patch, node, key, undefined, newValue);
484
+ newProps[key] = patchProperty(s, patch, node, key, void 0, newValue);
495
485
  }
496
486
  }
497
487
  } else if (newProps) {
498
488
  for (const key in newProps) {
499
489
  const newValue = newProps[key];
500
- newProps[key] = patchProperty(s, patch, node, key, undefined, newValue);
490
+ newProps[key] = patchProperty(s, patch, node, key, void 0, newValue);
501
491
  }
502
492
  }
503
493
  }
@@ -506,8 +496,7 @@ function patchProperty(s, patch, node, key, oldValue, newValue) {
506
496
  if (!newValue) {
507
497
  node.style.cssText = "";
508
498
  } else if (typeof newValue === "string") {
509
- if (oldValue !== newValue)
510
- node.style.cssText = newValue;
499
+ if (oldValue !== newValue) node.style.cssText = newValue;
511
500
  } else if (oldValue && typeof oldValue === "object") {
512
501
  for (let k in oldValue) {
513
502
  const nv = newValue[k];
@@ -548,7 +537,7 @@ function patchProperty(s, patch, node, key, oldValue, newValue) {
548
537
  }
549
538
  } else {
550
539
  node[key] = newValue;
551
- if (newValue === undefined || newValue === null || newValue === false)
540
+ if (newValue === void 0 || newValue === null || newValue === false)
552
541
  node.removeAttribute(key);
553
542
  else
554
543
  node.setAttribute(key, newValue);
@@ -565,6 +554,7 @@ function classString(classProp) {
565
554
  else
566
555
  return "";
567
556
  }
557
+
568
558
  // src/vode-tags.ts
569
559
  var A = "a";
570
560
  var ABBR = "abbr";
@@ -767,14 +757,13 @@ var MTR = "mtr";
767
757
  var MUNDER = "munder";
768
758
  var MUNDEROVER = "munderover";
769
759
  var SEMANTICS = "semantics";
760
+
770
761
  // src/merge-class.ts
771
762
  function mergeClass(...classes) {
772
- if (!classes || classes.length === 0)
773
- return null;
774
- if (classes.length === 1)
775
- return classes[0];
763
+ if (!classes || classes.length === 0) return null;
764
+ if (classes.length === 1) return classes[0];
776
765
  let finalClass = classes[0];
777
- for (let index = 1;index < classes.length; index++) {
766
+ for (let index = 1; index < classes.length; index++) {
778
767
  const a = finalClass, b = classes[index];
779
768
  if (!a) {
780
769
  finalClass = b;
@@ -783,16 +772,16 @@ function mergeClass(...classes) {
783
772
  } else if (typeof a === "string" && typeof b === "string") {
784
773
  const aSplit = a.split(" ");
785
774
  const bSplit = b.split(" ");
786
- const classSet = new Set([...aSplit, ...bSplit]);
775
+ const classSet = /* @__PURE__ */ new Set([...aSplit, ...bSplit]);
787
776
  finalClass = Array.from(classSet).join(" ").trim();
788
777
  } else if (typeof a === "string" && Array.isArray(b)) {
789
- const classSet = new Set([...b, ...a.split(" ")]);
778
+ const classSet = /* @__PURE__ */ new Set([...b, ...a.split(" ")]);
790
779
  finalClass = Array.from(classSet).join(" ").trim();
791
780
  } else if (Array.isArray(a) && typeof b === "string") {
792
- const classSet = new Set([...a, ...b.split(" ")]);
781
+ const classSet = /* @__PURE__ */ new Set([...a, ...b.split(" ")]);
793
782
  finalClass = Array.from(classSet).join(" ").trim();
794
783
  } else if (Array.isArray(a) && Array.isArray(b)) {
795
- const classSet = new Set([...a, ...b]);
784
+ const classSet = /* @__PURE__ */ new Set([...a, ...b]);
796
785
  finalClass = Array.from(classSet).join(" ").trim();
797
786
  } else if (typeof a === "string" && typeof b === "object") {
798
787
  finalClass = { [a]: true, ...b };
@@ -815,25 +804,23 @@ function mergeClass(...classes) {
815
804
  aa[bKey] = b[bKey];
816
805
  }
817
806
  finalClass = aa;
818
- } else
819
- throw new Error(`cannot merge classes of ${a} (${typeof a}) and ${b} (${typeof b})`);
807
+ } else throw new Error(`cannot merge classes of ${a} (${typeof a}) and ${b} (${typeof b})`);
820
808
  }
821
809
  return finalClass;
822
810
  }
811
+
823
812
  // src/state-context.ts
824
- class KeyStateContext {
825
- state;
826
- path;
827
- keys;
813
+ var KeyStateContext = class {
828
814
  constructor(state, path) {
829
815
  this.state = state;
830
816
  this.path = path;
831
817
  this.keys = path.split(".");
832
818
  }
819
+ keys;
833
820
  get() {
834
821
  const keys = this.keys;
835
- let raw = this.state ? this.state[keys[0]] : undefined;
836
- for (let i = 1;i < keys.length && !!raw; i++) {
822
+ let raw = this.state ? this.state[keys[0]] : void 0;
823
+ for (let i = 1; i < keys.length && !!raw; i++) {
837
824
  raw = raw[keys[i]];
838
825
  }
839
826
  return raw;
@@ -852,6 +839,19 @@ class KeyStateContext {
852
839
  this.state.patch(this.createPatch(value));
853
840
  }
854
841
  }
842
+ /**
843
+ * Creates a render-patch for the parent state by setting a nested sub-state value while creating necessary structure.
844
+ *
845
+ * @example
846
+ * ```typescript
847
+ * const ctx = new KeyStateContext(state, 'user.profile.settings');
848
+ * const patch = ctx.createPatch({ theme: 'light' });
849
+ * // patch is { user: { profile: { settings: { theme: 'light' } } } }
850
+ * ```
851
+ *
852
+ * @param value
853
+ * @returns {{key-path}:{...: value}} render-patch for the parent state
854
+ */
855
855
  createPatch(value) {
856
856
  const renderPatch = {};
857
857
  this.putDeep(value, renderPatch);
@@ -865,7 +865,7 @@ class KeyStateContext {
865
865
  if (typeof raw !== "object" || raw === null) {
866
866
  target[keys[i]] = raw = {};
867
867
  }
868
- for (i = 1;i < keys.length - 1; i++) {
868
+ for (i = 1; i < keys.length - 1; i++) {
869
869
  const p = raw;
870
870
  raw = raw[keys[i]];
871
871
  if (typeof raw !== "object" || raw === null) {
@@ -880,237 +880,232 @@ class KeyStateContext {
880
880
  target[keys[0]] = value;
881
881
  }
882
882
  }
883
- }
884
-
885
- class DelegateStateContext {
886
- state;
887
- get;
888
- put;
889
- patch;
883
+ };
884
+ var DelegateStateContext = class {
890
885
  constructor(state, get, put, patch) {
891
886
  this.state = state;
892
887
  this.get = get;
893
888
  this.put = put;
894
889
  this.patch = patch;
895
890
  }
896
- }
891
+ };
897
892
  export {
898
- vode,
899
- tag,
900
- props,
901
- mergeClass,
902
- memo,
903
- hydrate,
904
- globals,
905
- defuse,
906
- createState,
907
- createPatch,
908
- childrenStart,
909
- children,
910
- childCount,
911
- child,
912
- app,
913
- WBR,
914
- VIEW,
915
- VIDEO,
916
- VAR,
917
- USE,
918
- UL,
919
- U,
920
- TSPAN,
921
- TRACK,
922
- TR,
923
- TITLE,
924
- TIME,
925
- THEAD,
926
- TH,
927
- TFOOT,
928
- TEXTPATH,
929
- TEXTAREA,
930
- TEXT,
931
- TEMPLATE,
932
- TD,
933
- TBODY,
934
- TABLE,
935
- SYMBOL,
936
- SWITCH,
937
- SVG,
938
- SUP,
939
- SUMMARY,
940
- SUB,
941
- STYLE,
942
- STRONG,
943
- STOP,
944
- SPAN,
945
- SOURCE,
946
- SMALL,
947
- SLOT,
948
- SET,
949
- SEMANTICS,
950
- SELECT,
951
- SECTION,
952
- SEARCH,
953
- SCRIPT,
954
- SAMP,
955
- S,
956
- RUBY,
957
- RT,
958
- RP,
959
- RECT,
960
- RADIALGRADIENT,
961
- Q,
962
- PROGRESS,
963
- PRE,
964
- POLYLINE,
965
- POLYGON,
966
- PICTURE,
967
- PATTERN,
968
- PATH,
969
- P,
970
- OUTPUT,
971
- OPTION,
972
- OPTGROUP,
973
- OL,
974
- OBJECT,
975
- NOSCRIPT,
976
- NAV,
977
- MUNDEROVER,
978
- MUNDER,
979
- MTR,
980
- MTEXT,
981
- MTD,
982
- MTABLE,
983
- MSUP,
984
- MSUBSUP,
985
- MSUB,
986
- MSTYLE,
987
- MSQRT,
988
- MSPACE,
989
- MS,
990
- MROW,
991
- MROOT,
992
- MPRESCRIPTS,
993
- MPHANTOM,
994
- MPATH,
995
- MPADDED,
996
- MOVER,
997
- MO,
998
- MN,
999
- MMULTISCRIPTS,
1000
- MI,
1001
- MFRAC,
1002
- METER,
1003
- METADATA,
1004
- META,
1005
- MERROR,
1006
- MENU,
1007
- MATH,
1008
- MASK,
1009
- MARKER,
1010
- MARK,
1011
- MAP,
1012
- MAIN,
1013
- MACTION,
1014
- LINK,
1015
- LINEARGRADIENT,
1016
- LINE,
1017
- LI,
1018
- LEGEND,
1019
- LABEL,
1020
- KeyStateContext,
1021
- KBD,
1022
- INS,
1023
- INPUT,
1024
- IMG,
1025
- IMAGE,
1026
- IFRAME,
1027
- I,
1028
- HTML,
1029
- HR,
1030
- HGROUP,
1031
- HEADER,
1032
- HEAD,
1033
- H6,
1034
- H5,
1035
- H4,
1036
- H3,
1037
- H2,
1038
- H1,
1039
- G,
1040
- FORM,
1041
- FOREIGNOBJECT,
1042
- FOOTER,
1043
- FILTER,
1044
- FIGURE,
1045
- FIGCAPTION,
1046
- FIELDSET,
1047
- FETURBULENCE,
1048
- FETILE,
1049
- FESPOTLIGHT,
1050
- FESPECULARLIGHTING,
1051
- FEPOINTLIGHT,
1052
- FEOFFSET,
1053
- FEMORPHOLOGY,
1054
- FEMERGENODE,
1055
- FEMERGE,
1056
- FEIMAGE,
1057
- FEGAUSSIANBLUR,
1058
- FEFUNCR,
1059
- FEFUNCG,
1060
- FEFUNCB,
1061
- FEFUNCA,
1062
- FEFLOOD,
1063
- FEDROPSHADOW,
1064
- FEDISTANTLIGHT,
1065
- FEDISPLACEMENTMAP,
1066
- FEDIFFUSELIGHTING,
1067
- FECONVOLVEMATRIX,
1068
- FECOMPOSITE,
1069
- FECOMPONENTTRANSFER,
1070
- FECOLORMATRIX,
1071
- FEBLEND,
1072
- EMBED,
1073
- EM,
1074
- ELLIPSE,
1075
- DelegateStateContext,
1076
- DT,
1077
- DL,
1078
- DIV,
1079
- DIALOG,
1080
- DFN,
1081
- DETAILS,
1082
- DESC,
1083
- DEL,
1084
- DEFS,
1085
- DD,
1086
- DATALIST,
1087
- DATA,
1088
- COLGROUP,
1089
- COL,
1090
- CODE,
1091
- CLIPPATH,
1092
- CITE,
1093
- CIRCLE,
1094
- CAPTION,
1095
- CANVAS,
1096
- BUTTON,
1097
- BR,
1098
- BODY,
1099
- BLOCKQUOTE,
1100
- BDO,
1101
- BDI,
1102
- BASE,
1103
- B,
1104
- AUDIO,
1105
- ASIDE,
1106
- ARTICLE,
1107
- AREA,
1108
- ANNOTATION_XML,
1109
- ANNOTATION,
1110
- ANIMATETRANSFORM,
1111
- ANIMATEMOTION,
1112
- ANIMATE,
1113
- ADDRESS,
893
+ A,
1114
894
  ABBR,
1115
- A
895
+ ADDRESS,
896
+ ANIMATE,
897
+ ANIMATEMOTION,
898
+ ANIMATETRANSFORM,
899
+ ANNOTATION,
900
+ ANNOTATION_XML,
901
+ AREA,
902
+ ARTICLE,
903
+ ASIDE,
904
+ AUDIO,
905
+ B,
906
+ BASE,
907
+ BDI,
908
+ BDO,
909
+ BLOCKQUOTE,
910
+ BODY,
911
+ BR,
912
+ BUTTON,
913
+ CANVAS,
914
+ CAPTION,
915
+ CIRCLE,
916
+ CITE,
917
+ CLIPPATH,
918
+ CODE,
919
+ COL,
920
+ COLGROUP,
921
+ DATA,
922
+ DATALIST,
923
+ DD,
924
+ DEFS,
925
+ DEL,
926
+ DESC,
927
+ DETAILS,
928
+ DFN,
929
+ DIALOG,
930
+ DIV,
931
+ DL,
932
+ DT,
933
+ DelegateStateContext,
934
+ ELLIPSE,
935
+ EM,
936
+ EMBED,
937
+ FEBLEND,
938
+ FECOLORMATRIX,
939
+ FECOMPONENTTRANSFER,
940
+ FECOMPOSITE,
941
+ FECONVOLVEMATRIX,
942
+ FEDIFFUSELIGHTING,
943
+ FEDISPLACEMENTMAP,
944
+ FEDISTANTLIGHT,
945
+ FEDROPSHADOW,
946
+ FEFLOOD,
947
+ FEFUNCA,
948
+ FEFUNCB,
949
+ FEFUNCG,
950
+ FEFUNCR,
951
+ FEGAUSSIANBLUR,
952
+ FEIMAGE,
953
+ FEMERGE,
954
+ FEMERGENODE,
955
+ FEMORPHOLOGY,
956
+ FEOFFSET,
957
+ FEPOINTLIGHT,
958
+ FESPECULARLIGHTING,
959
+ FESPOTLIGHT,
960
+ FETILE,
961
+ FETURBULENCE,
962
+ FIELDSET,
963
+ FIGCAPTION,
964
+ FIGURE,
965
+ FILTER,
966
+ FOOTER,
967
+ FOREIGNOBJECT,
968
+ FORM,
969
+ G,
970
+ H1,
971
+ H2,
972
+ H3,
973
+ H4,
974
+ H5,
975
+ H6,
976
+ HEAD,
977
+ HEADER,
978
+ HGROUP,
979
+ HR,
980
+ HTML,
981
+ I,
982
+ IFRAME,
983
+ IMAGE,
984
+ IMG,
985
+ INPUT,
986
+ INS,
987
+ KBD,
988
+ KeyStateContext,
989
+ LABEL,
990
+ LEGEND,
991
+ LI,
992
+ LINE,
993
+ LINEARGRADIENT,
994
+ LINK,
995
+ MACTION,
996
+ MAIN,
997
+ MAP,
998
+ MARK,
999
+ MARKER,
1000
+ MASK,
1001
+ MATH,
1002
+ MENU,
1003
+ MERROR,
1004
+ META,
1005
+ METADATA,
1006
+ METER,
1007
+ MFRAC,
1008
+ MI,
1009
+ MMULTISCRIPTS,
1010
+ MN,
1011
+ MO,
1012
+ MOVER,
1013
+ MPADDED,
1014
+ MPATH,
1015
+ MPHANTOM,
1016
+ MPRESCRIPTS,
1017
+ MROOT,
1018
+ MROW,
1019
+ MS,
1020
+ MSPACE,
1021
+ MSQRT,
1022
+ MSTYLE,
1023
+ MSUB,
1024
+ MSUBSUP,
1025
+ MSUP,
1026
+ MTABLE,
1027
+ MTD,
1028
+ MTEXT,
1029
+ MTR,
1030
+ MUNDER,
1031
+ MUNDEROVER,
1032
+ NAV,
1033
+ NOSCRIPT,
1034
+ OBJECT,
1035
+ OL,
1036
+ OPTGROUP,
1037
+ OPTION,
1038
+ OUTPUT,
1039
+ P,
1040
+ PATH,
1041
+ PATTERN,
1042
+ PICTURE,
1043
+ POLYGON,
1044
+ POLYLINE,
1045
+ PRE,
1046
+ PROGRESS,
1047
+ Q,
1048
+ RADIALGRADIENT,
1049
+ RECT,
1050
+ RP,
1051
+ RT,
1052
+ RUBY,
1053
+ S,
1054
+ SAMP,
1055
+ SCRIPT,
1056
+ SEARCH,
1057
+ SECTION,
1058
+ SELECT,
1059
+ SEMANTICS,
1060
+ SET,
1061
+ SLOT,
1062
+ SMALL,
1063
+ SOURCE,
1064
+ SPAN,
1065
+ STOP,
1066
+ STRONG,
1067
+ STYLE,
1068
+ SUB,
1069
+ SUMMARY,
1070
+ SUP,
1071
+ SVG,
1072
+ SWITCH,
1073
+ SYMBOL,
1074
+ TABLE,
1075
+ TBODY,
1076
+ TD,
1077
+ TEMPLATE,
1078
+ TEXT,
1079
+ TEXTAREA,
1080
+ TEXTPATH,
1081
+ TFOOT,
1082
+ TH,
1083
+ THEAD,
1084
+ TIME,
1085
+ TITLE,
1086
+ TR,
1087
+ TRACK,
1088
+ TSPAN,
1089
+ U,
1090
+ UL,
1091
+ USE,
1092
+ VAR,
1093
+ VIDEO,
1094
+ VIEW,
1095
+ WBR,
1096
+ app,
1097
+ child,
1098
+ childCount,
1099
+ children,
1100
+ childrenStart,
1101
+ createPatch,
1102
+ createState,
1103
+ defuse,
1104
+ globals,
1105
+ hydrate,
1106
+ memo,
1107
+ mergeClass,
1108
+ props,
1109
+ tag,
1110
+ vode
1116
1111
  };