j-templates 8.0.13 → 8.0.14

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 (49) hide show
  1. package/DOM/createAssignment.js +2 -6
  2. package/DOM/createAttributeAssignment.js +2 -6
  3. package/DOM/createEventAssignment.js +2 -6
  4. package/DOM/createPropertyAssignment.js +10 -14
  5. package/DOM/domNodeConfig.js +27 -30
  6. package/DOM/elements.js +102 -108
  7. package/DOM/index.js +3 -19
  8. package/Node/component.js +12 -16
  9. package/Node/component.types.js +1 -2
  10. package/Node/nodeConfig.js +2 -5
  11. package/Node/vNode.js +64 -67
  12. package/Node/vNode.types.js +5 -9
  13. package/Store/Diff/defaultDiffTreeWorker.d.ts +1 -0
  14. package/Store/Diff/defaultDiffTreeWorker.js +4 -0
  15. package/Store/Diff/diffAsync.d.ts +2 -4
  16. package/Store/Diff/diffAsync.js +4 -33
  17. package/Store/Diff/diffSync.js +3 -10
  18. package/Store/Diff/diffTree.d.ts +66 -41
  19. package/Store/Diff/diffTree.js +357 -427
  20. package/Store/Diff/diffTreeWorker.d.ts +8 -0
  21. package/Store/Diff/diffTreeWorker.js +27 -0
  22. package/Store/Diff/workerQueue.js +6 -10
  23. package/Store/Store/store.js +10 -14
  24. package/Store/Store/storeAsync.d.ts +1 -2
  25. package/Store/Store/storeAsync.js +10 -14
  26. package/Store/Store/storeSync.js +10 -14
  27. package/Store/Tree/observableNode.js +35 -38
  28. package/Store/Tree/observableScope.js +35 -42
  29. package/Store/index.js +5 -13
  30. package/Utils/animation.js +7 -11
  31. package/Utils/array.js +2 -6
  32. package/Utils/asyncQueue.js +7 -11
  33. package/Utils/decorators.js +44 -53
  34. package/Utils/emitter.js +6 -9
  35. package/Utils/functions.js +1 -4
  36. package/Utils/index.js +3 -21
  37. package/Utils/injector.js +2 -6
  38. package/Utils/json.d.ts +32 -10
  39. package/Utils/json.js +195 -208
  40. package/Utils/list.js +2 -5
  41. package/Utils/scheduling.js +4 -7
  42. package/Utils/thread.js +18 -26
  43. package/Utils/utils.types.js +1 -2
  44. package/_not_used/array.js +4 -10
  45. package/_not_used/avlTree.js +2 -5
  46. package/index.js +2 -10
  47. package/package.json +1 -1
  48. package/Store/Diff/diffWorker.d.ts +0 -3
  49. package/Store/Diff/diffWorker.js +0 -21
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * This module provides decorators for managing state, computed values, and dependency injection in components.
4
3
  * These decorators are designed to work with observable data structures, allowing for efficient updates and notifications.
@@ -57,19 +56,9 @@
57
56
  * console.log(list === list2); // @Computed: true, @Scope: false
58
57
  * ```
59
58
  */
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- exports.Bound = void 0;
62
- exports.Computed = Computed;
63
- exports.ComputedAsync = ComputedAsync;
64
- exports.State = State;
65
- exports.Value = Value;
66
- exports.Scope = Scope;
67
- exports.Watch = Watch;
68
- exports.Inject = Inject;
69
- exports.Destroy = Destroy;
70
- const observableScope_1 = require("../Store/Tree/observableScope");
71
- const observableNode_1 = require("../Store/Tree/observableNode");
72
- const Store_1 = require("../Store");
59
+ import { ObservableScope, } from "../Store/Tree/observableScope";
60
+ import { ObservableNode } from "../Store/Tree/observableNode";
61
+ import { StoreAsync } from "../Store";
73
62
  /**
74
63
  * WeakMap for storing node instances and their associated properties.
75
64
  * @private
@@ -134,22 +123,22 @@ function GetDestroyArrayForPrototype(prototype, create = true) {
134
123
  return array;
135
124
  }
136
125
  function CreateStoreScope(getter, store, defaultValue) {
137
- const getterScope = observableScope_1.ObservableScope.Gated(function () {
126
+ const getterScope = ObservableScope.Gated(function () {
138
127
  const value = getter();
139
- return observableNode_1.ObservableNode.Clone(value);
128
+ return ObservableNode.Clone(value);
140
129
  });
141
- observableScope_1.ObservableScope.Watch(getterScope, (scope) => {
142
- const data = observableScope_1.ObservableScope.Peek(scope);
130
+ ObservableScope.Watch(getterScope, (scope) => {
131
+ const data = ObservableScope.Peek(scope);
143
132
  store.Write(data, "root");
144
133
  });
145
- const data = observableScope_1.ObservableScope.Peek(getterScope);
134
+ const data = ObservableScope.Peek(getterScope);
146
135
  store.Write(data, "root");
147
- const propertyScope = observableScope_1.ObservableScope.Create(() => {
136
+ const propertyScope = ObservableScope.Create(() => {
148
137
  return store.Get("root", defaultValue);
149
138
  });
150
- observableScope_1.ObservableScope.OnDestroyed(propertyScope, function () {
151
- observableScope_1.ObservableScope.Destroy(getterScope);
152
- if (store instanceof Store_1.StoreAsync)
139
+ ObservableScope.OnDestroyed(propertyScope, function () {
140
+ ObservableScope.Destroy(getterScope);
141
+ if (store instanceof StoreAsync)
153
142
  store.Destroy();
154
143
  });
155
144
  return propertyScope;
@@ -170,11 +159,11 @@ function CreateStoreScope(getter, store, defaultValue) {
170
159
  * @returns The Gated scope whose value is the observable root node.
171
160
  */
172
161
  function CreateNodeScope(getter) {
173
- const observableNode = observableNode_1.ObservableNode.Create({ root: null });
174
- const getterScope = observableScope_1.ObservableScope.Gated(function () {
162
+ const observableNode = ObservableNode.Create({ root: null });
163
+ const getterScope = ObservableScope.Gated(function () {
175
164
  const value = getter();
176
- const clonedValue = observableNode_1.ObservableNode.Clone(value);
177
- observableNode_1.ObservableNode.Apply(observableNode, { root: clonedValue });
165
+ const clonedValue = ObservableNode.Clone(value);
166
+ ObservableNode.Apply(observableNode, { root: clonedValue });
178
167
  return observableNode.root;
179
168
  });
180
169
  return getterScope;
@@ -280,7 +269,7 @@ function CreateNodeScope(getter) {
280
269
  * @see {@link ObservableScope} for the Gated scope mechanism (batched, ===-gated updates)
281
270
  * @see {@link StoreSync} for the store-backed variant used by @ComputedAsync
282
271
  */
283
- function Computed() {
272
+ export function Computed() {
284
273
  return function (target, propertyKey, descriptor) {
285
274
  return ComputedDecorator(target, propertyKey, descriptor);
286
275
  };
@@ -310,7 +299,7 @@ function ComputedDecorator(target, prop, descriptor) {
310
299
  const propertyScope = CreateNodeScope(getter.bind(this));
311
300
  scopeMap[propertyKey] = [propertyScope, undefined];
312
301
  }
313
- return observableScope_1.ObservableScope.Value(scopeMap[propertyKey][0]);
302
+ return ObservableScope.Value(scopeMap[propertyKey][0]);
314
303
  },
315
304
  };
316
305
  }
@@ -405,7 +394,7 @@ function ComputedDecorator(target, prop, descriptor) {
405
394
  * @see {@link StoreAsync} for async store implementation
406
395
  * @see {@link ObservableScope.Create} for async function support
407
396
  */
408
- function ComputedAsync(defaultValue) {
397
+ export function ComputedAsync(defaultValue) {
409
398
  return function (target, propertyKey, descriptor) {
410
399
  return ComputedAsyncDecorator(target, propertyKey, descriptor, defaultValue);
411
400
  };
@@ -433,10 +422,12 @@ function ComputedAsyncDecorator(target, prop, descriptor, defaultValue) {
433
422
  get: function () {
434
423
  const scopeMap = GetScopeMapForInstance(this);
435
424
  if (scopeMap[propertyKey] === undefined) {
436
- const propertyScope = CreateStoreScope(getter.bind(this), new Store_1.StoreAsync(), defaultValue);
425
+ const worker = new Worker(new URL("../Store/Diff/defaultDiffTreeWorker.js", import.meta.url), { type: "module" });
426
+ const storeAsync = new StoreAsync(worker);
427
+ const propertyScope = CreateStoreScope(getter.bind(this), storeAsync, defaultValue);
437
428
  scopeMap[propertyKey] = [propertyScope, undefined];
438
429
  }
439
- return observableScope_1.ObservableScope.Value(scopeMap[propertyKey][0]);
430
+ return ObservableScope.Value(scopeMap[propertyKey][0]);
440
431
  },
441
432
  };
442
433
  }
@@ -498,7 +489,7 @@ function ComputedAsyncDecorator(target, prop, descriptor, defaultValue) {
498
489
  * @see {@link Computed} for derived/read-only values
499
490
  * @see {@link ObservableNode} for the proxy-based reactivity system
500
491
  */
501
- function State() {
492
+ export function State() {
502
493
  return StateDecorator;
503
494
  }
504
495
  /**
@@ -514,13 +505,13 @@ function StateDecorator(target, propertyKey) {
514
505
  enumerable: true,
515
506
  get: function () {
516
507
  const map = GetNodeMapForInstance(this);
517
- map[propertyKey] ??= observableNode_1.ObservableNode.Create({ root: undefined });
508
+ map[propertyKey] ??= ObservableNode.Create({ root: undefined });
518
509
  return map[propertyKey].root;
519
510
  },
520
511
  set: function (val) {
521
512
  const map = GetNodeMapForInstance(this);
522
513
  if (map[propertyKey] === undefined)
523
- map[propertyKey] ??= observableNode_1.ObservableNode.Create({ root: val });
514
+ map[propertyKey] ??= ObservableNode.Create({ root: val });
524
515
  else
525
516
  map[propertyKey].root = val;
526
517
  },
@@ -587,7 +578,7 @@ function StateDecorator(target, propertyKey) {
587
578
  * @see {@link Computed} for derived/read-only values
588
579
  * @see {@link ObservableScope} for the scope-based reactivity system
589
580
  */
590
- function Value() {
581
+ export function Value() {
591
582
  return ValueDecorator;
592
583
  }
593
584
  /**
@@ -597,7 +588,7 @@ function Value() {
597
588
  * @returns An observable scope created from the tuple's value.
598
589
  */
599
590
  function CreateValueScope(tuple) {
600
- return observableScope_1.ObservableScope.Basic(function () {
591
+ return ObservableScope.Basic(function () {
601
592
  return tuple[1];
602
593
  });
603
594
  }
@@ -616,14 +607,14 @@ function ValueDecorator(target, propertyKey) {
616
607
  const propertyMap = GetScopeMapForInstance(this);
617
608
  const tuple = (propertyMap[propertyKey] ??= [null, undefined]);
618
609
  tuple[0] ??= CreateValueScope(tuple);
619
- return observableScope_1.ObservableScope.Value(tuple[0]);
610
+ return ObservableScope.Value(tuple[0]);
620
611
  },
621
612
  set: function (val) {
622
613
  const propertyMap = GetScopeMapForInstance(this);
623
614
  propertyMap[propertyKey] ??= [null, undefined];
624
615
  const tuple = propertyMap[propertyKey];
625
616
  tuple[1] = val;
626
- observableScope_1.ObservableScope.Update(tuple[0]);
617
+ ObservableScope.Update(tuple[0]);
627
618
  },
628
619
  };
629
620
  }
@@ -746,7 +737,7 @@ function ValueDecorator(target, propertyKey) {
746
737
  * @see {@link ObservableScope} for the scope-based reactivity system
747
738
  * @see {@link scope} for inline computed scopes within @Scope
748
739
  */
749
- function Scope() {
740
+ export function Scope() {
750
741
  return ScopeDecorator;
751
742
  }
752
743
  /**
@@ -772,8 +763,8 @@ function ScopeDecorator(target, propertyKey, descriptor) {
772
763
  propertyMap[propertyKey] ??= [null, undefined];
773
764
  const tuple = propertyMap[propertyKey];
774
765
  if (tuple[0] === null)
775
- tuple[0] = observableScope_1.ObservableScope.Create(getter.bind(this));
776
- return observableScope_1.ObservableScope.Value(tuple[0]);
766
+ tuple[0] = ObservableScope.Create(getter.bind(this));
767
+ return ObservableScope.Value(tuple[0]);
777
768
  },
778
769
  };
779
770
  }
@@ -833,7 +824,7 @@ function ScopeDecorator(target, propertyKey, descriptor) {
833
824
  * @see {@link Destroy} for automatic cleanup on component teardown
834
825
  * @see {@link Scope} for creating computed values to watch
835
826
  */
836
- function Watch(scope) {
827
+ export function Watch(scope) {
837
828
  return function (target, propertyKey, descriptor) {
838
829
  return WatchDecorator(target, propertyKey, descriptor, scope);
839
830
  };
@@ -845,13 +836,13 @@ function WatchDecorator(target, propertyKey, descriptor, scopeFunction) {
845
836
  function scopeFunctionWrapper() {
846
837
  return scopeFunction(instance);
847
838
  }
848
- const scope = observableScope_1.ObservableScope.Gated(scopeFunctionWrapper);
839
+ const scope = ObservableScope.Gated(scopeFunctionWrapper);
849
840
  const propertyMap = GetScopeMapForInstance(instance);
850
841
  propertyMap[propertyKey] = [scope, undefined];
851
- observableScope_1.ObservableScope.Watch(scope, function (scope) {
852
- instance[propertyKey](observableScope_1.ObservableScope.Value(scope));
842
+ ObservableScope.Watch(scope, function (scope) {
843
+ instance[propertyKey](ObservableScope.Value(scope));
853
844
  });
854
- instance[propertyKey](observableScope_1.ObservableScope.Value(scope));
845
+ instance[propertyKey](ObservableScope.Value(scope));
855
846
  return instance;
856
847
  }
857
848
  const boundArray = GetBoundArrayForPrototype(target);
@@ -930,7 +921,7 @@ function WatchDecorator(target, propertyKey, descriptor, scopeFunction) {
930
921
  * @see {@link Injector} for the dependency injection system
931
922
  * @see {@link Component.Injector} for accessing the component's injector
932
923
  */
933
- function Inject(type) {
924
+ export function Inject(type) {
934
925
  return function () {
935
926
  return InjectDecorator(type);
936
927
  };
@@ -1024,14 +1015,14 @@ function InjectDecorator(type) {
1024
1015
  * @see {@link Destroy.All} for the cleanup implementation
1025
1016
  * @see {@link Component.Destroy} for component lifecycle
1026
1017
  */
1027
- function Destroy() {
1018
+ export function Destroy() {
1028
1019
  return DestroyDecorator;
1029
1020
  }
1030
1021
  /**
1031
1022
  * Bound namespace provides lifecycle hooks for component initialization.
1032
1023
  * Methods in this namespace are called after a component is attached to the DOM.
1033
1024
  */
1034
- var Bound;
1025
+ export var Bound;
1035
1026
  (function (Bound) {
1036
1027
  /**
1037
1028
  * Binds all @Watch-decorated methods on a component instance.
@@ -1067,7 +1058,7 @@ var Bound;
1067
1058
  array[x](value);
1068
1059
  }
1069
1060
  Bound.All = All;
1070
- })(Bound || (exports.Bound = Bound = {}));
1061
+ })(Bound || (Bound = {}));
1071
1062
  /**
1072
1063
  * Destroy namespace provides cleanup utilities for component teardown.
1073
1064
  * Methods in this namespace are called when a component is destroyed to prevent memory leaks.
@@ -1122,14 +1113,14 @@ var Bound;
1122
1113
  if (scopeMap !== undefined) {
1123
1114
  const values = Object.values(scopeMap);
1124
1115
  for (let x = 0; x < values.length; x++)
1125
- observableScope_1.ObservableScope.Destroy(values[x][0]);
1116
+ ObservableScope.Destroy(values[x][0]);
1126
1117
  }
1127
1118
  const array = GetDestroyArrayForPrototype(Object.getPrototypeOf(value), false);
1128
1119
  for (let x = 0; array && x < array.length; x++)
1129
1120
  value[array[x]].Destroy();
1130
1121
  }
1131
1122
  Destroy.All = All;
1132
- })(Destroy || (exports.Destroy = Destroy = {}));
1123
+ })(Destroy || (Destroy = {}));
1133
1124
  function DestroyDecorator(target, propertyKey) {
1134
1125
  const array = GetDestroyArrayForPrototype(target);
1135
1126
  array.push(propertyKey);
package/Utils/emitter.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Emitter = void 0;
4
- const array_1 = require("./array");
5
- const scheduling_1 = require("./scheduling");
1
+ import { RemoveNulls } from "./array";
2
+ import { _requestIdleCallback } from "./scheduling";
6
3
  const pendingCompactEmitters = new Set();
7
4
  function Compact(emitter) {
8
5
  if (emitter.length === 1 || emitter[0] === 0)
@@ -15,7 +12,7 @@ function ScheduleCompact() {
15
12
  if (compactScheduled)
16
13
  return;
17
14
  compactScheduled = true;
18
- (0, scheduling_1._requestIdleCallback)(PerformCompact);
15
+ _requestIdleCallback(PerformCompact);
19
16
  }
20
17
  function PerformCompact() {
21
18
  compactScheduled = false;
@@ -30,7 +27,7 @@ function CompactEmitter(emitter) {
30
27
  emitter.splice(1, emitter[0]);
31
28
  emitter[0] = 0;
32
29
  }
33
- var Emitter;
30
+ export var Emitter;
34
31
  (function (Emitter) {
35
32
  function Create() {
36
33
  return [0];
@@ -48,7 +45,7 @@ var Emitter;
48
45
  emitter[x]?.(...args);
49
46
  emitterStack.pop();
50
47
  if (modifiedDuringEmit.delete(emitter)) {
51
- (0, array_1.RemoveNulls)(emitter);
48
+ RemoveNulls(emitter);
52
49
  emitter[0] = 0;
53
50
  }
54
51
  }
@@ -78,4 +75,4 @@ var Emitter;
78
75
  emitter[0] = 0;
79
76
  }
80
77
  Emitter.Clear = Clear;
81
- })(Emitter || (exports.Emitter = Emitter = {}));
78
+ })(Emitter || (Emitter = {}));
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsAsync = IsAsync;
4
1
  /**
5
2
  * Checks if a function is an async function.
6
3
  * @param func - The function to check
7
4
  * @returns true if the function is async, false otherwise
8
5
  */
9
- function IsAsync(func) {
6
+ export function IsAsync(func) {
10
7
  return func && func[Symbol.toStringTag] === "AsyncFunction";
11
8
  }
package/Utils/index.js CHANGED
@@ -1,21 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Injector = void 0;
18
- __exportStar(require("./decorators"), exports);
19
- __exportStar(require("./animation"), exports);
20
- var injector_1 = require("./injector");
21
- Object.defineProperty(exports, "Injector", { enumerable: true, get: function () { return injector_1.Injector; } });
1
+ export * from "./decorators";
2
+ export * from "./animation";
3
+ export { Injector } from "./injector";
package/Utils/injector.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Injector = void 0;
4
1
  /**
5
2
  * Simple scoped dependency injection class. Manages types/instances as key/value pairs.
6
3
  */
7
- class Injector {
4
+ export class Injector {
8
5
  constructor() {
9
6
  this.parent = Injector.Current();
10
7
  this.typeMap = new Map();
@@ -32,7 +29,6 @@ class Injector {
32
29
  return instance;
33
30
  }
34
31
  }
35
- exports.Injector = Injector;
36
32
  (function (Injector) {
37
33
  var scope = null;
38
34
  /**
@@ -62,4 +58,4 @@ exports.Injector = Injector;
62
58
  }
63
59
  }
64
60
  Injector.Scope = Scope;
65
- })(Injector || (exports.Injector = Injector = {}));
61
+ })(Injector || (Injector = {}));
package/Utils/json.d.ts CHANGED
@@ -8,15 +8,37 @@ export type JsonDiffResult<T = unknown> = {
8
8
  /** The new value at this path */
9
9
  value: unknown;
10
10
  }[];
11
- export type JsonDiffFactoryResult = ReturnType<typeof JsonDiffFactory>;
12
11
  /**
13
- * Factory that creates JSON utility functions for diffing, merging, and cloning.
14
- * @returns Object containing JsonDiff, JsonType, JsonDeepClone, and JsonMerge functions
12
+ * Determines the JSON type of a value.
13
+ * @param value - The value to check
14
+ * @returns "value" for primitives/null/undefined, "object" for plain objects, "array" for arrays
15
15
  */
16
- export declare function JsonDiffFactory(): {
17
- JsonDiff: <T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>) => JsonDiffResult<T>;
18
- JsonType: (value: any) => "object" | "value" | "array";
19
- JsonDeepClone: <T>(value: T, type?: string) => T;
20
- JsonMerge: (source: unknown, patch: unknown) => unknown;
21
- };
22
- export declare const JsonDiff: <T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>) => JsonDiffResult<T>, JsonType: (value: any) => "object" | "value" | "array", JsonDeepClone: <T>(value: T, type?: string) => T, JsonMerge: (source: unknown, patch: unknown) => unknown;
16
+ export declare function JsonType(value: any): "object" | "value" | "array";
17
+ /**
18
+ * Deep merges a patch into a source value.
19
+ * - If types don't match, returns the patch
20
+ * - For objects: recursively merges properties, adds new properties
21
+ * - For arrays: maps over patch, merging with corresponding source elements
22
+ * @param source - The original value
23
+ * @param patch - The value to merge into source
24
+ * @returns The merged result
25
+ */
26
+ export declare function JsonMerge(source: unknown, patch: unknown): unknown;
27
+ /**
28
+ * Creates a deep clone of a JSON-compatible value.
29
+ * @template T - The type of the value to clone
30
+ * @param value - The value to clone
31
+ * @returns A deep clone of the value
32
+ */
33
+ export declare function JsonDeepClone<T>(value: T, type?: string): T;
34
+ /**
35
+ * Computes the differences between two JSON values.
36
+ * Returns an array of paths and values that changed from oldValue to newValue.
37
+ * @template T - The type of the JSON values being compared
38
+ * @param newValue - The new value
39
+ * @param oldValue - The old value to compare against
40
+ * @param rootPath - Optional dot-separated string for the base path (for internal recursion)
41
+ * @param initResult - Optional initial result array (for internal recursion)
42
+ * @returns Array of change records with path and new value
43
+ */
44
+ export declare function JsonDiff<T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>): JsonDiffResult<T>;