native-document 1.0.109 → 1.0.111

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$1 = {};
4
+ let DebugManager = {};
5
5
 
6
6
  {
7
- DebugManager$1 = {
7
+ DebugManager = {
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 = DebugManager$1;
38
+ var DebugManager$1 = DebugManager;
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$1 = null;
316
+ let PluginsManager = null;
317
317
 
318
318
  {
319
- PluginsManager$1 = (function() {
319
+ PluginsManager = (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.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
385
+ DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
386
386
  }
387
387
  }
388
388
  }
@@ -391,12 +391,12 @@ var NativeDocument = (function (exports) {
391
391
  }());
392
392
  }
393
393
 
394
- var PluginsManager = PluginsManager$1;
394
+ var PluginsManager$1 = PluginsManager;
395
395
 
396
396
  function NDElement(element) {
397
397
  this.$element = element;
398
398
  {
399
- PluginsManager.emit('NDElementCreated', element, this);
399
+ PluginsManager$1.emit('NDElementCreated', element, this);
400
400
  }
401
401
  }
402
402
 
@@ -576,7 +576,7 @@ var NativeDocument = (function (exports) {
576
576
  }
577
577
  {
578
578
  if (this[name] && !this.$localExtensions.has(name)) {
579
- DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
579
+ DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
580
580
  }
581
581
  this.$localExtensions.set(name, method);
582
582
  }
@@ -627,23 +627,23 @@ var NativeDocument = (function (exports) {
627
627
  const method = methods[name];
628
628
 
629
629
  if (typeof method !== 'function') {
630
- DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
630
+ DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
631
631
  continue;
632
632
  }
633
633
 
634
634
  if (protectedMethods.has(name)) {
635
- DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
635
+ DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
636
636
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
637
637
  }
638
638
 
639
639
  if (NDElement.prototype[name]) {
640
- DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
640
+ DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
641
641
  }
642
642
 
643
643
  NDElement.prototype[name] = method;
644
644
  }
645
645
  {
646
- PluginsManager.emit('NDElementExtended', methods);
646
+ PluginsManager$1.emit('NDElementExtended', methods);
647
647
  }
648
648
 
649
649
  return NDElement;
@@ -656,12 +656,11 @@ var NativeDocument = (function (exports) {
656
656
  DOCUMENT_FRAGMENT: 11
657
657
  };
658
658
 
659
- const VALID_TYPES = {
660
- [COMMON_NODE_TYPES.ELEMENT]: true,
661
- [COMMON_NODE_TYPES.TEXT]: true,
662
- [COMMON_NODE_TYPES.DOCUMENT_FRAGMENT]: true,
663
- [COMMON_NODE_TYPES.COMMENT]: true
664
- };
659
+ const VALID_TYPES = [];
660
+ VALID_TYPES[COMMON_NODE_TYPES.ELEMENT] = true;
661
+ VALID_TYPES[COMMON_NODE_TYPES.TEXT] = true;
662
+ VALID_TYPES[COMMON_NODE_TYPES.DOCUMENT_FRAGMENT] = true;
663
+ VALID_TYPES[COMMON_NODE_TYPES.COMMENT] = true;
665
664
 
666
665
  const Validator = {
667
666
  isObservable(value) {
@@ -795,7 +794,7 @@ var NativeDocument = (function (exports) {
795
794
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
796
795
 
797
796
  if (foundReserved.length > 0) {
798
- DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
797
+ DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
799
798
  }
800
799
 
801
800
  return attributes;
@@ -846,7 +845,7 @@ var NativeDocument = (function (exports) {
846
845
  anchorFragment.appendChild = function(child, before = null) {
847
846
  const parent = anchorEnd.parentNode;
848
847
  if(!parent) {
849
- DebugManager.error('Anchor', 'Anchor : parent not found', child);
848
+ DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
850
849
  return;
851
850
  }
852
851
  before = before ?? anchorEnd;
@@ -1040,7 +1039,7 @@ var NativeDocument = (function (exports) {
1040
1039
  }
1041
1040
  }
1042
1041
  if (cleanedCount > 0) {
1043
- DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1042
+ DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1044
1043
  }
1045
1044
  }
1046
1045
  };
@@ -1242,7 +1241,7 @@ var NativeDocument = (function (exports) {
1242
1241
  const $getStoreOrThrow = (method, name) => {
1243
1242
  const item = $stores.get(name);
1244
1243
  if (!item) {
1245
- DebugManager.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
1244
+ DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
1246
1245
  throw new NativeDocumentError(
1247
1246
  `Store.${method}('${name}') : store not found.`
1248
1247
  );
@@ -1255,7 +1254,7 @@ var NativeDocument = (function (exports) {
1255
1254
  */
1256
1255
  const $applyReadOnly = (observer, name, context) => {
1257
1256
  const readOnlyError = (method) => () => {
1258
- DebugManager.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
1257
+ DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
1259
1258
  throw new NativeDocumentError(
1260
1259
  `Store.${context}('${name}') is read-only.`
1261
1260
  );
@@ -1286,7 +1285,7 @@ var NativeDocument = (function (exports) {
1286
1285
  */
1287
1286
  create(name, value) {
1288
1287
  if ($stores.has(name)) {
1289
- DebugManager.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
1288
+ DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
1290
1289
  throw new NativeDocumentError(
1291
1290
  `Store.create('${name}') : a store with this name already exists.`
1292
1291
  );
@@ -1307,7 +1306,7 @@ var NativeDocument = (function (exports) {
1307
1306
  */
1308
1307
  createResettable(name, value) {
1309
1308
  if ($stores.has(name)) {
1310
- DebugManager.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
1309
+ DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
1311
1310
  throw new NativeDocumentError(
1312
1311
  `Store.createResettable('${name}') : a store with this name already exists.`
1313
1312
  );
@@ -1343,7 +1342,7 @@ var NativeDocument = (function (exports) {
1343
1342
  */
1344
1343
  createComposed(name, computation, dependencies) {
1345
1344
  if ($stores.has(name)) {
1346
- DebugManager.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
1345
+ DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
1347
1346
  throw new NativeDocumentError(
1348
1347
  `Store.createComposed('${name}') : a store with this name already exists.`
1349
1348
  );
@@ -1366,7 +1365,7 @@ var NativeDocument = (function (exports) {
1366
1365
  }
1367
1366
  const depItem = $stores.get(depName);
1368
1367
  if (!depItem) {
1369
- DebugManager.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
1368
+ DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
1370
1369
  throw new NativeDocumentError(
1371
1370
  `Store.createComposed('${name}') : dependency store '${depName}' not found.`
1372
1371
  );
@@ -1400,13 +1399,13 @@ var NativeDocument = (function (exports) {
1400
1399
  reset(name) {
1401
1400
  const item = $getStoreOrThrow('reset', name);
1402
1401
  if (item.composed) {
1403
- DebugManager.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
1402
+ DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
1404
1403
  throw new NativeDocumentError(
1405
1404
  `Store.reset('${name}') : composed stores cannot be reset.`
1406
1405
  );
1407
1406
  }
1408
1407
  if (!item.resettable) {
1409
- DebugManager.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
1408
+ DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
1410
1409
  throw new NativeDocumentError(
1411
1410
  `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
1412
1411
  );
@@ -1427,7 +1426,7 @@ var NativeDocument = (function (exports) {
1427
1426
  const item = $getStoreOrThrow('use', name);
1428
1427
 
1429
1428
  if (item.composed) {
1430
- DebugManager.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
1429
+ DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
1431
1430
  throw new NativeDocumentError(
1432
1431
  `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
1433
1432
  );
@@ -1494,7 +1493,7 @@ var NativeDocument = (function (exports) {
1494
1493
  get(name) {
1495
1494
  const item = $stores.get(name);
1496
1495
  if (!item) {
1497
- DebugManager.warn('Store', `Store.get('${name}') : store not found.`);
1496
+ DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
1498
1497
  return null;
1499
1498
  }
1500
1499
  return item.observer;
@@ -1516,7 +1515,7 @@ var NativeDocument = (function (exports) {
1516
1515
  delete(name) {
1517
1516
  const item = $stores.get(name);
1518
1517
  if (!item) {
1519
- DebugManager.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
1518
+ DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
1520
1519
  return;
1521
1520
  }
1522
1521
  item.subscribers.forEach(follower => follower.destroy());
@@ -1618,7 +1617,7 @@ var NativeDocument = (function (exports) {
1618
1617
  return undefined;
1619
1618
  },
1620
1619
  set(target, prop, value) {
1621
- DebugManager.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
1620
+ DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
1622
1621
  throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
1623
1622
  },
1624
1623
  deleteProperty(target, prop) {
@@ -1750,7 +1749,7 @@ var NativeDocument = (function (exports) {
1750
1749
  }
1751
1750
  }
1752
1751
  {
1753
- PluginsManager.emit('CreateObservable', this);
1752
+ PluginsManager$1.emit('CreateObservable', this);
1754
1753
  }
1755
1754
  }
1756
1755
 
@@ -1854,12 +1853,12 @@ var NativeDocument = (function (exports) {
1854
1853
  this.$previousValue = this.$currentValue;
1855
1854
  this.$currentValue = newValue;
1856
1855
  {
1857
- PluginsManager.emit('ObservableBeforeChange', this);
1856
+ PluginsManager$1.emit('ObservableBeforeChange', this);
1858
1857
  }
1859
1858
  this.trigger();
1860
1859
  this.$previousValue = null;
1861
1860
  {
1862
- PluginsManager.emit('ObservableAfterChange', this);
1861
+ PluginsManager$1.emit('ObservableAfterChange', this);
1863
1862
  }
1864
1863
  };
1865
1864
 
@@ -1937,7 +1936,7 @@ var NativeDocument = (function (exports) {
1937
1936
  ObservableItem.prototype.subscribe = function(callback) {
1938
1937
  {
1939
1938
  if (this.$isCleanedUp) {
1940
- DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
1939
+ DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
1941
1940
  return;
1942
1941
  }
1943
1942
  if (typeof callback !== 'function') {
@@ -1949,7 +1948,7 @@ var NativeDocument = (function (exports) {
1949
1948
  this.$listeners.push(callback);
1950
1949
  this.assocTrigger();
1951
1950
  {
1952
- PluginsManager.emit('ObservableSubscribe', this);
1951
+ PluginsManager$1.emit('ObservableSubscribe', this);
1953
1952
  }
1954
1953
  };
1955
1954
 
@@ -2060,7 +2059,7 @@ var NativeDocument = (function (exports) {
2060
2059
  }
2061
2060
  this.assocTrigger();
2062
2061
  {
2063
- PluginsManager.emit('ObservableUnsubscribe', this);
2062
+ PluginsManager$1.emit('ObservableUnsubscribe', this);
2064
2063
  }
2065
2064
  };
2066
2065
 
@@ -2453,7 +2452,9 @@ var NativeDocument = (function (exports) {
2453
2452
  */
2454
2453
  function AttributesWrapper(element, attributes) {
2455
2454
 
2456
- Validator.validateAttributes(attributes);
2455
+ {
2456
+ Validator.validateAttributes(attributes);
2457
+ }
2457
2458
 
2458
2459
  for(const originalAttributeName in attributes) {
2459
2460
  const attributeName = originalAttributeName.toLowerCase();
@@ -2534,7 +2535,7 @@ var NativeDocument = (function (exports) {
2534
2535
  Function.prototype.toNdElement = function () {
2535
2536
  const child = this;
2536
2537
  {
2537
- PluginsManager.emit('BeforeProcessComponent', child);
2538
+ PluginsManager$1.emit('BeforeProcessComponent', child);
2538
2539
  }
2539
2540
  return ElementCreator.getChild(child());
2540
2541
  };
@@ -2726,14 +2727,14 @@ var NativeDocument = (function (exports) {
2726
2727
  processChildren(children, parent) {
2727
2728
  if(children === null) return;
2728
2729
  {
2729
- PluginsManager.emit('BeforeProcessChildren', parent);
2730
+ PluginsManager$1.emit('BeforeProcessChildren', parent);
2730
2731
  }
2731
2732
  let child = this.getChild(children);
2732
2733
  if(child) {
2733
2734
  parent.appendChild(child);
2734
2735
  }
2735
2736
  {
2736
- PluginsManager.emit('AfterProcessChildren', parent);
2737
+ PluginsManager$1.emit('AfterProcessChildren', parent);
2737
2738
  }
2738
2739
  },
2739
2740
  async safeRemove(element) {
@@ -2764,7 +2765,15 @@ var NativeDocument = (function (exports) {
2764
2765
  if (attributes) {
2765
2766
  AttributesWrapper(element, attributes);
2766
2767
  }
2767
- }
2768
+ },
2769
+ /**
2770
+ *
2771
+ * @param {HTMLElement} element
2772
+ * @param {Object} attributes
2773
+ */
2774
+ processAttributesDirect: AttributesWrapper,
2775
+ processClassAttribute: bindClassAttribute,
2776
+ processStyleAttribute: bindStyleAttribute,
2768
2777
  };
2769
2778
 
2770
2779
  const EVENTS = [
@@ -3208,48 +3217,92 @@ var NativeDocument = (function (exports) {
3208
3217
  return createHtmlElement.bind(null, name, customWrapper);
3209
3218
  }
3210
3219
 
3211
- const cloneBindingsDataCache = new WeakMap();
3220
+ const OPERATIONS = {
3221
+ HYDRATE_TEXT: 1,
3222
+ ATTACH_METHOD: 2,
3223
+ HYDRATE_ATTRIBUTES: 3,
3224
+ HYDRATE_FULL: 4,
3225
+ };
3226
+
3227
+
3228
+
3229
+ const pathProcess = (target, path, data) => {
3230
+ if(path.operation === OPERATIONS.HYDRATE_TEXT) {
3231
+ const value = path.value;
3232
+ ElementCreator.bindTextNode(target, path.isString ? data[0][value] : value.apply(null, data));
3233
+ return;
3234
+ }
3235
+ if(path.operation === OPERATIONS.ATTACH_METHOD || path.operation === OPERATIONS.HYDRATE_FULL) {
3236
+ const bindingData = path.bindingData;
3237
+ for(let i = 0, length = bindingData._attachLength; i < length; i++) {
3238
+ const method = bindingData.attach[i];
3239
+ target.nd[method.methodName](function() {
3240
+ method.fn.call(this, ...data, ...arguments);
3241
+ });
3242
+ }
3243
+ }
3244
+ if(path.operation === OPERATIONS.HYDRATE_ATTRIBUTES || path.operation === OPERATIONS.HYDRATE_FULL) {
3245
+ path.hydrator(target, path.bindingData, data);
3246
+ }
3247
+ };
3248
+
3249
+ const buildAttributesCache = (bindDingData) => {
3250
+ const cache = { };
3251
+ if(bindDingData.attributes) cache.attributes = {};
3252
+ if(bindDingData.classes) cache.class = {};
3253
+ if(bindDingData.styles) cache.style = {};
3254
+ bindDingData._cache = cache;
3255
+ };
3212
3256
 
3257
+ const prepareBindingMetadata = (bindDingData) => {
3258
+ const attributes = [];
3259
+ const classAndStyles = [];
3213
3260
 
3214
- const bindAttributes = (node, bindDingData, data) => {
3215
- let attributes = null;
3216
3261
  if(bindDingData.attributes) {
3217
- attributes = {};
3218
3262
  for (const attr in bindDingData.attributes) {
3219
- attributes[attr] = bindDingData.attributes[attr].apply(null, data);
3263
+ attributes.push({
3264
+ name: attr,
3265
+ value: bindDingData.attributes[attr]
3266
+ });
3220
3267
  }
3221
3268
  }
3222
3269
 
3223
3270
  if(bindDingData.classes) {
3224
- attributes = attributes || {};
3225
- attributes.class = {};
3226
3271
  for (const className in bindDingData.classes) {
3227
- attributes.class[className] = bindDingData.classes[className].apply(null, data);
3272
+ bindDingData._hasClassAttribute = true;
3273
+ classAndStyles.push({
3274
+ name: 'class',
3275
+ key: className,
3276
+ value: bindDingData.classes[className]
3277
+ });
3228
3278
  }
3229
3279
  }
3230
3280
 
3231
3281
  if(bindDingData.styles) {
3232
- attributes = attributes || {};
3233
- attributes.style = {};
3234
3282
  for (const property in bindDingData.styles) {
3235
- attributes.style[property] = bindDingData.styles[property].apply(null, data);
3283
+ bindDingData._hasStyleAttribute = true;
3284
+ classAndStyles.push({
3285
+ name: 'style',
3286
+ key: property,
3287
+ value: bindDingData.styles[property]
3288
+ });
3236
3289
  }
3237
3290
  }
3238
3291
 
3239
- if(attributes) {
3240
- ElementCreator.processAttributes(node, attributes);
3241
- return true;
3242
- }
3243
-
3244
- return null;
3292
+ bindDingData._flatAttributes = attributes;
3293
+ bindDingData._flatAttributesLength = attributes.length;
3294
+ bindDingData._flatDynamique = classAndStyles;
3295
+ bindDingData._flatDynamiqueLength = classAndStyles.length;
3296
+ bindDingData._attachLength = bindDingData.attach.length;
3245
3297
  };
3246
3298
 
3299
+
3247
3300
  const $hydrateFn = function(hydrateFunction, targetType, element, property) {
3248
3301
  if(!cloneBindingsDataCache.has(element)) {
3249
- // { classes, styles, attributes, value, attach }
3250
3302
  cloneBindingsDataCache.set(element, { attach: [] });
3251
3303
  }
3252
3304
  const hydrationState = cloneBindingsDataCache.get(element);
3305
+
3253
3306
  if(targetType === 'value') {
3254
3307
  hydrationState.value = hydrateFunction;
3255
3308
  return;
@@ -3264,87 +3317,177 @@ var NativeDocument = (function (exports) {
3264
3317
  };
3265
3318
 
3266
3319
  const bindAttachMethods = (node, bindDingData, data) => {
3267
- for(let i = 0, length = bindDingData.attach.length; i < length; i++) {
3268
- const { methodName, fn } = bindDingData.attach[i];
3269
- node.nd[methodName](function(...args) {
3270
- fn.apply(this, [...args, ...data]);
3320
+ for(let i = 0, length = bindDingData._attachLength; i < length; i++) {
3321
+ const method = bindDingData.attach[i];
3322
+ node.nd[method.methodName](function() {
3323
+ method.fn.call(this, ...data, ...arguments);
3271
3324
  });
3272
3325
  }
3273
3326
  };
3274
3327
 
3328
+ const optimizeBindingData = (bindDingData) => {
3329
+ buildAttributesCache(bindDingData);
3330
+ prepareBindingMetadata(bindDingData);
3331
+ };
3332
+
3333
+
3334
+ const $applyBindingParents = [];
3335
+ const hydrateClonedNode = (root, data, paths, pathSize) => {
3336
+ const rootPath = paths[pathSize];
3337
+ $applyBindingParents[rootPath.id] = root;
3338
+ pathProcess(root, rootPath, data);
3339
+
3340
+ let target = null, path = null;
3341
+ for(let i = 0; i < pathSize; i++) {
3342
+ path = paths[i];
3343
+ target = $applyBindingParents[path.parentId].childNodes[path.index];
3344
+ $applyBindingParents[path.id] = target;
3345
+
3346
+ pathProcess(target, path, data);
3347
+ }
3348
+
3349
+ for (let i = 0; i <= pathSize; i++) {
3350
+ $applyBindingParents[i] = null;
3351
+ }
3352
+ };
3353
+
3354
+ const hydrateFull = (node, bindDingData, data) => {
3355
+ const cacheAttributes = bindDingData._cache;
3356
+
3357
+ for(let i = 0, length = bindDingData._flatAttributesLength; i < length; i++) {
3358
+ const attr = bindDingData._flatAttributes[i];
3359
+ cacheAttributes[attr.name] = attr.value.apply(null, data);
3360
+ }
3361
+
3362
+ for(let i = 0, length = bindDingData._flatDynamiqueLength; i < length; i++) {
3363
+ const dyn = bindDingData._flatDynamique[i];
3364
+ cacheAttributes[dyn.name][dyn.key] = dyn.value.apply(null, data);
3365
+ }
3366
+
3367
+ ElementCreator.processAttributesDirect(node, cacheAttributes);
3368
+ return true;
3369
+ };
3370
+
3371
+ const hydrateDynamic = (node, bindDingData, data) => {
3372
+ const cacheAttributes = bindDingData._cache;
3373
+
3374
+ for(let i = 0, length = bindDingData._flatDynamiqueLength; i < length; i++) {
3375
+ const dyn = bindDingData._flatDynamique[i];
3376
+ cacheAttributes[dyn.name][dyn.key] = dyn.value.apply(null, data);
3377
+ }
3378
+
3379
+ ElementCreator.processClassAttribute(node, cacheAttributes.class);
3380
+ ElementCreator.processStyleAttribute(node, cacheAttributes.style);
3381
+ return true;
3382
+ };
3383
+
3384
+ const hydrateClassAttribute = (node, bindDingData, data) => {
3385
+ const classAttributes = bindDingData._cache.class;
3386
+
3387
+ for(let i = 0, length = bindDingData._flatDynamiqueLength; i < length; i++) {
3388
+ const dyn = bindDingData._flatDynamique[i];
3389
+ classAttributes[dyn.key] = dyn.value.apply(null, data);
3390
+ }
3391
+
3392
+ ElementCreator.processClassAttribute(node, classAttributes);
3393
+ return true;
3394
+ };
3395
+
3396
+ const hydrateStyleAttribute = (node, bindDingData, data) => {
3397
+ const styleAttributes = bindDingData._cache;
3275
3398
 
3276
- const applyBindingTreePath = (root, data, paths) => {
3277
- const rootPath = paths.at(-1);
3278
- const parents = [];
3279
- parents[rootPath.id] = root;
3280
- data[0];
3281
- const rootPathFn = rootPath.fn;
3282
- rootPathFn(data, root, root);
3399
+ for(let i = 0, length = bindDingData._flatDynamiqueLength; i < length; i++) {
3400
+ const dyn = bindDingData._flatDynamique[i];
3401
+ styleAttributes[dyn.key] = dyn.value.apply(null, data);
3402
+ }
3283
3403
 
3404
+ ElementCreator.processStyleAttribute(node, styleAttributes);
3405
+ return true;
3406
+ };
3407
+
3408
+ const hydrateAttributes = (node, bindDingData, data) => {
3409
+ const cacheAttributes = bindDingData._cache;
3410
+
3411
+ for(let i = 0, length = bindDingData._flatAttributesLength; i < length; i++) {
3412
+ const attr = bindDingData._flatAttributes[i];
3413
+ cacheAttributes[attr.name] = attr.value.apply(null, data);
3414
+ }
3284
3415
 
3285
- for(let i = 0, length = paths.length - 1; i < length; i++) {
3286
- const path = paths[i];
3287
- const target = parents[path.parentId].childNodes[path.index];
3416
+ ElementCreator.processAttributesDirect(node, cacheAttributes);
3417
+ return true;
3418
+ };
3288
3419
 
3289
- parents[path.id] = target;
3290
- const pathFn = path.fn;
3291
- pathFn(data, target, root);
3420
+ const getHydrator = (bindDingData) => {
3421
+ if(!bindDingData._cache) {
3422
+ return noUpdate;
3423
+ }
3424
+ if(bindDingData._flatAttributesLength && bindDingData._flatDynamiqueLength) {
3425
+ return hydrateFull;
3426
+ }
3427
+ if(bindDingData._flatAttributesLength) {
3428
+ return hydrateAttributes;
3429
+ }
3430
+ if(bindDingData._hasClassAttribute && bindDingData._hasStyleAttribute) {
3431
+ return hydrateDynamic;
3432
+ }
3433
+ if(bindDingData._hasClassAttribute) {
3434
+ return hydrateClassAttribute;
3292
3435
  }
3293
- parents.length = 0;
3436
+ return hydrateStyleAttribute;
3294
3437
  };
3295
3438
 
3296
- const noUpdate = () => {};
3439
+ const cloneBindingsDataCache$1 = new WeakMap();
3440
+
3297
3441
  function TemplateCloner($fn) {
3298
3442
  let $node = null;
3299
3443
  let $hasBindingData = false;
3300
3444
 
3445
+ let $bindingTreePathSize = 0;
3301
3446
  const $bindingTreePath = [
3302
3447
  {
3303
3448
  id: 0,
3304
- parentId: null,
3305
- fn: noUpdate,
3449
+ parentId: null
3306
3450
  }
3307
3451
  ];
3308
3452
 
3309
3453
  let pathCounter = 0;
3310
3454
  const clone = (node, data, currentPath) => {
3311
- const bindDingData = cloneBindingsDataCache.get(node);
3455
+ const bindDingData = cloneBindingsDataCache$1.get(node);
3456
+ if(bindDingData) {
3457
+ optimizeBindingData(bindDingData);
3458
+ }
3312
3459
  if(node.nodeType === 3) {
3313
3460
  if(bindDingData && bindDingData.value) {
3314
- currentPath.fn = bindDingData.value;
3461
+ const value = bindDingData.value;
3315
3462
  const textNode = node.cloneNode();
3316
- if(typeof bindDingData.value === 'string') {
3317
- ElementCreator.bindTextNode(textNode, data[0][bindDingData.value]);
3318
- return textNode;
3319
- }
3320
- bindDingData.value(data, textNode);
3463
+ currentPath.value = value;
3464
+ currentPath.operation = OPERATIONS.HYDRATE_TEXT;
3465
+ currentPath.isString = (typeof value === 'string');
3466
+ ElementCreator.bindTextNode(textNode, (currentPath.isString ? data[0][value] : value.apply(null, data)));
3321
3467
  return textNode;
3322
3468
  }
3323
3469
  return node.cloneNode(true);
3324
3470
  }
3325
3471
  const nodeCloned = node.cloneNode();
3326
3472
  if(bindDingData) {
3327
- bindAttributes(nodeCloned, bindDingData, data);
3473
+ const hydrator = getHydrator(bindDingData);
3474
+ hydrator(nodeCloned, bindDingData, data);
3328
3475
  bindAttachMethods(nodeCloned, bindDingData, data);
3329
3476
 
3330
3477
  const hasAttributes = bindDingData.classes || bindDingData.styles || bindDingData.attributes;
3331
3478
  const hasAttachMethods = bindDingData.attach.length;
3332
3479
 
3480
+ currentPath.bindingData = bindDingData;
3481
+ currentPath.hydrator = hydrator;
3482
+
3333
3483
  if(hasAttributes && hasAttachMethods) {
3334
- currentPath.fn = (data, targetNode) => {
3335
- bindAttributes(targetNode, bindDingData, data);
3336
- bindAttachMethods(targetNode, bindDingData, data);
3337
- };
3484
+ currentPath.operation = OPERATIONS.HYDRATE_FULL;
3338
3485
  }
3339
3486
  else if(hasAttributes) {
3340
- currentPath.fn = (data, targetNode) => {
3341
- bindAttributes(targetNode, bindDingData, data);
3342
- };
3487
+ currentPath.operation = OPERATIONS.HYDRATE_ATTRIBUTES;
3343
3488
  }
3344
3489
  else if(hasAttachMethods) {
3345
- currentPath.fn = (data, targetNode) => {
3346
- bindAttachMethods(targetNode, bindDingData, data);
3347
- };
3490
+ currentPath.operation = OPERATIONS.ATTACH_METHOD;
3348
3491
  }
3349
3492
  }
3350
3493
  const childNodes = node.childNodes;
@@ -3352,10 +3495,10 @@ var NativeDocument = (function (exports) {
3352
3495
 
3353
3496
  for(let i = 0, length = childNodes.length; i < length; i++) {
3354
3497
  const childNode = childNodes[i];
3355
- const path = { parentId, id: ++pathCounter, index: i, fn: noUpdate };
3498
+ const path = { parentId, id: ++pathCounter, index: i };
3356
3499
  const childNodeCloned = clone(childNode, data, path);
3357
- if(path.hasChildren || path.fn) {
3358
- $bindingTreePath.unshift(path);
3500
+ if(path.hasChildren || path.operation) {
3501
+ $bindingTreePath.push(path);
3359
3502
  currentPath.hasChildren = true;
3360
3503
  }
3361
3504
  nodeCloned.appendChild(childNodeCloned);
@@ -3366,18 +3509,22 @@ var NativeDocument = (function (exports) {
3366
3509
  const cloneWithBindingPaths = (data) => {
3367
3510
  let root = $node.cloneNode(true);
3368
3511
 
3369
- applyBindingTreePath(root, data, $bindingTreePath);
3512
+ hydrateClonedNode(root, data, $bindingTreePath, $bindingTreePathSize);
3370
3513
  return root;
3371
3514
  };
3372
3515
 
3373
3516
  this.clone = (data) => {
3374
- $node = $fn(this);
3517
+ const binder = createTemplateCloner(this);
3518
+ $node = $fn(binder);
3375
3519
  if(!$hasBindingData) {
3376
3520
  this.clone = () => $node.cloneNode(true);
3377
3521
  return $node.cloneNode(true);
3378
3522
  }
3379
3523
 
3380
3524
  const firstClone = clone($node, data, $bindingTreePath[0]);
3525
+ $bindingTreePath.reverse();
3526
+ $bindingTreePathSize = $bindingTreePath.length - 1;
3527
+
3381
3528
  this.clone = cloneWithBindingPaths;
3382
3529
  return firstClone;
3383
3530
  };
@@ -3400,14 +3547,7 @@ var NativeDocument = (function (exports) {
3400
3547
  return this.value(propertyName);
3401
3548
  };
3402
3549
  this.value = (callbackOrProperty) => {
3403
- if(typeof callbackOrProperty !== 'function') {
3404
- return createBinding((data, textNode) => {
3405
- ElementCreator.bindTextNode(textNode, data[0][callbackOrProperty]);
3406
- }, 'value');
3407
- }
3408
- return createBinding((data, textNode) => {
3409
- ElementCreator.bindTextNode(textNode, callbackOrProperty(...data));
3410
- }, 'value');
3550
+ return createBinding(callbackOrProperty, 'value');
3411
3551
  };
3412
3552
  this.text = this.value;
3413
3553
  this.attr = (fn) => {
@@ -3416,14 +3556,29 @@ var NativeDocument = (function (exports) {
3416
3556
  this.attach = (fn) => {
3417
3557
  return createBinding(fn, 'attach');
3418
3558
  };
3559
+ this.callback = this.attach;
3419
3560
 
3420
3561
  }
3421
3562
 
3563
+
3564
+ function createTemplateCloner($binder) {
3565
+ return new Proxy($binder, {
3566
+ get(target, prop) {
3567
+ if(prop in target) {
3568
+ return target[prop];
3569
+ }
3570
+ if (typeof prop === 'symbol') return target[prop];
3571
+ return target.value(prop);
3572
+ }
3573
+ });
3574
+ }
3575
+
3422
3576
  function useCache(fn) {
3423
3577
  let $cache = null;
3424
3578
 
3425
3579
  let wrapper = function(args) {
3426
3580
  $cache = new TemplateCloner(fn);
3581
+
3427
3582
  wrapper = function(args) {
3428
3583
  return $cache.clone(args);
3429
3584
  };
@@ -4017,7 +4172,7 @@ var NativeDocument = (function (exports) {
4017
4172
 
4018
4173
  ObservableItem.call(this, target, configs);
4019
4174
  {
4020
- PluginsManager.emit('CreateObservableArray', this);
4175
+ PluginsManager$1.emit('CreateObservableArray', this);
4021
4176
  }
4022
4177
  };
4023
4178
 
@@ -4649,7 +4804,7 @@ var NativeDocument = (function (exports) {
4649
4804
  const observable = new ObservableItem(initialValue);
4650
4805
  const updatedValue = nextTick(() => observable.set(callback()));
4651
4806
  {
4652
- PluginsManager.emit('CreateObservableComputed', observable, dependencies);
4807
+ PluginsManager$1.emit('CreateObservableComputed', observable, dependencies);
4653
4808
  }
4654
4809
 
4655
4810
  if(Validator.isFunction(dependencies)) {
@@ -4748,7 +4903,7 @@ var NativeDocument = (function (exports) {
4748
4903
  }
4749
4904
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
4750
4905
  } catch (e) {
4751
- DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
4906
+ DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
4752
4907
  throw e;
4753
4908
  }
4754
4909
  return keyId;
@@ -5138,7 +5293,7 @@ var NativeDocument = (function (exports) {
5138
5293
  */
5139
5294
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
5140
5295
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
5141
- return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
5296
+ return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
5142
5297
  }
5143
5298
  const element = Anchor('Show if : '+(comment || ''));
5144
5299
 
@@ -6557,7 +6712,7 @@ var NativeDocument = (function (exports) {
6557
6712
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
6558
6713
  this.handleRouteChange(route, params, query, path);
6559
6714
  } catch (e) {
6560
- DebugManager.error('HistoryRouter', 'Error in pushState', e);
6715
+ DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
6561
6716
  }
6562
6717
  };
6563
6718
  /**
@@ -6570,7 +6725,7 @@ var NativeDocument = (function (exports) {
6570
6725
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
6571
6726
  this.handleRouteChange(route, params, {}, path);
6572
6727
  } catch(e) {
6573
- DebugManager.error('HistoryRouter', 'Error in replaceState', e);
6728
+ DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
6574
6729
  }
6575
6730
  };
6576
6731
  this.forward = function() {
@@ -6597,7 +6752,7 @@ var NativeDocument = (function (exports) {
6597
6752
  }
6598
6753
  this.handleRouteChange(route, params, query, path);
6599
6754
  } catch(e) {
6600
- DebugManager.error('HistoryRouter', 'Error in popstate event', e);
6755
+ DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
6601
6756
  }
6602
6757
  });
6603
6758
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -6822,7 +6977,7 @@ var NativeDocument = (function (exports) {
6822
6977
  listener(request);
6823
6978
  next && next(request);
6824
6979
  } catch (e) {
6825
- DebugManager.warn('Route Listener', 'Error in listener:', e);
6980
+ DebugManager$1.warn('Route Listener', 'Error in listener:', e);
6826
6981
  }
6827
6982
  }
6828
6983
  };
@@ -7000,7 +7155,7 @@ var NativeDocument = (function (exports) {
7000
7155
  */
7001
7156
  Router.create = function(options, callback) {
7002
7157
  if(!Validator.isFunction(callback)) {
7003
- DebugManager.error('Router', 'Callback must be a function');
7158
+ DebugManager$1.error('Router', 'Callback must be a function');
7004
7159
  throw new RouterError('Callback must be a function');
7005
7160
  }
7006
7161
  const router = new Router(options);
@@ -7204,7 +7359,7 @@ var NativeDocument = (function (exports) {
7204
7359
  exports.HtmlElementWrapper = HtmlElementWrapper;
7205
7360
  exports.NDElement = NDElement;
7206
7361
  exports.Observable = Observable;
7207
- exports.PluginsManager = PluginsManager;
7362
+ exports.PluginsManager = PluginsManager$1;
7208
7363
  exports.SingletonView = SingletonView;
7209
7364
  exports.Store = Store;
7210
7365
  exports.StoreFactory = StoreFactory;