native-document 1.0.104 → 1.0.106

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.
@@ -1,10 +1,10 @@
1
1
  var NativeDocument = (function (exports) {
2
2
  'use strict';
3
3
 
4
- let DebugManager = {};
4
+ let DebugManager$1 = {};
5
5
 
6
6
  {
7
- DebugManager = {
7
+ DebugManager$1 = {
8
8
  enabled: false,
9
9
 
10
10
  enable() {
@@ -35,7 +35,7 @@ var NativeDocument = (function (exports) {
35
35
  };
36
36
 
37
37
  }
38
- var DebugManager$1 = DebugManager;
38
+ var DebugManager = DebugManager$1;
39
39
 
40
40
  class NativeDocumentError extends Error {
41
41
  constructor(message, context = {}) {
@@ -313,10 +313,10 @@ var NativeDocument = (function (exports) {
313
313
  subtree: true,
314
314
  });
315
315
 
316
- let PluginsManager = null;
316
+ let PluginsManager$1 = null;
317
317
 
318
318
  {
319
- PluginsManager = (function() {
319
+ PluginsManager$1 = (function() {
320
320
 
321
321
  const $plugins = new Map();
322
322
  const $pluginByEvents = new Map();
@@ -382,7 +382,7 @@ var NativeDocument = (function (exports) {
382
382
  try{
383
383
  callback.call(plugin, ...data);
384
384
  } catch (error) {
385
- DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
385
+ DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
386
386
  }
387
387
  }
388
388
  }
@@ -391,13 +391,13 @@ var NativeDocument = (function (exports) {
391
391
  }());
392
392
  }
393
393
 
394
- var PluginsManager$1 = PluginsManager;
394
+ var PluginsManager = PluginsManager$1;
395
395
 
396
396
  function NDElement(element) {
397
397
  this.$element = element;
398
398
  this.$observer = null;
399
399
  {
400
- PluginsManager$1.emit('NDElementCreated', element, this);
400
+ PluginsManager.emit('NDElementCreated', element, this);
401
401
  }
402
402
  }
403
403
 
@@ -572,7 +572,7 @@ var NativeDocument = (function (exports) {
572
572
  }
573
573
  {
574
574
  if (this[name] && !this.$localExtensions.has(name)) {
575
- DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
575
+ DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
576
576
  }
577
577
  this.$localExtensions.set(name, method);
578
578
  }
@@ -623,23 +623,23 @@ var NativeDocument = (function (exports) {
623
623
  const method = methods[name];
624
624
 
625
625
  if (typeof method !== 'function') {
626
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
626
+ DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
627
627
  continue;
628
628
  }
629
629
 
630
630
  if (protectedMethods.has(name)) {
631
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
631
+ DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
632
632
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
633
633
  }
634
634
 
635
635
  if (NDElement.prototype[name]) {
636
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
636
+ DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
637
637
  }
638
638
 
639
639
  NDElement.prototype[name] = method;
640
640
  }
641
641
  {
642
- PluginsManager$1.emit('NDElementExtended', methods);
642
+ PluginsManager.emit('NDElementExtended', methods);
643
643
  }
644
644
 
645
645
  return NDElement;
@@ -652,6 +652,13 @@ var NativeDocument = (function (exports) {
652
652
  DOCUMENT_FRAGMENT: 11
653
653
  };
654
654
 
655
+ const VALID_TYPES = {
656
+ [COMMON_NODE_TYPES.ELEMENT]: true,
657
+ [COMMON_NODE_TYPES.TEXT]: true,
658
+ [COMMON_NODE_TYPES.DOCUMENT_FRAGMENT]: true,
659
+ [COMMON_NODE_TYPES.COMMENT]: true
660
+ };
661
+
655
662
  const Validator = {
656
663
  isObservable(value) {
657
664
  return value?.__$isObservable;
@@ -702,12 +709,10 @@ var NativeDocument = (function (exports) {
702
709
  return !(typeof value !== 'object' || value === null || Array.isArray(value) || value.constructor.name !== 'Object')
703
710
  },
704
711
  isElement(value) {
705
- return value && (
706
- value.nodeType === COMMON_NODE_TYPES.ELEMENT ||
707
- value.nodeType === COMMON_NODE_TYPES.TEXT ||
708
- value.nodeType === COMMON_NODE_TYPES.DOCUMENT_FRAGMENT ||
709
- value.nodeType === COMMON_NODE_TYPES.COMMENT
710
- );
712
+ return value && VALID_TYPES[value.nodeType];
713
+ },
714
+ isDOMNode(value) {
715
+ return VALID_TYPES[value.nodeType];
711
716
  },
712
717
  isFragment(value) {
713
718
  return value?.nodeType === COMMON_NODE_TYPES.DOCUMENT_FRAGMENT;
@@ -786,7 +791,7 @@ var NativeDocument = (function (exports) {
786
791
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
787
792
 
788
793
  if (foundReserved.length > 0) {
789
- DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
794
+ DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
790
795
  }
791
796
 
792
797
  return attributes;
@@ -807,7 +812,9 @@ var NativeDocument = (function (exports) {
807
812
  anchorFragment.nativeAppendChild = anchorFragment.appendChild;
808
813
  anchorFragment.nativeAppend = anchorFragment.append;
809
814
 
810
- const isParentUniqueChild = (parent) => (isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd));
815
+ const isParentUniqueChild = isUniqueChild
816
+ ? () => true
817
+ : (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
811
818
 
812
819
  const insertBefore = function(parent, child, target) {
813
820
  const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
@@ -835,7 +842,7 @@ var NativeDocument = (function (exports) {
835
842
  anchorFragment.appendChild = function(child, before = null) {
836
843
  const parent = anchorEnd.parentNode;
837
844
  if(!parent) {
838
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
845
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
839
846
  return;
840
847
  }
841
848
  before = before ?? anchorEnd;
@@ -846,61 +853,58 @@ var NativeDocument = (function (exports) {
846
853
  return anchorFragment.appendChild(args);
847
854
  };
848
855
 
849
- anchorFragment.removeChildren = async function() {
856
+ anchorFragment.removeChildren = function() {
850
857
  const parent = anchorEnd.parentNode;
851
858
  if(parent === anchorFragment) {
852
859
  return;
853
860
  }
854
- // if(isParentUniqueChild(parent)) {
855
- // parent.replaceChildren(anchorStart, anchorEnd);
856
- // return;
857
- // }
861
+ if(isParentUniqueChild(parent)) {
862
+ parent.replaceChildren(anchorStart, anchorEnd);
863
+ return;
864
+ }
858
865
 
859
866
  let itemToRemove = anchorStart.nextSibling, tempItem;
860
- const removes = [];
861
867
  while(itemToRemove && itemToRemove !== anchorEnd) {
862
868
  tempItem = itemToRemove.nextSibling;
863
- removes.push(itemToRemove.remove());
869
+ itemToRemove.remove();
864
870
  itemToRemove = tempItem;
865
871
  }
866
- await Promise.all(removes);
867
872
  };
868
873
 
869
- anchorFragment.remove = async function() {
874
+ anchorFragment.remove = function() {
870
875
  const parent = anchorEnd.parentNode;
871
876
  if(parent === anchorFragment) {
872
877
  return;
873
878
  }
879
+ if(isParentUniqueChild(parent)) {
880
+ parent.replaceChildren(anchorStart, anchorEnd);
881
+ return;
882
+ }
874
883
  let itemToRemove = anchorStart.nextSibling, tempItem;
875
- const allItemToRemove = [];
876
- const removes = [];
877
884
  while(itemToRemove && itemToRemove !== anchorEnd) {
878
885
  tempItem = itemToRemove.nextSibling;
879
- allItemToRemove.push(itemToRemove);
880
- removes.push(itemToRemove.remove());
886
+ anchorFragment.nativeAppend(itemToRemove);
881
887
  itemToRemove = tempItem;
882
888
  }
883
- await Promise.all(removes);
884
- anchorFragment.nativeAppend(...allItemToRemove);
885
889
  };
886
890
 
887
- anchorFragment.removeWithAnchors = async function() {
888
- await anchorFragment.removeChildren();
891
+ anchorFragment.removeWithAnchors = function() {
892
+ anchorFragment.removeChildren();
889
893
  anchorStart.remove();
890
894
  anchorEnd.remove();
891
895
  };
892
896
 
893
- anchorFragment.replaceContent = async function(child) {
897
+ anchorFragment.replaceContent = function(child) {
894
898
  const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
895
899
  const parent = anchorEnd.parentNode;
896
900
  if(!parent) {
897
901
  return;
898
902
  }
899
- // if(isParentUniqueChild(parent)) {
900
- // parent.replaceChildren(anchorStart, childElement, anchorEnd);
901
- // return;
902
- // }
903
- await anchorFragment.removeChildren();
903
+ if(isParentUniqueChild(parent)) {
904
+ parent.replaceChildren(anchorStart, childElement, anchorEnd);
905
+ return;
906
+ }
907
+ anchorFragment.removeChildren();
904
908
  parent.insertBefore(childElement, anchorEnd);
905
909
  };
906
910
 
@@ -910,7 +914,6 @@ var NativeDocument = (function (exports) {
910
914
  anchorFragment.appendChild(child, anchor);
911
915
  };
912
916
 
913
-
914
917
  anchorFragment.endElement = function() {
915
918
  return anchorEnd;
916
919
  };
@@ -1033,7 +1036,7 @@ var NativeDocument = (function (exports) {
1033
1036
  }
1034
1037
  }
1035
1038
  if (cleanedCount > 0) {
1036
- DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1039
+ DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1037
1040
  }
1038
1041
  }
1039
1042
  };
@@ -1235,7 +1238,7 @@ var NativeDocument = (function (exports) {
1235
1238
  const $getStoreOrThrow = (method, name) => {
1236
1239
  const item = $stores.get(name);
1237
1240
  if (!item) {
1238
- DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
1241
+ DebugManager.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
1239
1242
  throw new NativeDocumentError(
1240
1243
  `Store.${method}('${name}') : store not found.`
1241
1244
  );
@@ -1248,7 +1251,7 @@ var NativeDocument = (function (exports) {
1248
1251
  */
1249
1252
  const $applyReadOnly = (observer, name, context) => {
1250
1253
  const readOnlyError = (method) => () => {
1251
- DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
1254
+ DebugManager.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
1252
1255
  throw new NativeDocumentError(
1253
1256
  `Store.${context}('${name}') is read-only.`
1254
1257
  );
@@ -1279,7 +1282,7 @@ var NativeDocument = (function (exports) {
1279
1282
  */
1280
1283
  create(name, value) {
1281
1284
  if ($stores.has(name)) {
1282
- DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
1285
+ DebugManager.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
1283
1286
  throw new NativeDocumentError(
1284
1287
  `Store.create('${name}') : a store with this name already exists.`
1285
1288
  );
@@ -1300,7 +1303,7 @@ var NativeDocument = (function (exports) {
1300
1303
  */
1301
1304
  createResettable(name, value) {
1302
1305
  if ($stores.has(name)) {
1303
- DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
1306
+ DebugManager.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
1304
1307
  throw new NativeDocumentError(
1305
1308
  `Store.createResettable('${name}') : a store with this name already exists.`
1306
1309
  );
@@ -1336,7 +1339,7 @@ var NativeDocument = (function (exports) {
1336
1339
  */
1337
1340
  createComposed(name, computation, dependencies) {
1338
1341
  if ($stores.has(name)) {
1339
- DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
1342
+ DebugManager.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
1340
1343
  throw new NativeDocumentError(
1341
1344
  `Store.createComposed('${name}') : a store with this name already exists.`
1342
1345
  );
@@ -1359,7 +1362,7 @@ var NativeDocument = (function (exports) {
1359
1362
  }
1360
1363
  const depItem = $stores.get(depName);
1361
1364
  if (!depItem) {
1362
- DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
1365
+ DebugManager.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
1363
1366
  throw new NativeDocumentError(
1364
1367
  `Store.createComposed('${name}') : dependency store '${depName}' not found.`
1365
1368
  );
@@ -1393,13 +1396,13 @@ var NativeDocument = (function (exports) {
1393
1396
  reset(name) {
1394
1397
  const item = $getStoreOrThrow('reset', name);
1395
1398
  if (item.composed) {
1396
- DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
1399
+ DebugManager.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
1397
1400
  throw new NativeDocumentError(
1398
1401
  `Store.reset('${name}') : composed stores cannot be reset.`
1399
1402
  );
1400
1403
  }
1401
1404
  if (!item.resettable) {
1402
- DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
1405
+ DebugManager.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
1403
1406
  throw new NativeDocumentError(
1404
1407
  `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
1405
1408
  );
@@ -1420,7 +1423,7 @@ var NativeDocument = (function (exports) {
1420
1423
  const item = $getStoreOrThrow('use', name);
1421
1424
 
1422
1425
  if (item.composed) {
1423
- DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
1426
+ DebugManager.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
1424
1427
  throw new NativeDocumentError(
1425
1428
  `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
1426
1429
  );
@@ -1487,7 +1490,7 @@ var NativeDocument = (function (exports) {
1487
1490
  get(name) {
1488
1491
  const item = $stores.get(name);
1489
1492
  if (!item) {
1490
- DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
1493
+ DebugManager.warn('Store', `Store.get('${name}') : store not found.`);
1491
1494
  return null;
1492
1495
  }
1493
1496
  return item.observer;
@@ -1509,7 +1512,7 @@ var NativeDocument = (function (exports) {
1509
1512
  delete(name) {
1510
1513
  const item = $stores.get(name);
1511
1514
  if (!item) {
1512
- DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
1515
+ DebugManager.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
1513
1516
  return;
1514
1517
  }
1515
1518
  item.subscribers.forEach(follower => follower.destroy());
@@ -1611,7 +1614,7 @@ var NativeDocument = (function (exports) {
1611
1614
  return undefined;
1612
1615
  },
1613
1616
  set(target, prop, value) {
1614
- DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
1617
+ DebugManager.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
1615
1618
  throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
1616
1619
  },
1617
1620
  deleteProperty(target, prop) {
@@ -1743,7 +1746,7 @@ var NativeDocument = (function (exports) {
1743
1746
  }
1744
1747
  }
1745
1748
  {
1746
- PluginsManager$1.emit('CreateObservable', this);
1749
+ PluginsManager.emit('CreateObservable', this);
1747
1750
  }
1748
1751
  }
1749
1752
 
@@ -1847,12 +1850,12 @@ var NativeDocument = (function (exports) {
1847
1850
  this.$previousValue = this.$currentValue;
1848
1851
  this.$currentValue = newValue;
1849
1852
  {
1850
- PluginsManager$1.emit('ObservableBeforeChange', this);
1853
+ PluginsManager.emit('ObservableBeforeChange', this);
1851
1854
  }
1852
1855
  this.trigger();
1853
1856
  this.$previousValue = null;
1854
1857
  {
1855
- PluginsManager$1.emit('ObservableAfterChange', this);
1858
+ PluginsManager.emit('ObservableAfterChange', this);
1856
1859
  }
1857
1860
  };
1858
1861
 
@@ -1885,17 +1888,8 @@ var NativeDocument = (function (exports) {
1885
1888
  };
1886
1889
 
1887
1890
  ObservableItem.prototype.disconnectAll = function() {
1888
- this.$listeners?.splice(0);
1889
1891
  this.$previousValue = null;
1890
1892
  this.$currentValue = null;
1891
- if(this.$watchers) {
1892
- for (const [_, watchValueList] of this.$watchers) {
1893
- if(Validator.isArray(watchValueList)) {
1894
- watchValueList.splice(0);
1895
- }
1896
- }
1897
- }
1898
- this.$watchers?.clear();
1899
1893
  this.$listeners = null;
1900
1894
  this.$watchers = null;
1901
1895
  this.trigger = noneTrigger;
@@ -1939,7 +1933,7 @@ var NativeDocument = (function (exports) {
1939
1933
  ObservableItem.prototype.subscribe = function(callback) {
1940
1934
  {
1941
1935
  if (this.$isCleanedUp) {
1942
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
1936
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
1943
1937
  return;
1944
1938
  }
1945
1939
  if (typeof callback !== 'function') {
@@ -1951,7 +1945,7 @@ var NativeDocument = (function (exports) {
1951
1945
  this.$listeners.push(callback);
1952
1946
  this.assocTrigger();
1953
1947
  {
1954
- PluginsManager$1.emit('ObservableSubscribe', this);
1948
+ PluginsManager.emit('ObservableSubscribe', this);
1955
1949
  }
1956
1950
  };
1957
1951
 
@@ -2062,7 +2056,7 @@ var NativeDocument = (function (exports) {
2062
2056
  }
2063
2057
  this.assocTrigger();
2064
2058
  {
2065
- PluginsManager$1.emit('ObservableUnsubscribe', this);
2059
+ PluginsManager.emit('ObservableUnsubscribe', this);
2066
2060
  }
2067
2061
  };
2068
2062
 
@@ -2494,11 +2488,7 @@ var NativeDocument = (function (exports) {
2494
2488
  TemplateBinding.prototype.__$isTemplateBinding = true;
2495
2489
 
2496
2490
  String.prototype.toNdElement = function () {
2497
- const formattedChild = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
2498
- if(Validator.isString(formattedChild)) {
2499
- return ElementCreator.createStaticTextNode(null, formattedChild);
2500
- }
2501
- return ElementCreator.getChild(null, formattedChild);
2491
+ return ElementCreator.createStaticTextNode(null, this);
2502
2492
  };
2503
2493
 
2504
2494
  Element.prototype.toNdElement = function () {
@@ -2540,7 +2530,7 @@ var NativeDocument = (function (exports) {
2540
2530
  Function.prototype.toNdElement = function () {
2541
2531
  const child = this;
2542
2532
  {
2543
- PluginsManager$1.emit('BeforeProcessComponent', child);
2533
+ PluginsManager.emit('BeforeProcessComponent', child);
2544
2534
  }
2545
2535
  return ElementCreator.getChild(child());
2546
2536
  };
@@ -2728,14 +2718,14 @@ var NativeDocument = (function (exports) {
2728
2718
  processChildren(children, parent) {
2729
2719
  if(children === null) return;
2730
2720
  {
2731
- PluginsManager$1.emit('BeforeProcessChildren', parent);
2721
+ PluginsManager.emit('BeforeProcessChildren', parent);
2732
2722
  }
2733
2723
  let child = this.getChild(children);
2734
2724
  if(child) {
2735
2725
  parent.appendChild(child);
2736
2726
  }
2737
2727
  {
2738
- PluginsManager$1.emit('AfterProcessChildren', parent);
2728
+ PluginsManager.emit('AfterProcessChildren', parent);
2739
2729
  }
2740
2730
  },
2741
2731
  async safeRemove(element) {
@@ -3385,6 +3375,7 @@ var NativeDocument = (function (exports) {
3385
3375
  ElementCreator.bindTextNode(textNode, callbackOrProperty(...data));
3386
3376
  }, 'value');
3387
3377
  };
3378
+ this.text = this.value;
3388
3379
  this.attr = (fn) => {
3389
3380
  return createBinding(fn, 'attributes');
3390
3381
  };
@@ -3991,7 +3982,7 @@ var NativeDocument = (function (exports) {
3991
3982
 
3992
3983
  ObservableItem.call(this, target, configs);
3993
3984
  {
3994
- PluginsManager$1.emit('CreateObservableArray', this);
3985
+ PluginsManager.emit('CreateObservableArray', this);
3995
3986
  }
3996
3987
  };
3997
3988
 
@@ -4623,7 +4614,7 @@ var NativeDocument = (function (exports) {
4623
4614
  const observable = new ObservableItem(initialValue);
4624
4615
  const updatedValue = nextTick(() => observable.set(callback()));
4625
4616
  {
4626
- PluginsManager$1.emit('CreateObservableComputed', observable, dependencies);
4617
+ PluginsManager.emit('CreateObservableComputed', observable, dependencies);
4627
4618
  }
4628
4619
 
4629
4620
  if(Validator.isFunction(dependencies)) {
@@ -4722,7 +4713,7 @@ var NativeDocument = (function (exports) {
4722
4713
  }
4723
4714
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
4724
4715
  } catch (e) {
4725
- DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
4716
+ DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
4726
4717
  throw e;
4727
4718
  }
4728
4719
  return keyId;
@@ -4804,6 +4795,8 @@ var NativeDocument = (function (exports) {
4804
4795
  return element;
4805
4796
  }
4806
4797
 
4798
+ const CREATE_AND_CACHE_ACTIONS = new Set(['clear', 'push', 'unshift', 'replace']);
4799
+
4807
4800
  /**
4808
4801
  * Renders items from an ObservableArray with optimized array-specific updates.
4809
4802
  * Provides index observables and handles array mutations efficiently.
@@ -4864,50 +4857,67 @@ var NativeDocument = (function (exports) {
4864
4857
  if(removeChild) {
4865
4858
  const child = cacheItem.child;
4866
4859
  child?.remove();
4867
- cache.delete(cacheItem.keyId);
4860
+ cache.delete(item);
4868
4861
  }
4869
4862
  cacheItem.indexObserver?.cleanup();
4870
4863
  };
4871
4864
 
4872
- const cleanCache = (items) => {
4873
- if(configs.shouldKeepItemsInCache) {
4874
- return;
4875
- }
4876
- if(!isIndexRequired) {
4877
- cache.clear();
4878
- return;
4865
+ const createAndCache = (item) => {
4866
+ const child = ElementCreator.getChild(callback(item, null));
4867
+ {
4868
+ if(!child) {
4869
+ throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
4870
+ }
4879
4871
  }
4880
- for (const [itemAsKey, _] of cache.entries()) {
4881
- if(items && items.contains(itemAsKey)) {
4882
- continue;
4872
+ cache.set(item, { child, indexObserver: null });
4873
+ return child;
4874
+ };
4875
+
4876
+ const createWithIndexAndCache = (item, indexKey) => {
4877
+ const indexObserver = Observable(indexKey);
4878
+ const child = ElementCreator.getChild(callback(item, indexObserver));
4879
+ {
4880
+ if(!child) {
4881
+ throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
4883
4882
  }
4884
- removeCacheItem(itemAsKey, false);
4885
4883
  }
4886
- cache.clear();
4884
+ cache.set(item, { child, indexObserver });
4885
+ return child;
4887
4886
  };
4888
4887
 
4889
- const buildItem = (item, indexKey) => {
4888
+ const getOrCreate = (item, indexKey) => {
4890
4889
  const cacheItem = cache.get(item);
4891
4890
  if(cacheItem) {
4892
4891
  cacheItem.indexObserver?.set(indexKey);
4893
- const child = cacheItem.child;
4894
- if(child) {
4895
- return child;
4896
- }
4897
- cache.delete(item);
4892
+ return cacheItem.child;
4898
4893
  }
4894
+ return createAndCache(item);
4895
+ };
4899
4896
 
4900
- const indexObserver = isIndexRequired ? Observable(indexKey) : null;
4901
- let child = ElementCreator.getChild(callback(item, indexObserver));
4902
- if(child) {
4903
- cache.set(item, {
4904
- child,
4905
- indexObserver
4906
- });
4907
- return child;
4897
+ let buildItem = createAndCache;
4898
+ const selectBuildStrategy = (action = null) => {
4899
+ if(CREATE_AND_CACHE_ACTIONS.has(action)) {
4900
+ buildItem = isIndexRequired ? createWithIndexAndCache : createAndCache;
4901
+ return;
4908
4902
  }
4903
+ buildItem = cache.size ? getOrCreate : (isIndexRequired ? createWithIndexAndCache : createAndCache);
4904
+ };
4909
4905
 
4910
- throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
4906
+
4907
+ const cleanCache = (items) => {
4908
+ if(!isIndexRequired) {
4909
+ cache.clear();
4910
+ return;
4911
+ }
4912
+ if(configs.shouldKeepItemsInCache) {
4913
+ return;
4914
+ }
4915
+ for (const [itemAsKey, _] of cache.entries()) {
4916
+ if(items && items.includes(itemAsKey)) {
4917
+ continue;
4918
+ }
4919
+ removeCacheItem(itemAsKey, false);
4920
+ }
4911
4921
  };
4912
4922
 
4913
4923
  const removeByItem = function(item, fragment) {
@@ -4928,7 +4938,7 @@ var NativeDocument = (function (exports) {
4928
4938
  };
4929
4939
 
4930
4940
  const Actions = {
4931
- toFragment(items, startIndexFrom = 0){
4941
+ toFragment(items){
4932
4942
  const fragment = document.createDocumentFragment();
4933
4943
  for(let i = 0, length = items.length; i < length; i++) {
4934
4944
  fragment.appendChild(buildItem(items[i], lastNumberOfItems));
@@ -4936,7 +4946,7 @@ var NativeDocument = (function (exports) {
4936
4946
  }
4937
4947
  return fragment;
4938
4948
  },
4939
- add(items, delay = 2) {
4949
+ add(items) {
4940
4950
  element.appendElement(Actions.toFragment(items));
4941
4951
  },
4942
4952
  replace(items) {
@@ -5051,6 +5061,7 @@ var NativeDocument = (function (exports) {
5051
5061
  clear();
5052
5062
  return;
5053
5063
  }
5064
+ selectBuildStrategy(operations?.action);
5054
5065
 
5055
5066
  if(!operations?.action) {
5056
5067
  if(lastNumberOfItems === 0) {
@@ -5092,7 +5103,7 @@ var NativeDocument = (function (exports) {
5092
5103
  */
5093
5104
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
5094
5105
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
5095
- return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
5106
+ return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
5096
5107
  }
5097
5108
  const element = Anchor('Show if : '+(comment || ''));
5098
5109
 
@@ -6317,13 +6328,13 @@ var NativeDocument = (function (exports) {
6317
6328
  *
6318
6329
  * @param {string} path
6319
6330
  */
6320
- this.match = function(path) {
6331
+ this.match = function(path) {
6321
6332
  path = '/'+trim(path, '/');
6322
6333
  const match = getPattern().exec(path);
6323
6334
  if(!match) return false;
6324
6335
  const params = {};
6325
6336
 
6326
- match.forEach((value, index) => {
6337
+ getPattern().exec(path).forEach((value, index) => {
6327
6338
  if(index < 1) return;
6328
6339
  const name = $paramsNames[index - 1];
6329
6340
  params[name] = value;
@@ -6511,7 +6522,7 @@ var NativeDocument = (function (exports) {
6511
6522
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
6512
6523
  this.handleRouteChange(route, params, query, path);
6513
6524
  } catch (e) {
6514
- DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
6525
+ DebugManager.error('HistoryRouter', 'Error in pushState', e);
6515
6526
  }
6516
6527
  };
6517
6528
  /**
@@ -6524,7 +6535,7 @@ var NativeDocument = (function (exports) {
6524
6535
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
6525
6536
  this.handleRouteChange(route, params, {}, path);
6526
6537
  } catch(e) {
6527
- DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
6538
+ DebugManager.error('HistoryRouter', 'Error in replaceState', e);
6528
6539
  }
6529
6540
  };
6530
6541
  this.forward = function() {
@@ -6551,7 +6562,7 @@ var NativeDocument = (function (exports) {
6551
6562
  }
6552
6563
  this.handleRouteChange(route, params, query, path);
6553
6564
  } catch(e) {
6554
- DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
6565
+ DebugManager.error('HistoryRouter', 'Error in popstate event', e);
6555
6566
  }
6556
6567
  });
6557
6568
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -6652,7 +6663,7 @@ var NativeDocument = (function (exports) {
6652
6663
  }
6653
6664
 
6654
6665
  let anchor = node;
6655
- if(!Validator.isAnchor(node) || Validator.isFragment(node)) {
6666
+ if(!Validator.isAnchor(node)) {
6656
6667
  anchor = Anchor(path);
6657
6668
  anchor.appendChild(node);
6658
6669
  }
@@ -6776,7 +6787,7 @@ var NativeDocument = (function (exports) {
6776
6787
  listener(request);
6777
6788
  next && next(request);
6778
6789
  } catch (e) {
6779
- DebugManager$1.warn('Route Listener', 'Error in listener:', e);
6790
+ DebugManager.warn('Route Listener', 'Error in listener:', e);
6780
6791
  }
6781
6792
  }
6782
6793
  };
@@ -6954,7 +6965,7 @@ var NativeDocument = (function (exports) {
6954
6965
  */
6955
6966
  Router.create = function(options, callback) {
6956
6967
  if(!Validator.isFunction(callback)) {
6957
- DebugManager$1.error('Router', 'Callback must be a function');
6968
+ DebugManager.error('Router', 'Callback must be a function');
6958
6969
  throw new RouterError('Callback must be a function');
6959
6970
  }
6960
6971
  const router = new Router(options);
@@ -7145,10 +7156,9 @@ var NativeDocument = (function (exports) {
7145
7156
  exports.$ = $;
7146
7157
  exports.ElementCreator = ElementCreator;
7147
7158
  exports.HtmlElementWrapper = HtmlElementWrapper;
7148
- exports.LocalStorage = LocalStorage;
7149
7159
  exports.NDElement = NDElement;
7150
7160
  exports.Observable = Observable;
7151
- exports.PluginsManager = PluginsManager$1;
7161
+ exports.PluginsManager = PluginsManager;
7152
7162
  exports.SingletonView = SingletonView;
7153
7163
  exports.Store = Store;
7154
7164
  exports.StoreFactory = StoreFactory;