native-document 1.0.154 โ†’ 1.0.156

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,14 +1,14 @@
1
1
  var NativeDocument = (function (exports) {
2
2
  'use strict';
3
3
 
4
- let DebugManager$1 = {};
4
+ let DebugManager$2 = {};
5
5
 
6
6
  {
7
- DebugManager$1 = {
7
+ DebugManager$2 = {
8
8
  enabled: true,
9
9
 
10
10
  enable() {
11
- DebugManager$1.log('๐Ÿ” NativeDocument Debug Mode enabled');
11
+ DebugManager$2.log('๐Ÿ” NativeDocument Debug Mode enabled');
12
12
  },
13
13
 
14
14
  disable() {
@@ -32,7 +32,7 @@ var NativeDocument = (function (exports) {
32
32
  };
33
33
 
34
34
  }
35
- var DebugManager$2 = DebugManager$1;
35
+ var DebugManager$1 = DebugManager$2;
36
36
 
37
37
  class NativeDocumentError extends Error {
38
38
  constructor(message, context = {}) {
@@ -188,7 +188,7 @@ var NativeDocument = (function (exports) {
188
188
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
189
189
 
190
190
  if (foundReserved.length > 0) {
191
- DebugManager$2.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
191
+ DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
192
192
  }
193
193
 
194
194
  return attributes;
@@ -275,16 +275,16 @@ var NativeDocument = (function (exports) {
275
275
  }
276
276
  }
277
277
  if (cleanedCount > 0) {
278
- DebugManager$2.log('Memory Auto Clean', `๐Ÿงน Cleaned ${cleanedCount} orphaned observables`);
278
+ DebugManager$1.log('Memory Auto Clean', `๐Ÿงน Cleaned ${cleanedCount} orphaned observables`);
279
279
  }
280
280
  }
281
281
  };
282
282
  }());
283
283
 
284
- let PluginsManager = null;
284
+ let PluginsManager$1 = null;
285
285
 
286
286
  {
287
- PluginsManager = (function() {
287
+ PluginsManager$1 = (function() {
288
288
 
289
289
  const $plugins = new Map();
290
290
  const $pluginByEvents = new Map();
@@ -350,7 +350,7 @@ var NativeDocument = (function (exports) {
350
350
  try{
351
351
  callback.call(plugin, ...data);
352
352
  } catch (error) {
353
- DebugManager$2.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
353
+ DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
354
354
  }
355
355
  }
356
356
  }
@@ -359,7 +359,7 @@ var NativeDocument = (function (exports) {
359
359
  }());
360
360
  }
361
361
 
362
- var PluginsManager$1 = PluginsManager;
362
+ var PluginsManager = PluginsManager$1;
363
363
 
364
364
  const nextTick = function(fn) {
365
365
  let pending = false;
@@ -521,7 +521,7 @@ var NativeDocument = (function (exports) {
521
521
  }
522
522
  }
523
523
  {
524
- PluginsManager$1.emit('CreateObservable', this);
524
+ PluginsManager.emit('CreateObservable', this);
525
525
  }
526
526
  }
527
527
 
@@ -636,12 +636,12 @@ var NativeDocument = (function (exports) {
636
636
  this.$previousValue = this.$currentValue;
637
637
  this.$currentValue = newValue;
638
638
  {
639
- PluginsManager$1.emit('ObservableBeforeChange', this);
639
+ PluginsManager.emit('ObservableBeforeChange', this);
640
640
  }
641
641
  this.trigger($setOperation);
642
642
  this.$previousValue = null;
643
643
  {
644
- PluginsManager$1.emit('ObservableAfterChange', this);
644
+ PluginsManager.emit('ObservableAfterChange', this);
645
645
  }
646
646
  };
647
647
 
@@ -720,7 +720,7 @@ var NativeDocument = (function (exports) {
720
720
  ObservableItem.prototype.subscribe = function(callback) {
721
721
  {
722
722
  if (this.$isCleanedUp) {
723
- DebugManager$2.warn('Observable subscription', 'โš ๏ธ Attempted to subscribe to a cleaned up observable.');
723
+ DebugManager$1.warn('Observable subscription', 'โš ๏ธ Attempted to subscribe to a cleaned up observable.');
724
724
  return;
725
725
  }
726
726
  if (typeof callback !== 'function') {
@@ -732,7 +732,7 @@ var NativeDocument = (function (exports) {
732
732
  this.$listeners.push(callback);
733
733
  this.assocTrigger();
734
734
  {
735
- PluginsManager$1.emit('ObservableSubscribe', this);
735
+ PluginsManager.emit('ObservableSubscribe', this);
736
736
  }
737
737
  };
738
738
 
@@ -843,7 +843,7 @@ var NativeDocument = (function (exports) {
843
843
  }
844
844
  this.assocTrigger();
845
845
  {
846
- PluginsManager$1.emit('ObservableUnsubscribe', this);
846
+ PluginsManager.emit('ObservableUnsubscribe', this);
847
847
  }
848
848
  };
849
849
 
@@ -1089,7 +1089,7 @@ var NativeDocument = (function (exports) {
1089
1089
  const regex = new RegExp(pattern, flags);
1090
1090
  return regex.test(String(value));
1091
1091
  } catch (error){
1092
- DebugManager$2.warn('Invalid regex pattern:', pattern, error);
1092
+ DebugManager$1.warn('Invalid regex pattern:', pattern, error);
1093
1093
  return false;
1094
1094
  }
1095
1095
  }
@@ -1348,7 +1348,7 @@ var NativeDocument = (function (exports) {
1348
1348
 
1349
1349
  ObservableItem.call(this, target, configs);
1350
1350
  {
1351
- PluginsManager$1.emit('CreateObservableArray', this);
1351
+ PluginsManager.emit('CreateObservableArray', this);
1352
1352
  }
1353
1353
  };
1354
1354
 
@@ -2204,7 +2204,7 @@ var NativeDocument = (function (exports) {
2204
2204
 
2205
2205
  ObservableItem.call(this);
2206
2206
  {
2207
- PluginsManager$1.emit('CreateObservableChecker', this);
2207
+ PluginsManager.emit('CreateObservableChecker', this);
2208
2208
  }
2209
2209
 
2210
2210
  this.$mutation = $checker;
@@ -2571,7 +2571,7 @@ var NativeDocument = (function (exports) {
2571
2571
  const getValues = () => dependencies.map((item) => item.val());
2572
2572
  const updatedValue = nextTick(() => observable.set(callback(...getValues())));
2573
2573
  {
2574
- PluginsManager$1.emit('CreateObservableComputed', observable, dependencies);
2574
+ PluginsManager.emit('CreateObservableComputed', observable, dependencies);
2575
2575
  }
2576
2576
 
2577
2577
  if(Validator.isFunction(dependencies)) {
@@ -2877,14 +2877,14 @@ var NativeDocument = (function (exports) {
2877
2877
  processChildren: (children, parent) => {
2878
2878
  if(children === null) return;
2879
2879
  {
2880
- PluginsManager$1.emit('BeforeProcessChildren', parent);
2880
+ PluginsManager.emit('BeforeProcessChildren', parent);
2881
2881
  }
2882
2882
  let child = ElementCreator.getChild(children);
2883
2883
  if(child) {
2884
2884
  parent.appendChild(child);
2885
2885
  }
2886
2886
  {
2887
- PluginsManager$1.emit('AfterProcessChildren', parent);
2887
+ PluginsManager.emit('AfterProcessChildren', parent);
2888
2888
  }
2889
2889
  },
2890
2890
  async safeRemove(element) {
@@ -3228,6 +3228,127 @@ var NativeDocument = (function (exports) {
3228
3228
 
3229
3229
  DocumentFragment.prototype.setAttribute = () => {};
3230
3230
 
3231
+ class ArgTypesError extends Error {
3232
+ constructor(message, errors) {
3233
+ super(`${message}\n\n${errors.join("\n")}\n\n`);
3234
+ }
3235
+ }
3236
+
3237
+ exports.withValidation = (fn) => fn;
3238
+ exports.ArgTypes = {};
3239
+
3240
+ /**
3241
+ *
3242
+ * @type {{string: (function(*): {name: *, type: string, validate: function(*): boolean}),
3243
+ * number: (function(*): {name: *, type: string, validate: function(*): boolean}),
3244
+ * boolean: (function(*): {name: *, type: string, validate: function(*): boolean}),
3245
+ * observable: (function(*): {name: *, type: string, validate: function(*): boolean}),
3246
+ * element: (function(*): {name: *, type: string, validate: function(*): *}),
3247
+ * function: (function(*): {name: *, type: string, validate: function(*): boolean}),
3248
+ * object: (function(*): {name: *, type: string, validate: function(*): boolean}),
3249
+ * objectNotNull: (function(*): {name: *, type: string, validate: function(*): *}),
3250
+ * children: (function(*): {name: *, type: string, validate: function(*): *}),
3251
+ * attributes: (function(*): {name: *, type: string, validate: function(*): *}),
3252
+ * optional: (function(*): *&{optional: boolean}),
3253
+ * oneOf: (function(*, ...[*]): {name: *, type: string, types: *[],
3254
+ * validate: function(*): boolean})
3255
+ * }}
3256
+ */
3257
+ {
3258
+ exports.ArgTypes = {
3259
+ string: (name) => ({ name, type: 'string', validate: (v) => Validator.isString(v) }),
3260
+ number: (name) => ({ name, type: 'number', validate: (v) => Validator.isNumber(v) }),
3261
+ boolean: (name) => ({ name, type: 'boolean', validate: (v) => Validator.isBoolean(v) }),
3262
+ observable: (name) => ({ name, type: 'observable', validate: (v) => Validator.isObservable(v) }),
3263
+ element: (name) => ({ name, type: 'element', validate: (v) => Validator.isElement(v) }),
3264
+ function: (name) => ({ name, type: 'function', validate: (v) => Validator.isFunction(v) }),
3265
+ object: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v)) }),
3266
+ objectNotNull: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v) && v !== null) }),
3267
+ children: (name) => ({ name, type: 'children', validate: (v) => Validator.validateChildren(v) }),
3268
+ attributes: (name) => ({ name, type: 'attributes', validate: (v) => Validator.validateAttributes(v) }),
3269
+
3270
+ // Optional arguments
3271
+ optional: (argType) => ({ ...argType, optional: true }),
3272
+
3273
+ // Union types
3274
+ oneOf: (name, ...argTypes) => ({
3275
+ name,
3276
+ type: 'oneOf',
3277
+ types: argTypes,
3278
+ validate: (v) => argTypes.some(type => type.validate(v))
3279
+ })
3280
+ };
3281
+
3282
+
3283
+ /**
3284
+ *
3285
+ * @param {Array} args
3286
+ * @param {Array} argSchema
3287
+ * @param {string} fnName
3288
+ */
3289
+ const validateArgs = (args, argSchema, fnName = 'Function') => {
3290
+ if (!argSchema) return;
3291
+
3292
+ const errors = [];
3293
+
3294
+ // Check the number of arguments
3295
+ const requiredCount = argSchema.filter(arg => !arg.optional).length;
3296
+ if (args.length < requiredCount) {
3297
+ errors.push(`${fnName}: Expected at least ${requiredCount} arguments, got ${args.length}`);
3298
+ }
3299
+
3300
+ // Validate each argument
3301
+ argSchema.forEach((schema, index) => {
3302
+ const position = index + 1;
3303
+ const value = args[index];
3304
+
3305
+ if (value === undefined) {
3306
+ if (!schema.optional) {
3307
+ errors.push(`${fnName}: Missing required argument '${schema.name}' at position ${position}`);
3308
+ }
3309
+ return;
3310
+ }
3311
+
3312
+ if (!schema.validate(value)) {
3313
+ const valueTypeOf = value?.constructor?.name || typeof value;
3314
+ errors.push(`${fnName}: Invalid argument '${schema.name}' at position ${position}, expected ${schema.type}, got ${valueTypeOf}`);
3315
+ }
3316
+ });
3317
+
3318
+ if (errors.length > 0) {
3319
+ throw new ArgTypesError(`Argument validation failed`, errors);
3320
+ }
3321
+ };
3322
+
3323
+
3324
+
3325
+ /**
3326
+ * @param {Function} fn
3327
+ * @param {Array} argSchema
3328
+ * @param {string} fnName
3329
+ * @returns {Function}
3330
+ */
3331
+ exports.withValidation = (fn, argSchema, fnName = 'Function') => {
3332
+ if(!Validator.isArray(argSchema)) {
3333
+ throw new NativeDocumentError('withValidation : argSchema must be an array');
3334
+ }
3335
+ return function(...args) {
3336
+ validateArgs(args, argSchema, fn.name || fnName);
3337
+ return fn.apply(this, args);
3338
+ };
3339
+ };
3340
+ }
3341
+
3342
+ const normalizeComponentArgs = function(props, children = null) {
3343
+ if(props && children) {
3344
+ return { props, children };
3345
+ }
3346
+ if(typeof props !== 'object' || Array.isArray(props) || props === null || props.constructor.name !== 'Object' || props.$hydrate) { // IF it's not a JSON
3347
+ return { props: children, children: props }
3348
+ }
3349
+ return { props, children };
3350
+ };
3351
+
3231
3352
  const DocumentObserver = {
3232
3353
  mounted: new WeakMap(),
3233
3354
  beforeUnmount: new WeakMap(),
@@ -3413,7 +3534,7 @@ var NativeDocument = (function (exports) {
3413
3534
  this.$element = element;
3414
3535
  this.$attachements = null;
3415
3536
  {
3416
- PluginsManager$1.emit('NDElementCreated', element, this);
3537
+ PluginsManager.emit('NDElementCreated', element, this);
3417
3538
  }
3418
3539
  }
3419
3540
 
@@ -3585,12 +3706,12 @@ var NativeDocument = (function (exports) {
3585
3706
  const method = methods[name];
3586
3707
 
3587
3708
  if (typeof method !== 'function') {
3588
- DebugManager$2.warn(`โš ๏ธ extends(): "${name}" is not a function, skipping`);
3709
+ DebugManager$1.warn(`โš ๏ธ extends(): "${name}" is not a function, skipping`);
3589
3710
  continue;
3590
3711
  }
3591
3712
  {
3592
3713
  if (this[name] && !this.$localExtensions.has(name)) {
3593
- DebugManager$2.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
3714
+ DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
3594
3715
  }
3595
3716
  this.$localExtensions.set(name, method);
3596
3717
  }
@@ -3641,23 +3762,23 @@ var NativeDocument = (function (exports) {
3641
3762
  const method = methods[name];
3642
3763
 
3643
3764
  if (typeof method !== 'function') {
3644
- DebugManager$2.warn('NDElement.extend', `"${name}" is not a function, skipping`);
3765
+ DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
3645
3766
  continue;
3646
3767
  }
3647
3768
 
3648
3769
  if (protectedMethods.has(name)) {
3649
- DebugManager$2.error('NDElement.extend', `Cannot override protected method "${name}"`);
3770
+ DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
3650
3771
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
3651
3772
  }
3652
3773
 
3653
3774
  if (NDElement.prototype[name]) {
3654
- DebugManager$2.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
3775
+ DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
3655
3776
  }
3656
3777
 
3657
3778
  NDElement.prototype[name] = method;
3658
3779
  }
3659
3780
  {
3660
- PluginsManager$1.emit('NDElementExtended', methods);
3781
+ PluginsManager.emit('NDElementExtended', methods);
3661
3782
  }
3662
3783
 
3663
3784
  return NDElement;
@@ -3954,125 +4075,193 @@ var NativeDocument = (function (exports) {
3954
4075
  }
3955
4076
  });
3956
4077
 
3957
- class ArgTypesError extends Error {
3958
- constructor(message, errors) {
3959
- super(`${message}\n\n${errors.join("\n")}\n\n`);
3960
- }
3961
- }
3962
-
3963
- exports.withValidation = (fn) => fn;
3964
- exports.ArgTypes = {};
3965
-
3966
- /**
3967
- *
3968
- * @type {{string: (function(*): {name: *, type: string, validate: function(*): boolean}),
3969
- * number: (function(*): {name: *, type: string, validate: function(*): boolean}),
3970
- * boolean: (function(*): {name: *, type: string, validate: function(*): boolean}),
3971
- * observable: (function(*): {name: *, type: string, validate: function(*): boolean}),
3972
- * element: (function(*): {name: *, type: string, validate: function(*): *}),
3973
- * function: (function(*): {name: *, type: string, validate: function(*): boolean}),
3974
- * object: (function(*): {name: *, type: string, validate: function(*): boolean}),
3975
- * objectNotNull: (function(*): {name: *, type: string, validate: function(*): *}),
3976
- * children: (function(*): {name: *, type: string, validate: function(*): *}),
3977
- * attributes: (function(*): {name: *, type: string, validate: function(*): *}),
3978
- * optional: (function(*): *&{optional: boolean}),
3979
- * oneOf: (function(*, ...[*]): {name: *, type: string, types: *[],
3980
- * validate: function(*): boolean})
3981
- * }}
3982
- */
3983
- {
3984
- exports.ArgTypes = {
3985
- string: (name) => ({ name, type: 'string', validate: (v) => Validator.isString(v) }),
3986
- number: (name) => ({ name, type: 'number', validate: (v) => Validator.isNumber(v) }),
3987
- boolean: (name) => ({ name, type: 'boolean', validate: (v) => Validator.isBoolean(v) }),
3988
- observable: (name) => ({ name, type: 'observable', validate: (v) => Validator.isObservable(v) }),
3989
- element: (name) => ({ name, type: 'element', validate: (v) => Validator.isElement(v) }),
3990
- function: (name) => ({ name, type: 'function', validate: (v) => Validator.isFunction(v) }),
3991
- object: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v)) }),
3992
- objectNotNull: (name) => ({ name, type: 'object', validate: (v) => (Validator.isObject(v) && v !== null) }),
3993
- children: (name) => ({ name, type: 'children', validate: (v) => Validator.validateChildren(v) }),
3994
- attributes: (name) => ({ name, type: 'attributes', validate: (v) => Validator.validateAttributes(v) }),
4078
+ DocumentFragment.prototype.__IS_FRAGMENT = true;
3995
4079
 
3996
- // Optional arguments
3997
- optional: (argType) => ({ ...argType, optional: true }),
4080
+ Function.prototype.args = function(...args) {
4081
+ return exports.withValidation(this, args);
4082
+ };
3998
4083
 
3999
- // Union types
4000
- oneOf: (name, ...argTypes) => ({
4001
- name,
4002
- type: 'oneOf',
4003
- types: argTypes,
4004
- validate: (v) => argTypes.some(type => type.validate(v))
4005
- })
4084
+ Function.prototype.errorBoundary = function(callback) {
4085
+ const handler = (...args) => {
4086
+ try {
4087
+ return this.apply(this, args);
4088
+ } catch(e) {
4089
+ return callback(e, {caller: handler, args: args });
4090
+ }
4006
4091
  };
4092
+ return handler;
4093
+ };
4007
4094
 
4095
+ function TemplateBinding(hydrate) {
4096
+ this.$hydrate = hydrate;
4097
+ }
4008
4098
 
4009
- /**
4010
- *
4011
- * @param {Array} args
4012
- * @param {Array} argSchema
4013
- * @param {string} fnName
4014
- */
4015
- const validateArgs = (args, argSchema, fnName = 'Function') => {
4016
- if (!argSchema) return;
4017
-
4018
- const errors = [];
4099
+ TemplateBinding.prototype.__$isTemplateBinding = true;
4019
4100
 
4020
- // Check the number of arguments
4021
- const requiredCount = argSchema.filter(arg => !arg.optional).length;
4022
- if (args.length < requiredCount) {
4023
- errors.push(`${fnName}: Expected at least ${requiredCount} arguments, got ${args.length}`);
4024
- }
4101
+ NDElement.$getChild = ElementCreator.getChild;
4025
4102
 
4026
- // Validate each argument
4027
- argSchema.forEach((schema, index) => {
4028
- const position = index + 1;
4029
- const value = args[index];
4103
+ String.prototype.toNdElement = function () {
4104
+ return ElementCreator.createStaticTextNode(null, this);
4105
+ };
4030
4106
 
4031
- if (value === undefined) {
4032
- if (!schema.optional) {
4033
- errors.push(`${fnName}: Missing required argument '${schema.name}' at position ${position}`);
4034
- }
4035
- return;
4036
- }
4107
+ Number.prototype.toNdElement = function () {
4108
+ return ElementCreator.createStaticTextNode(null, this.toString());
4109
+ };
4037
4110
 
4038
- if (!schema.validate(value)) {
4039
- const valueTypeOf = value?.constructor?.name || typeof value;
4040
- errors.push(`${fnName}: Invalid argument '${schema.name}' at position ${position}, expected ${schema.type}, got ${valueTypeOf}`);
4041
- }
4042
- });
4111
+ Element.prototype.toNdElement = function () {
4112
+ return this;
4113
+ };
4114
+ Text.prototype.toNdElement = function () {
4115
+ return this;
4116
+ };
4117
+ Comment.prototype.toNdElement = function () {
4118
+ return this;
4119
+ };
4120
+ Document.prototype.toNdElement = function () {
4121
+ return this;
4122
+ };
4123
+ DocumentFragment.prototype.toNdElement = function () {
4124
+ return this;
4125
+ };
4043
4126
 
4044
- if (errors.length > 0) {
4045
- throw new ArgTypesError(`Argument validation failed`, errors);
4046
- }
4047
- };
4127
+ ObservableItem.prototype.toNdElement = function () {
4128
+ return ElementCreator.createObservableNode(null, this);
4129
+ };
4048
4130
 
4131
+ ObservableChecker.prototype.toNdElement = ObservableItem.prototype.toNdElement;
4049
4132
 
4133
+ NDElement.prototype.toNdElement = function () {
4134
+ const element = this.$element ?? this.$build?.() ?? this.build?.() ?? null;
4135
+ if(this.$attachements) {
4136
+ if(!this.$attachements.contains(this.$element)) {
4137
+ this.$attachements.append(this.$element);
4138
+ }
4139
+ return this.$attachements;
4140
+ }
4141
+ return element;
4142
+ };
4050
4143
 
4051
- /**
4052
- * @param {Function} fn
4053
- * @param {Array} argSchema
4054
- * @param {string} fnName
4055
- * @returns {Function}
4056
- */
4057
- exports.withValidation = (fn, argSchema, fnName = 'Function') => {
4058
- if(!Validator.isArray(argSchema)) {
4059
- throw new NativeDocumentError('withValidation : argSchema must be an array');
4060
- }
4061
- return function(...args) {
4062
- validateArgs(args, argSchema, fn.name || fnName);
4063
- return fn.apply(this, args);
4064
- };
4065
- };
4066
- }
4144
+ Array.prototype.toNdElement = function () {
4145
+ const fragment = document.createDocumentFragment();
4146
+ for(let i = 0, length = this.length; i < length; i++) {
4147
+ const child = ElementCreator.getChild(this[i]);
4148
+ if(child === null) continue;
4149
+ fragment.appendChild(child);
4150
+ }
4151
+ return fragment;
4152
+ };
4067
4153
 
4068
- const normalizeComponentArgs = function(props, children = null) {
4069
- if(props && children) {
4070
- return { props, children };
4154
+ Function.prototype.toNdElement = function () {
4155
+ const child = this;
4156
+ {
4157
+ PluginsManager.emit('BeforeProcessComponent', child);
4071
4158
  }
4072
- if(typeof props !== 'object' || Array.isArray(props) || props === null || props.constructor.name !== 'Object' || props.$hydrate) { // IF it's not a JSON
4073
- return { props: children, children: props }
4159
+ return ElementCreator.getChild(child());
4160
+ };
4161
+
4162
+ TemplateBinding.prototype.toNdElement = function () {
4163
+ return ElementCreator.createHydratableNode(null, this);
4164
+ };
4165
+
4166
+ /**
4167
+ * @param {HTMLElement} el
4168
+ * @param {number} timeout
4169
+ */
4170
+ const waitForVisualEnd = (el, timeout = 1000) => {
4171
+ return new Promise((resolve) => {
4172
+ let isResolved = false;
4173
+
4174
+ const cleanupAndResolve = (e) => {
4175
+ if (e && e.target !== el) return;
4176
+ if (isResolved) return;
4177
+
4178
+ isResolved = true;
4179
+ el.removeEventListener('transitionend', cleanupAndResolve);
4180
+ el.removeEventListener('animationend', cleanupAndResolve);
4181
+ clearTimeout(timer);
4182
+ resolve();
4183
+ };
4184
+
4185
+ el.addEventListener('transitionend', cleanupAndResolve);
4186
+ el.addEventListener('animationend', cleanupAndResolve);
4187
+
4188
+ const timer = setTimeout(cleanupAndResolve, timeout);
4189
+
4190
+ const style = window.getComputedStyle(el);
4191
+ const hasTransition = style.transitionDuration !== '0s';
4192
+ const hasAnimation = style.animationDuration !== '0s';
4193
+
4194
+ if (!hasTransition && !hasAnimation) {
4195
+ cleanupAndResolve();
4196
+ }
4197
+ });
4198
+ };
4199
+
4200
+ NDElement.prototype.transitionOut = function(transitionName) {
4201
+ const exitClass = transitionName + '-exit';
4202
+ const el = this.$element;
4203
+ this.beforeUnmount('transition-exit', async function() {
4204
+ el.classes.add(exitClass);
4205
+ await waitForVisualEnd(el);
4206
+ el.classes.remove(exitClass);
4207
+ });
4208
+ return this;
4209
+ };
4210
+
4211
+ NDElement.prototype.transitionIn = function(transitionName) {
4212
+ const startClass = transitionName + '-enter-from';
4213
+ const endClass = transitionName + '-enter-to';
4214
+
4215
+ const el = this.$element;
4216
+
4217
+ el.classes.add(startClass);
4218
+
4219
+ this.mounted(() => {
4220
+ requestAnimationFrame(() => {
4221
+ requestAnimationFrame(() => {
4222
+ el.classes.remove(startClass);
4223
+ el.classes.add(endClass);
4224
+
4225
+ waitForVisualEnd(el).then(() => {
4226
+ el.classes.remove(endClass);
4227
+ });
4228
+ });
4229
+ });
4230
+ });
4231
+ return this;
4232
+ };
4233
+
4234
+
4235
+ NDElement.prototype.transition = function (transitionName) {
4236
+ this.transitionIn(transitionName);
4237
+ this.transitionOut(transitionName);
4238
+ return this;
4239
+ };
4240
+
4241
+ NDElement.prototype.animate = function(animationName) {
4242
+ const el = this.$element;
4243
+ el.classes.add(animationName);
4244
+
4245
+ waitForVisualEnd(el).then(() => {
4246
+ el.classes.remove(animationName);
4247
+ });
4248
+
4249
+ return this;
4250
+ };
4251
+
4252
+ ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
4253
+ if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
4254
+ bindBooleanAttribute(element, attributeName, this);
4255
+ return;
4074
4256
  }
4075
- return { props, children };
4257
+
4258
+ bindAttributeWithObservable(element, attributeName, this);
4259
+ };
4260
+
4261
+ ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
4262
+
4263
+ TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
4264
+ this.$hydrate(element, attributeName);
4076
4265
  };
4077
4266
 
4078
4267
  /**
@@ -4134,12 +4323,6 @@ var NativeDocument = (function (exports) {
4134
4323
  };
4135
4324
  }
4136
4325
 
4137
- function TemplateBinding(hydrate) {
4138
- this.$hydrate = hydrate;
4139
- }
4140
-
4141
- TemplateBinding.prototype.__$isTemplateBinding = true;
4142
-
4143
4326
  function NodeCloner($element) {
4144
4327
  this.$element = $element;
4145
4328
  this.$classes = null;
@@ -4478,189 +4661,6 @@ var NativeDocument = (function (exports) {
4478
4661
  };
4479
4662
  }
4480
4663
 
4481
- DocumentFragment.prototype.__IS_FRAGMENT = true;
4482
-
4483
- Function.prototype.args = function(...args) {
4484
- return exports.withValidation(this, args);
4485
- };
4486
-
4487
- Function.prototype.errorBoundary = function(callback) {
4488
- const handler = (...args) => {
4489
- try {
4490
- return this.apply(this, args);
4491
- } catch(e) {
4492
- return callback(e, {caller: handler, args: args });
4493
- }
4494
- };
4495
- return handler;
4496
- };
4497
-
4498
- NDElement.$getChild = ElementCreator.getChild;
4499
-
4500
- String.prototype.toNdElement = function () {
4501
- return ElementCreator.createStaticTextNode(null, this);
4502
- };
4503
-
4504
- Number.prototype.toNdElement = function () {
4505
- return ElementCreator.createStaticTextNode(null, this.toString());
4506
- };
4507
-
4508
- Element.prototype.toNdElement = function () {
4509
- return this;
4510
- };
4511
- Text.prototype.toNdElement = function () {
4512
- return this;
4513
- };
4514
- Comment.prototype.toNdElement = function () {
4515
- return this;
4516
- };
4517
- Document.prototype.toNdElement = function () {
4518
- return this;
4519
- };
4520
- DocumentFragment.prototype.toNdElement = function () {
4521
- return this;
4522
- };
4523
-
4524
- ObservableItem.prototype.toNdElement = function () {
4525
- return ElementCreator.createObservableNode(null, this);
4526
- };
4527
-
4528
- ObservableChecker.prototype.toNdElement = ObservableItem.prototype.toNdElement;
4529
-
4530
- NDElement.prototype.toNdElement = function () {
4531
- const element = this.$element ?? this.$build?.() ?? this.build?.() ?? null;
4532
- if(this.$attachements) {
4533
- if(!this.$attachements.contains(this.$element)) {
4534
- this.$attachements.append(this.$element);
4535
- }
4536
- return this.$attachements;
4537
- }
4538
- return element;
4539
- };
4540
-
4541
- Array.prototype.toNdElement = function () {
4542
- const fragment = document.createDocumentFragment();
4543
- for(let i = 0, length = this.length; i < length; i++) {
4544
- const child = ElementCreator.getChild(this[i]);
4545
- if(child === null) continue;
4546
- fragment.appendChild(child);
4547
- }
4548
- return fragment;
4549
- };
4550
-
4551
- Function.prototype.toNdElement = function () {
4552
- const child = this;
4553
- {
4554
- PluginsManager$1.emit('BeforeProcessComponent', child);
4555
- }
4556
- return ElementCreator.getChild(child());
4557
- };
4558
-
4559
- TemplateBinding.prototype.toNdElement = function () {
4560
- return ElementCreator.createHydratableNode(null, this);
4561
- };
4562
-
4563
- /**
4564
- * @param {HTMLElement} el
4565
- * @param {number} timeout
4566
- */
4567
- const waitForVisualEnd = (el, timeout = 1000) => {
4568
- return new Promise((resolve) => {
4569
- let isResolved = false;
4570
-
4571
- const cleanupAndResolve = (e) => {
4572
- if (e && e.target !== el) return;
4573
- if (isResolved) return;
4574
-
4575
- isResolved = true;
4576
- el.removeEventListener('transitionend', cleanupAndResolve);
4577
- el.removeEventListener('animationend', cleanupAndResolve);
4578
- clearTimeout(timer);
4579
- resolve();
4580
- };
4581
-
4582
- el.addEventListener('transitionend', cleanupAndResolve);
4583
- el.addEventListener('animationend', cleanupAndResolve);
4584
-
4585
- const timer = setTimeout(cleanupAndResolve, timeout);
4586
-
4587
- const style = window.getComputedStyle(el);
4588
- const hasTransition = style.transitionDuration !== '0s';
4589
- const hasAnimation = style.animationDuration !== '0s';
4590
-
4591
- if (!hasTransition && !hasAnimation) {
4592
- cleanupAndResolve();
4593
- }
4594
- });
4595
- };
4596
-
4597
- NDElement.prototype.transitionOut = function(transitionName) {
4598
- const exitClass = transitionName + '-exit';
4599
- const el = this.$element;
4600
- this.beforeUnmount('transition-exit', async function() {
4601
- el.classes.add(exitClass);
4602
- await waitForVisualEnd(el);
4603
- el.classes.remove(exitClass);
4604
- });
4605
- return this;
4606
- };
4607
-
4608
- NDElement.prototype.transitionIn = function(transitionName) {
4609
- const startClass = transitionName + '-enter-from';
4610
- const endClass = transitionName + '-enter-to';
4611
-
4612
- const el = this.$element;
4613
-
4614
- el.classes.add(startClass);
4615
-
4616
- this.mounted(() => {
4617
- requestAnimationFrame(() => {
4618
- requestAnimationFrame(() => {
4619
- el.classes.remove(startClass);
4620
- el.classes.add(endClass);
4621
-
4622
- waitForVisualEnd(el).then(() => {
4623
- el.classes.remove(endClass);
4624
- });
4625
- });
4626
- });
4627
- });
4628
- return this;
4629
- };
4630
-
4631
-
4632
- NDElement.prototype.transition = function (transitionName) {
4633
- this.transitionIn(transitionName);
4634
- this.transitionOut(transitionName);
4635
- return this;
4636
- };
4637
-
4638
- NDElement.prototype.animate = function(animationName) {
4639
- const el = this.$element;
4640
- el.classes.add(animationName);
4641
-
4642
- waitForVisualEnd(el).then(() => {
4643
- el.classes.remove(animationName);
4644
- });
4645
-
4646
- return this;
4647
- };
4648
-
4649
- ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
4650
- if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
4651
- bindBooleanAttribute(element, attributeName, this);
4652
- return;
4653
- }
4654
-
4655
- bindAttributeWithObservable(element, attributeName, this);
4656
- };
4657
-
4658
- ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
4659
-
4660
- TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
4661
- this.$hydrate(element, attributeName);
4662
- };
4663
-
4664
4664
  const cssPropertyAccumulator = function(initialValue = {}) {
4665
4665
  let data = Validator.isString(initialValue) ? initialValue.split(';').filter(Boolean) : initialValue;
4666
4666
 
@@ -4804,7 +4804,7 @@ var NativeDocument = (function (exports) {
4804
4804
  const $getStoreOrThrow = (method, name) => {
4805
4805
  const item = $stores.get(name);
4806
4806
  if (!item) {
4807
- DebugManager$2.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
4807
+ DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
4808
4808
  throw new NativeDocumentError(
4809
4809
  `Store.${method}('${name}') : store not found.`
4810
4810
  );
@@ -4817,7 +4817,7 @@ var NativeDocument = (function (exports) {
4817
4817
  */
4818
4818
  const $applyReadOnly = (observer, name, context) => {
4819
4819
  const readOnlyError = (method) => () => {
4820
- DebugManager$2.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
4820
+ DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
4821
4821
  throw new NativeDocumentError(
4822
4822
  `Store.${context}('${name}') is read-only.`
4823
4823
  );
@@ -4848,7 +4848,7 @@ var NativeDocument = (function (exports) {
4848
4848
  */
4849
4849
  create(name, value) {
4850
4850
  if ($stores.has(name)) {
4851
- DebugManager$2.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
4851
+ DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
4852
4852
  throw new NativeDocumentError(
4853
4853
  `Store.create('${name}') : a store with this name already exists.`
4854
4854
  );
@@ -4869,7 +4869,7 @@ var NativeDocument = (function (exports) {
4869
4869
  */
4870
4870
  createResettable(name, value) {
4871
4871
  if ($stores.has(name)) {
4872
- DebugManager$2.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
4872
+ DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
4873
4873
  throw new NativeDocumentError(
4874
4874
  `Store.createResettable('${name}') : a store with this name already exists.`
4875
4875
  );
@@ -4905,7 +4905,7 @@ var NativeDocument = (function (exports) {
4905
4905
  */
4906
4906
  createComposed(name, computation, dependencies) {
4907
4907
  if ($stores.has(name)) {
4908
- DebugManager$2.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
4908
+ DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
4909
4909
  throw new NativeDocumentError(
4910
4910
  `Store.createComposed('${name}') : a store with this name already exists.`
4911
4911
  );
@@ -4928,7 +4928,7 @@ var NativeDocument = (function (exports) {
4928
4928
  }
4929
4929
  const depItem = $stores.get(depName);
4930
4930
  if (!depItem) {
4931
- DebugManager$2.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
4931
+ DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
4932
4932
  throw new NativeDocumentError(
4933
4933
  `Store.createComposed('${name}') : dependency store '${depName}' not found.`
4934
4934
  );
@@ -4962,13 +4962,13 @@ var NativeDocument = (function (exports) {
4962
4962
  reset(name) {
4963
4963
  const item = $getStoreOrThrow('reset', name);
4964
4964
  if (item.composed) {
4965
- DebugManager$2.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
4965
+ DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
4966
4966
  throw new NativeDocumentError(
4967
4967
  `Store.reset('${name}') : composed stores cannot be reset.`
4968
4968
  );
4969
4969
  }
4970
4970
  if (!item.resettable) {
4971
- DebugManager$2.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
4971
+ DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
4972
4972
  throw new NativeDocumentError(
4973
4973
  `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
4974
4974
  );
@@ -4989,7 +4989,7 @@ var NativeDocument = (function (exports) {
4989
4989
  const item = $getStoreOrThrow('use', name);
4990
4990
 
4991
4991
  if (item.composed) {
4992
- DebugManager$2.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
4992
+ DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
4993
4993
  throw new NativeDocumentError(
4994
4994
  `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
4995
4995
  );
@@ -5056,7 +5056,7 @@ var NativeDocument = (function (exports) {
5056
5056
  get(name) {
5057
5057
  const item = $stores.get(name);
5058
5058
  if (!item) {
5059
- DebugManager$2.warn('Store', `Store.get('${name}') : store not found.`);
5059
+ DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
5060
5060
  return null;
5061
5061
  }
5062
5062
  return item.observer;
@@ -5078,7 +5078,7 @@ var NativeDocument = (function (exports) {
5078
5078
  delete(name) {
5079
5079
  const item = $stores.get(name);
5080
5080
  if (!item) {
5081
- DebugManager$2.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
5081
+ DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
5082
5082
  return;
5083
5083
  }
5084
5084
  item.subscribers.forEach(follower => follower.destroy());
@@ -5180,7 +5180,7 @@ var NativeDocument = (function (exports) {
5180
5180
  return undefined;
5181
5181
  },
5182
5182
  set(target, prop, value) {
5183
- DebugManager$2.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
5183
+ DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
5184
5184
  throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
5185
5185
  },
5186
5186
  deleteProperty(target, prop) {
@@ -5271,7 +5271,7 @@ var NativeDocument = (function (exports) {
5271
5271
  }
5272
5272
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
5273
5273
  } catch (e) {
5274
- DebugManager$2.error('ForEach', `Error creating element for key ${keyId}` , e);
5274
+ DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
5275
5275
  throw e;
5276
5276
  }
5277
5277
  return keyId;
@@ -5661,7 +5661,7 @@ var NativeDocument = (function (exports) {
5661
5661
  return condition ? ElementCreator.getChild(child) : null;
5662
5662
  }
5663
5663
 
5664
- return DebugManager$2.warn('ShowIf', "ShowIf : condition must be an Observable or boolean / "+comment, condition);
5664
+ return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable or boolean / "+comment, condition);
5665
5665
  }
5666
5666
  const element = Anchor('Show if : '+(comment || ''));
5667
5667
 
@@ -7215,7 +7215,7 @@ var NativeDocument = (function (exports) {
7215
7215
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
7216
7216
  this.handleRouteChange(route, params, query, path);
7217
7217
  } catch (e) {
7218
- DebugManager$2.error('HistoryRouter', 'Error in pushState', e);
7218
+ DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
7219
7219
  }
7220
7220
  };
7221
7221
  /**
@@ -7228,7 +7228,7 @@ var NativeDocument = (function (exports) {
7228
7228
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
7229
7229
  this.handleRouteChange(route, params, {}, path);
7230
7230
  } catch(e) {
7231
- DebugManager$2.error('HistoryRouter', 'Error in replaceState', e);
7231
+ DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
7232
7232
  }
7233
7233
  };
7234
7234
  this.forward = function() {
@@ -7255,7 +7255,7 @@ var NativeDocument = (function (exports) {
7255
7255
  }
7256
7256
  this.handleRouteChange(route, params, query, path);
7257
7257
  } catch(e) {
7258
- DebugManager$2.error('HistoryRouter', 'Error in popstate event', e);
7258
+ DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
7259
7259
  }
7260
7260
  });
7261
7261
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -7484,7 +7484,7 @@ var NativeDocument = (function (exports) {
7484
7484
  listener(request);
7485
7485
  next && next(request);
7486
7486
  } catch (e) {
7487
- DebugManager$2.warn('Route Listener', 'Error in listener:', e);
7487
+ DebugManager$1.warn('Route Listener', 'Error in listener:', e);
7488
7488
  }
7489
7489
  }
7490
7490
  };
@@ -7673,7 +7673,7 @@ var NativeDocument = (function (exports) {
7673
7673
  */
7674
7674
  Router.create = function(options, callback) {
7675
7675
  if(!Validator.isFunction(callback)) {
7676
- DebugManager$2.error('Router', 'Callback must be a function');
7676
+ DebugManager$1.error('Router', 'Callback must be a function');
7677
7677
  throw new RouterError('Callback must be a function');
7678
7678
  }
7679
7679
  const router = new Router(options);
@@ -7878,7 +7878,7 @@ var NativeDocument = (function (exports) {
7878
7878
  exports.HtmlElementWrapper = HtmlElementWrapper;
7879
7879
  exports.NDElement = NDElement;
7880
7880
  exports.Observable = Observable;
7881
- exports.PluginsManager = PluginsManager$1;
7881
+ exports.PluginsManager = PluginsManager;
7882
7882
  exports.SingletonView = SingletonView;
7883
7883
  exports.Store = Store;
7884
7884
  exports.StoreFactory = StoreFactory;