vasille 1.2.9 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +195 -129
  3. package/cdn/es2015.js +3231 -0
  4. package/cdn/es5.js +3675 -0
  5. package/flow-typed/vasille.js +839 -0
  6. package/lib/binding/attribute.js +32 -0
  7. package/lib/binding/binding.js +39 -0
  8. package/lib/binding/class.js +51 -0
  9. package/lib/binding/style.js +29 -0
  10. package/lib/core/core.js +186 -0
  11. package/lib/core/destroyable.js +45 -0
  12. package/lib/core/errors.js +16 -0
  13. package/lib/core/executor.js +154 -0
  14. package/lib/core/ivalue.js +56 -0
  15. package/lib/core/signal.js +50 -0
  16. package/lib/core/slot.js +47 -0
  17. package/lib/index.js +27 -22
  18. package/lib/models/array-model.js +208 -0
  19. package/lib/models/listener.js +130 -0
  20. package/lib/models/map-model.js +66 -0
  21. package/lib/models/model.js +1 -0
  22. package/lib/models/object-model.js +78 -0
  23. package/lib/models/set-model.js +62 -0
  24. package/lib/node/app.js +39 -0
  25. package/lib/node/interceptor.js +83 -0
  26. package/lib/node/node.js +1204 -0
  27. package/lib/node/watch.js +27 -0
  28. package/lib/value/expression.js +83 -0
  29. package/lib/value/mirror.js +58 -0
  30. package/lib/value/pointer.js +26 -0
  31. package/lib/value/reference.js +55 -0
  32. package/lib/views/array-view.js +21 -0
  33. package/lib/views/base-view.js +49 -0
  34. package/lib/views/map-view.js +19 -0
  35. package/lib/views/object-view.js +19 -0
  36. package/lib/views/repeat-node.js +106 -0
  37. package/lib/views/repeater.js +63 -0
  38. package/lib/views/set-view.js +22 -0
  39. package/package.json +26 -18
  40. package/types/binding/attribute.d.ts +23 -0
  41. package/types/binding/binding.d.ts +30 -0
  42. package/types/binding/class.d.ts +23 -0
  43. package/types/binding/style.d.ts +23 -0
  44. package/types/core/core.d.ts +144 -0
  45. package/types/core/destroyable.d.ts +15 -0
  46. package/types/core/errors.d.ts +4 -0
  47. package/types/core/executor.d.ts +87 -0
  48. package/types/core/ivalue.d.ts +45 -0
  49. package/types/core/signal.d.ts +35 -0
  50. package/types/core/slot.d.ts +45 -0
  51. package/types/index.d.ts +27 -21
  52. package/types/models/array-model.d.ts +103 -0
  53. package/types/models/listener.d.ts +74 -0
  54. package/types/models/map-model.d.ts +35 -0
  55. package/types/models/model.d.ts +19 -0
  56. package/types/models/object-model.d.ts +36 -0
  57. package/types/models/set-model.d.ts +34 -0
  58. package/types/node/app.d.ts +42 -0
  59. package/types/node/interceptor.d.ts +50 -0
  60. package/types/node/node.d.ts +741 -0
  61. package/types/node/watch.d.ts +23 -0
  62. package/types/value/expression.d.ts +60 -0
  63. package/types/value/mirror.d.ts +35 -0
  64. package/types/value/pointer.d.ts +19 -0
  65. package/types/value/reference.d.ts +30 -0
  66. package/types/views/array-view.d.ts +13 -0
  67. package/types/views/base-view.d.ts +43 -0
  68. package/types/views/map-view.d.ts +11 -0
  69. package/types/views/object-view.d.ts +11 -0
  70. package/types/views/repeat-node.d.ts +35 -0
  71. package/types/views/repeater.d.ts +38 -0
  72. package/types/views/set-view.d.ts +11 -0
  73. package/CHANGELOG.md +0 -23
  74. package/img/favicon.svg +0 -441
  75. package/img/getLocus.svg +0 -18
  76. package/img/logo.png +0 -0
  77. package/img/logo.svg +0 -550
  78. package/img/scores-o-log.png +0 -0
  79. package/img/scores-o.png +0 -0
  80. package/img/scores-wo-log.png +0 -0
  81. package/img/scores-wo.png +0 -0
  82. package/img/x1-x32.png +0 -0
  83. package/lib/attribute.js +0 -71
  84. package/lib/attribute.js.map +0 -1
  85. package/lib/bind.js +0 -286
  86. package/lib/bind.js.map +0 -1
  87. package/lib/class.js +0 -97
  88. package/lib/class.js.map +0 -1
  89. package/lib/executor.js +0 -167
  90. package/lib/executor.js.map +0 -1
  91. package/lib/index.js.map +0 -1
  92. package/lib/interfaces/core.js +0 -247
  93. package/lib/interfaces/core.js.map +0 -1
  94. package/lib/interfaces/destroyable.js +0 -39
  95. package/lib/interfaces/destroyable.js.map +0 -1
  96. package/lib/interfaces/errors.js +0 -49
  97. package/lib/interfaces/errors.js.map +0 -1
  98. package/lib/interfaces/ibind.js +0 -31
  99. package/lib/interfaces/ibind.js.map +0 -1
  100. package/lib/interfaces/idefinition.js +0 -64
  101. package/lib/interfaces/idefinition.js.map +0 -1
  102. package/lib/interfaces/ivalue.js +0 -60
  103. package/lib/interfaces/ivalue.js.map +0 -1
  104. package/lib/models.js +0 -579
  105. package/lib/models.js.map +0 -1
  106. package/lib/node.js +0 -2155
  107. package/lib/node.js.map +0 -1
  108. package/lib/property.js +0 -38
  109. package/lib/property.js.map +0 -1
  110. package/lib/style.js +0 -66
  111. package/lib/style.js.map +0 -1
  112. package/lib/value.js +0 -203
  113. package/lib/value.js.map +0 -1
  114. package/lib/views.js +0 -688
  115. package/lib/views.js.map +0 -1
  116. package/types/attribute.d.ts +0 -18
  117. package/types/bind.d.ts +0 -72
  118. package/types/class.d.ts +0 -19
  119. package/types/data.d.ts +0 -11
  120. package/types/event.d.ts +0 -10
  121. package/types/executor.d.ts +0 -57
  122. package/types/interfaces/core.d.ts +0 -129
  123. package/types/interfaces/destroyable.d.ts +0 -11
  124. package/types/interfaces/errors.d.ts +0 -24
  125. package/types/interfaces/ibind.d.ts +0 -19
  126. package/types/interfaces/idefinition.d.ts +0 -29
  127. package/types/interfaces/ivalue.d.ts +0 -40
  128. package/types/models.d.ts +0 -179
  129. package/types/node.d.ts +0 -906
  130. package/types/property.d.ts +0 -9
  131. package/types/style.d.ts +0 -28
  132. package/types/value.d.ts +0 -43
  133. package/types/views.d.ts +0 -135
package/cdn/es5.js ADDED
@@ -0,0 +1,3675 @@
1
+ (function(){
2
+ var __extends = function (child, parent) {
3
+ child.prototype = Object.create(parent.prototype);
4
+ }
5
+ var __spreadArray = function (to, from, pack) {
6
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
7
+ if (ar || !(i in from)) {
8
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
9
+ ar[i] = from[i];
10
+ }
11
+ }
12
+ return to.concat(ar || Array.prototype.slice.call(from));
13
+ };
14
+
15
+ var Set = window.Set || /** @class */ (function (_super) {
16
+ __extends(Set, _super);
17
+ function Set(set) {
18
+ if (set === void 0) { set = []; }
19
+ var _this = this; _super.call(this);
20
+ set.forEach(function (item) {
21
+ _this.add (item)
22
+ });
23
+ Object.defineProperty(_this, 'hash', {
24
+ value: Object.create(null),
25
+ writable: true
26
+ });
27
+ return _this;
28
+ }
29
+
30
+ Set.prototype.has = function (value) {
31
+ if (typeof value === "string" || typeof value === "number") {
32
+ return this.hash[value] !== void 0;
33
+ }
34
+ else {
35
+ return this.indexOf(value) !== -1;
36
+ }
37
+ };
38
+
39
+ Set.prototype.add = function (value) {
40
+ if (typeof value === "string" || typeof value === "number") {
41
+ if (this.hash[value]) {
42
+ return this;
43
+ }
44
+ else {
45
+ this.hash[value] = true;
46
+ }
47
+ }
48
+ else {
49
+ if (this.indexOf(value) !== -1) {
50
+ return this;
51
+ }
52
+ this.push(value);
53
+ }
54
+ return this;
55
+ };
56
+
57
+ Set.prototype.clear = function () {
58
+ this.hash = Object.create(null);
59
+ this.splice(0);
60
+ };
61
+
62
+ Set.prototype.delete = function (value) {
63
+ if (typeof value === "string" || typeof value === "number") {
64
+ if (this.hash[value] !== void 0) {
65
+ delete this.hash[value];
66
+ }
67
+ }
68
+ else {
69
+ var index = this.indexOf(value);
70
+ if (index !== -1) {
71
+ this.splice(index, 1);
72
+ }
73
+ }
74
+ this.push(value);
75
+ return this;
76
+ };
77
+ return Set;
78
+ }(Array));
79
+
80
+ var Map = window.Map || /** @class */ (function (_super) {
81
+ __extends(Map, _super);
82
+
83
+ function Map(map) {
84
+ if (map === void 0) { map = []; }
85
+ var _this = this; _super.call(this);
86
+ Object.defineProperty(_this, 'hash', {
87
+ value: Object.create(null),
88
+ writable: true
89
+ });
90
+ map.forEach(function (_a) {
91
+ var key = _a[0], value = _a[1];
92
+ this.set(key, value);
93
+ });
94
+ return _this;
95
+ }
96
+
97
+ Map.prototype.clear = function () {
98
+ this.hash = Object.create(null);
99
+ this.splice(0);
100
+ };
101
+
102
+ Map.prototype.delete = function (key) {
103
+ if (typeof key === "string" || typeof key === "number") {
104
+ if (this.hash[key] !== void 0) {
105
+ delete this.hash[key];
106
+ }
107
+ }
108
+ else {
109
+ for (var i = 0; i < this.length; i++) {
110
+ if (this[i][0] === key) {
111
+ this.splice(i, 1);
112
+ }
113
+ }
114
+ }
115
+ };
116
+
117
+ function indexOfKey(key) {
118
+ for (var i = 0; i < this.length; i++) {
119
+ if (this[i][0] === key) {
120
+ return i;
121
+ }
122
+ }
123
+ return -1;
124
+ }
125
+
126
+ Map.prototype.set = function (key, value) {
127
+ if (typeof key === "string" || typeof key === "number") {
128
+ this.hash[key] = value;
129
+ }
130
+ else {
131
+ var index = indexOfKey.call(this, key);
132
+ if (index === -1) {
133
+ this.push([key, value]);
134
+ }
135
+ else {
136
+ this[index][1] = value;
137
+ }
138
+ }
139
+ };
140
+
141
+
142
+ Map.prototype.has = function (key) {
143
+ if (typeof key === "string" || typeof key === "number") {
144
+ return !!this.hash[key];
145
+ }
146
+ else {
147
+ return indexOfKey.call(this, key) !== -1;
148
+ }
149
+ };
150
+
151
+ Map.prototype.get = function (key) {
152
+ if (typeof key === "string" || typeof key === "number") {
153
+ return this.hash[key];
154
+ }
155
+ else {
156
+ var index = indexOfKey.call(this, key);
157
+ if (index !== -1) {
158
+ return this[index][1];
159
+ }
160
+ else {
161
+ return void 0;
162
+ }
163
+ }
164
+ };
165
+
166
+ return Map;
167
+ }(Array));
168
+ // ./lib-es5/models/model.js
169
+
170
+
171
+
172
+ // ./lib-es5/models/listener.js
173
+ /**
174
+ * Represent a listener for a model
175
+ * @class Listener
176
+ */
177
+ var Listener = /** @class */ (function () {
178
+ function Listener() {
179
+ Object.defineProperties(this, {
180
+ onAdded: {
181
+ value: new Set,
182
+ writable: false,
183
+ configurable: false
184
+ },
185
+ onRemoved: {
186
+ value: new Set,
187
+ writable: false,
188
+ configurable: false
189
+ },
190
+ frozen: {
191
+ value: false,
192
+ writable: true,
193
+ configurable: false
194
+ },
195
+ queue: {
196
+ value: [],
197
+ writable: false,
198
+ configurable: false
199
+ }
200
+ });
201
+ }
202
+ /**
203
+ * Exclude the repeated operation in queue
204
+ * @private
205
+ */
206
+ Listener.prototype.excludeRepeat = function (index) {
207
+ var _this = this;
208
+ this.queue.forEach(function (item, i) {
209
+ if (item.index === index) {
210
+ _this.queue.splice(i, 1);
211
+ return true;
212
+ }
213
+ });
214
+ return false;
215
+ };
216
+ /**
217
+ * Emits added event to listeners
218
+ * @param index {*} index of value
219
+ * @param value {*} value of added item
220
+ */
221
+ Listener.prototype.emitAdded = function (index, value) {
222
+ if (this.frozen) {
223
+ if (!this.excludeRepeat(index)) {
224
+ this.queue.push({ sign: true, index: index, value: value });
225
+ }
226
+ }
227
+ else {
228
+ this.onAdded.forEach(function (handler) {
229
+ handler(index, value);
230
+ });
231
+ }
232
+ };
233
+ /**
234
+ * Emits removed event to listeners
235
+ * @param index {*} index of removed value
236
+ * @param value {*} value of removed item
237
+ */
238
+ Listener.prototype.emitRemoved = function (index, value) {
239
+ if (this.frozen) {
240
+ if (!this.excludeRepeat(index)) {
241
+ this.queue.push({ sign: false, index: index, value: value });
242
+ }
243
+ }
244
+ else {
245
+ this.onRemoved.forEach(function (handler) {
246
+ handler(index, value);
247
+ });
248
+ }
249
+ };
250
+ /**
251
+ * Adds a handler to added event
252
+ * @param handler {function} function to run on event emitting
253
+ */
254
+ Listener.prototype.onAdd = function (handler) {
255
+ this.onAdded.add(handler);
256
+ };
257
+ /**
258
+ * Adds a handler to removed event
259
+ * @param handler {function} function to run on event emitting
260
+ */
261
+ Listener.prototype.onRemove = function (handler) {
262
+ this.onRemoved.add(handler);
263
+ };
264
+ /**
265
+ * Removes an handler from added event
266
+ * @param handler {function} handler to remove
267
+ */
268
+ Listener.prototype.offAdd = function (handler) {
269
+ this.onAdded.delete(handler);
270
+ };
271
+ /**
272
+ * Removes an handler form removed event
273
+ * @param handler {function} handler to remove
274
+ */
275
+ Listener.prototype.offRemove = function (handler) {
276
+ this.onRemoved.delete(handler);
277
+ };
278
+ /**
279
+ * Run all queued operation and enable reactivity
280
+ */
281
+ Listener.prototype.enableReactivity = function () {
282
+ var _this = this;
283
+ this.queue.forEach(function (item) {
284
+ if (item.sign) {
285
+ _this.onAdded.forEach(function (handler) {
286
+ handler(item.index, item.value);
287
+ });
288
+ }
289
+ else {
290
+ _this.onRemoved.forEach(function (handler) {
291
+ handler(item.index, item.value);
292
+ });
293
+ }
294
+ });
295
+ this.queue.splice(0);
296
+ this.frozen = false;
297
+ };
298
+ /**
299
+ * Disable the reactivity and enable the queue
300
+ */
301
+ Listener.prototype.disableReactivity = function () {
302
+ this.frozen = true;
303
+ };
304
+ return Listener;
305
+ }());
306
+
307
+
308
+ window.Listener = Listener;
309
+
310
+ // ./lib-es5/models/object-model.js
311
+ /**
312
+ * Object based model
313
+ * @extends Object
314
+ */
315
+ var ObjectModel = /** @class */ (function (_super) {
316
+ __extends(ObjectModel, _super);
317
+ /**
318
+ * Constructs a object model
319
+ * @param obj {Object} input data
320
+ */
321
+ function ObjectModel(obj) {
322
+ if (obj === void 0) { obj = {}; }
323
+ var _this = this; _super.call(this);
324
+ Object.defineProperty(_this, 'listener', {
325
+ value: new Listener,
326
+ writable: false,
327
+ configurable: false
328
+ });
329
+ for (var i in obj) {
330
+ Object.defineProperty(_this, i, {
331
+ value: obj[i],
332
+ configurable: true,
333
+ writable: true,
334
+ enumerable: true
335
+ });
336
+ _this.listener.emitAdded(i, obj[i]);
337
+ }
338
+ return _this;
339
+ }
340
+ /**
341
+ * Gets a value of a field
342
+ * @param key {string}
343
+ * @return {*}
344
+ */
345
+ ObjectModel.prototype.get = function (key) {
346
+ var ts = this;
347
+ return ts[key];
348
+ };
349
+ /**
350
+ * Sets an object property value
351
+ * @param key {string} property name
352
+ * @param v {*} property value
353
+ * @return {ObjectModel} a pointer to this
354
+ */
355
+ ObjectModel.prototype.set = function (key, v) {
356
+ var ts = this;
357
+ // eslint-disable-next-line no-prototype-builtins
358
+ if (ts.hasOwnProperty(key)) {
359
+ this.listener.emitRemoved(key, ts[key]);
360
+ ts[key] = v;
361
+ }
362
+ else {
363
+ Object.defineProperty(ts, key, {
364
+ value: v,
365
+ configurable: true,
366
+ writable: true,
367
+ enumerable: true
368
+ });
369
+ }
370
+ this.listener.emitAdded(key, ts[key]);
371
+ return this;
372
+ };
373
+ /**
374
+ * Deletes an object property
375
+ * @param key {string} property name
376
+ */
377
+ ObjectModel.prototype.delete = function (key) {
378
+ var ts = this;
379
+ if (ts[key]) {
380
+ this.listener.emitRemoved(key, ts[key]);
381
+ delete ts[key];
382
+ }
383
+ };
384
+ ObjectModel.prototype.enableReactivity = function () {
385
+ this.listener.enableReactivity();
386
+ };
387
+ ObjectModel.prototype.disableReactivity = function () {
388
+ this.listener.disableReactivity();
389
+ };
390
+ return ObjectModel;
391
+ }(Object));
392
+
393
+
394
+ window.ObjectModel = ObjectModel;
395
+
396
+ // ./lib-es5/models/set-model.js
397
+ /**
398
+ * A Set based model
399
+ * @class SetModel
400
+ * @extends Set
401
+ * @implements IModel
402
+ */
403
+ var SetModel = /** @class */ (function (_super) {
404
+ __extends(SetModel, _super);
405
+ /**
406
+ * Constructs a set model based on a set
407
+ * @param set {Set} input data
408
+ */
409
+ function SetModel(set) {
410
+ if (set === void 0) { set = []; }
411
+ var _this = this; _super.call(this);
412
+ Object.defineProperty(_this, 'listener', {
413
+ value: new Listener,
414
+ writable: false,
415
+ configurable: false
416
+ });
417
+ set.forEach(function (item) {
418
+ _super.prototype.add.call(_this, item);
419
+ });
420
+ return _this;
421
+ }
422
+ /**
423
+ * Calls Set.add and notify abut changes
424
+ * @param value {*} value
425
+ * @return {this} a pointer to this
426
+ */
427
+ SetModel.prototype.add = function (value) {
428
+ if (!_super.prototype.has.call(this, value)) {
429
+ this.listener.emitAdded(value, value);
430
+ _super.prototype.add.call(this, value);
431
+ }
432
+ return this;
433
+ };
434
+ /**
435
+ * Calls Set.clear and notify abut changes
436
+ */
437
+ SetModel.prototype.clear = function () {
438
+ var _this = this;
439
+ this.forEach(function (item) {
440
+ _this.listener.emitRemoved(item, item);
441
+ });
442
+ _super.prototype.clear.call(this);
443
+ };
444
+ /**
445
+ * Calls Set.delete and notify abut changes
446
+ * @param value {*}
447
+ * @return {boolean} true if a value was deleted, otherwise false
448
+ */
449
+ SetModel.prototype.delete = function (value) {
450
+ if (_super.prototype.has.call(this, value)) {
451
+ this.listener.emitRemoved(value, value);
452
+ }
453
+ return _super.prototype.delete.call(this, value);
454
+ };
455
+ SetModel.prototype.enableReactivity = function () {
456
+ this.listener.enableReactivity();
457
+ };
458
+ SetModel.prototype.disableReactivity = function () {
459
+ this.listener.disableReactivity();
460
+ };
461
+ return SetModel;
462
+ }(Set));
463
+
464
+
465
+ window.SetModel = SetModel;
466
+
467
+ // ./lib-es5/models/map-model.js
468
+ /**
469
+ * A Map based memory
470
+ * @class MapModel
471
+ * @extends Map
472
+ * @implements IModel
473
+ */
474
+ var MapModel = /** @class */ (function (_super) {
475
+ __extends(MapModel, _super);
476
+ /**
477
+ * Constructs a map model
478
+ * @param map {[*, *][]} input data
479
+ */
480
+ function MapModel(map) {
481
+ if (map === void 0) { map = []; }
482
+ var _this = this; _super.call(this);
483
+ Object.defineProperty(_this, 'listener', {
484
+ value: new Listener,
485
+ writable: false,
486
+ configurable: false
487
+ });
488
+ map.forEach(function (_a) {
489
+ var key = _a[0], value = _a[1];
490
+ _super.prototype.set.call(_this, key, value);
491
+ });
492
+ return _this;
493
+ }
494
+ /**
495
+ * Calls Map.clear and notify abut changes
496
+ */
497
+ MapModel.prototype.clear = function () {
498
+ var _this = this;
499
+ this.forEach(function (value, key) {
500
+ _this.listener.emitRemoved(key, value);
501
+ });
502
+ _super.prototype.clear.call(this);
503
+ };
504
+ /**
505
+ * Calls Map.delete and notify abut changes
506
+ * @param key {*} key
507
+ * @return {boolean} true if removed something, otherwise false
508
+ */
509
+ MapModel.prototype.delete = function (key) {
510
+ var tmp = _super.prototype.get.call(this, key);
511
+ if (tmp) {
512
+ this.listener.emitRemoved(key, tmp);
513
+ }
514
+ return _super.prototype.delete.call(this, key);
515
+ };
516
+ /**
517
+ * Calls Map.set and notify abut changes
518
+ * @param key {*} key
519
+ * @param value {*} value
520
+ * @return {MapModel} a pointer to this
521
+ */
522
+ MapModel.prototype.set = function (key, value) {
523
+ var tmp = _super.prototype.get.call(this, key);
524
+ if (tmp) {
525
+ this.listener.emitRemoved(key, tmp);
526
+ }
527
+ _super.prototype.set.call(this, key, value);
528
+ this.listener.emitAdded(key, value);
529
+ return this;
530
+ };
531
+ MapModel.prototype.enableReactivity = function () {
532
+ this.listener.enableReactivity();
533
+ };
534
+ MapModel.prototype.disableReactivity = function () {
535
+ this.listener.disableReactivity();
536
+ };
537
+ return MapModel;
538
+ }(Map));
539
+
540
+
541
+ window.MapModel = MapModel;
542
+
543
+ // ./lib-es5/models/array-model.js
544
+ /**
545
+ * Model based on Array class
546
+ * @extends Array
547
+ * @implements IModel
548
+ */
549
+ var ArrayModel = /** @class */ (function (_super) {
550
+ __extends(ArrayModel, _super);
551
+ /**
552
+ * @param data {Array} input data
553
+ */
554
+ function ArrayModel(data) {
555
+ if (data === void 0) { data = []; }
556
+ var _this = this; _super.call(this);
557
+ Object.defineProperty(_this, 'listener', {
558
+ value: new Listener,
559
+ writable: false,
560
+ configurable: false
561
+ });
562
+ for (var i = 0; i < data.length; i++) {
563
+ _super.prototype.push.call(_this, data[i]);
564
+ }
565
+ return _this;
566
+ }
567
+ Object.defineProperty(ArrayModel.prototype, "last", {
568
+ /* Array members */
569
+ /**
570
+ * Gets the last item of array
571
+ * @return {*} the last item of array
572
+ */
573
+ get: function () {
574
+ return this.length ? this[this.length - 1] : null;
575
+ },
576
+ enumerable: false,
577
+ configurable: true
578
+ });
579
+ /**
580
+ * Calls Array.fill and notify about changes
581
+ * @param value {*} value to fill with
582
+ * @param start {?number} begin index
583
+ * @param end {?number} end index
584
+ */
585
+ ArrayModel.prototype.fill = function (value, start, end) {
586
+ if (!start) {
587
+ start = 0;
588
+ }
589
+ if (!end) {
590
+ end = this.length;
591
+ }
592
+ for (var i = start; i < end; i++) {
593
+ this.listener.emitRemoved(this[i], this[i]);
594
+ this[i] = value;
595
+ this.listener.emitAdded(value, value);
596
+ }
597
+ return this;
598
+ };
599
+ /**
600
+ * Calls Array.pop and notify about changes
601
+ * @return {*} removed value
602
+ */
603
+ ArrayModel.prototype.pop = function () {
604
+ var v = _super.prototype.pop.call(this);
605
+ if (v !== undefined) {
606
+ this.listener.emitRemoved(v, v);
607
+ }
608
+ return v;
609
+ };
610
+ /**
611
+ * Calls Array.push and notify about changes
612
+ * @param items {...*} values to push
613
+ * @return {number} new length of array
614
+ */
615
+ ArrayModel.prototype.push = function () {
616
+ var _this = this;
617
+ var items = [];
618
+ for (var _i = 0; _i < arguments.length; _i++) {
619
+ items[_i] = arguments[_i];
620
+ }
621
+ items.forEach(function (item) {
622
+ _this.listener.emitAdded(item, item);
623
+ _super.prototype.push.call(_this, item);
624
+ });
625
+ return this.length;
626
+ };
627
+ /**
628
+ * Calls Array.shift and notify about changed
629
+ * @return {*} the shifted value
630
+ */
631
+ ArrayModel.prototype.shift = function () {
632
+ var v = _super.prototype.shift.call(this);
633
+ if (v !== undefined) {
634
+ this.listener.emitRemoved(v, v);
635
+ }
636
+ return v;
637
+ };
638
+ /**
639
+ * Calls Array.splice and notify about changed
640
+ * @param start {number} start index
641
+ * @param deleteCount {?number} delete count
642
+ * @param items {...*}
643
+ * @return {ArrayModel} a pointer to this
644
+ */
645
+ ArrayModel.prototype.splice = function (start, deleteCount) {
646
+ var items = [];
647
+ for (var _i = 2; _i < arguments.length; _i++) {
648
+ items[_i - 2] = arguments[_i];
649
+ }
650
+ start = Math.min(start, this.length);
651
+ deleteCount = deleteCount || this.length - start;
652
+ var before = this[start + deleteCount];
653
+ for (var i = 0; i < deleteCount; i++) {
654
+ var index = start + deleteCount - i - 1;
655
+ if (this[index] !== undefined) {
656
+ this.listener.emitRemoved(this[index], this[index]);
657
+ }
658
+ }
659
+ for (var i = 0; i < items.length; i++) {
660
+ this.listener.emitAdded(before, items[i]);
661
+ }
662
+ return new ArrayModel(_super.prototype.splice.apply(this, __spreadArray([start, deleteCount], items, false)));
663
+ };
664
+ /**
665
+ * Calls Array.unshift and notify about changed
666
+ * @param items {...*} values to insert
667
+ * @return {number} the length after prepend
668
+ */
669
+ ArrayModel.prototype.unshift = function () {
670
+ var items = [];
671
+ for (var _i = 0; _i < arguments.length; _i++) {
672
+ items[_i] = arguments[_i];
673
+ }
674
+ for (var i = 0; i < items.length; i++) {
675
+ this.listener.emitAdded(this[i], items[i]);
676
+ }
677
+ return _super.prototype.unshift.apply(this, items);
678
+ };
679
+ /**
680
+ * Inserts a value to the end of array
681
+ * @param v {*} value to insert
682
+ */
683
+ ArrayModel.prototype.append = function (v) {
684
+ this.listener.emitAdded(null, v);
685
+ _super.prototype.push.call(this, v);
686
+ return this;
687
+ };
688
+ /**
689
+ * Clears array
690
+ * @return {this} a pointer to this
691
+ */
692
+ ArrayModel.prototype.clear = function () {
693
+ var _this = this;
694
+ this.forEach(function (v) {
695
+ _this.listener.emitRemoved(v, v);
696
+ });
697
+ _super.prototype.splice.call(this, 0);
698
+ return this;
699
+ };
700
+ /**
701
+ * Inserts a value to position `index`
702
+ * @param index {number} index to insert value
703
+ * @param v {*} value to insert
704
+ * @return {this} a pointer to this
705
+ */
706
+ ArrayModel.prototype.insert = function (index, v) {
707
+ this.listener.emitAdded(this[index], v);
708
+ _super.prototype.splice.call(this, index, 0, v);
709
+ return this;
710
+ };
711
+ /**
712
+ * Inserts a value to the beginning of array
713
+ * @param v {*} value to insert
714
+ * @return {this} a pointer to this
715
+ */
716
+ ArrayModel.prototype.prepend = function (v) {
717
+ this.listener.emitAdded(this[0], v);
718
+ _super.prototype.unshift.call(this, v);
719
+ return this;
720
+ };
721
+ /**
722
+ * Removes a value from an index
723
+ * @param index {number} index of value to remove
724
+ * @return {this} a pointer to this
725
+ */
726
+ ArrayModel.prototype.removeAt = function (index) {
727
+ if (index > 0 && index < this.length) {
728
+ this.listener.emitRemoved(this[index], this[index]);
729
+ _super.prototype.splice.call(this, index, 1);
730
+ }
731
+ return this;
732
+ };
733
+ /**
734
+ * Removes the first value of array
735
+ * @return {this} a pointer to this
736
+ */
737
+ ArrayModel.prototype.removeFirst = function () {
738
+ if (this.length) {
739
+ this.listener.emitRemoved(this[0], this[0]);
740
+ _super.prototype.shift.call(this);
741
+ }
742
+ return this;
743
+ };
744
+ /**
745
+ * Removes the ast value of array
746
+ * @return {this} a pointer to this
747
+ */
748
+ ArrayModel.prototype.removeLast = function () {
749
+ var last = this.last;
750
+ if (last != null) {
751
+ this.listener.emitRemoved(this[this.length - 1], last);
752
+ _super.prototype.pop.call(this);
753
+ }
754
+ return this;
755
+ };
756
+ /**
757
+ * Remove the first occurrence of value
758
+ * @param v {*} value to remove
759
+ * @return {this}
760
+ */
761
+ ArrayModel.prototype.removeOne = function (v) {
762
+ this.removeAt(this.indexOf(v));
763
+ return this;
764
+ };
765
+ ArrayModel.prototype.enableReactivity = function () {
766
+ this.listener.enableReactivity();
767
+ };
768
+ ArrayModel.prototype.disableReactivity = function () {
769
+ this.listener.disableReactivity();
770
+ };
771
+ return ArrayModel;
772
+ }(Array));
773
+
774
+
775
+ window.ArrayModel = ArrayModel;
776
+
777
+ // ./lib-es5/core/signal.js
778
+ /**
779
+ * Signal is an event generator
780
+ * @class Signal
781
+ */
782
+ var Signal = /** @class */ (function () {
783
+ function Signal() {
784
+ /**
785
+ * Handler of event
786
+ * @type {Set}
787
+ * @private
788
+ */
789
+ this.handlers = new Set;
790
+ }
791
+ /**
792
+ * Emit event
793
+ * @param a1 {*} argument
794
+ * @param a2 {*} argument
795
+ * @param a3 {*} argument
796
+ * @param a4 {*} argument
797
+ * @param a5 {*} argument
798
+ * @param a6 {*} argument
799
+ * @param a7 {*} argument
800
+ * @param a8 {*} argument
801
+ * @param a9 {*} argument
802
+ */
803
+ Signal.prototype.emit = function (a1, a2, a3, a4, a5, a6, a7, a8, a9) {
804
+ this.handlers.forEach(function (handler) {
805
+ try {
806
+ handler(a1, a2, a3, a4, a5, a6, a7, a8, a9);
807
+ }
808
+ catch (e) {
809
+ console.error("Vasille.js: Handler throw exception: ", e);
810
+ }
811
+ });
812
+ };
813
+ /**
814
+ * Subscribe to event
815
+ * @param func {function} handler
816
+ */
817
+ Signal.prototype.subscribe = function (func) {
818
+ this.handlers.add(func);
819
+ };
820
+ /**
821
+ * Unsubscribe from event
822
+ * @param func {function} handler
823
+ */
824
+ Signal.prototype.unsubscribe = function (func) {
825
+ this.handlers.delete(func);
826
+ };
827
+ return Signal;
828
+ }());
829
+
830
+
831
+ window.Signal = Signal;
832
+
833
+ // ./lib-es5/core/slot.js
834
+ /**
835
+ * Component slot
836
+ * @class Slot
837
+ */
838
+ var Slot = /** @class */ (function () {
839
+ function Slot() {
840
+ }
841
+ /**
842
+ * Sets the runner
843
+ * @param func {function} the function to run
844
+ */
845
+ Slot.prototype.insert = function (func) {
846
+ this.runner = func;
847
+ };
848
+ /**
849
+ * @param a0 {Fragment} node to paste content
850
+ * @param a1 {*} 1st argument
851
+ * @param a2 {*} 2nd argument
852
+ * @param a3 {*} 3rd argument
853
+ * @param a4 {*} 4th argument
854
+ * @param a5 {*} 5th argument
855
+ * @param a6 {*} 6th argument
856
+ * @param a7 {*} 7th argument
857
+ * @param a8 {*} 8th argument
858
+ * @param a9 {*} 9th argument
859
+ */
860
+ Slot.prototype.release = function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
861
+ if (this.runner) {
862
+ this.runner(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
863
+ }
864
+ };
865
+ /**
866
+ * Predefine a handler for a slot
867
+ * @param func {function(node : Fragment)} Function to run if no handler specified
868
+ * @param a0 {Fragment} node to paste content
869
+ * @param a1 {*} 1st argument
870
+ * @param a2 {*} 2nd argument
871
+ * @param a3 {*} 3rd argument
872
+ * @param a4 {*} 4th argument
873
+ * @param a5 {*} 5th argument
874
+ * @param a6 {*} 6th argument
875
+ * @param a7 {*} 7th argument
876
+ * @param a8 {*} 8th argument
877
+ * @param a9 {*} 9th argument
878
+ */
879
+ Slot.prototype.predefine = function (func, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
880
+ (this.runner || func)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
881
+ };
882
+ return Slot;
883
+ }());
884
+
885
+
886
+ window.Slot = Slot;
887
+
888
+ // ./lib-es5/core/errors.js
889
+ var reportIt = "Report it here: https://gitlab.com/vasille-js/vasille-js/-/issues";
890
+ function notOverwritten() {
891
+ console.error("Vasille-SFP: Internal error", "Must be overwritten", reportIt);
892
+ return "not-overwritten";
893
+ }
894
+ function internalError(msg) {
895
+ console.error("Vasille-SFP: Internal error", msg, reportIt);
896
+ return "internal-error";
897
+ }
898
+ function userError(msg, err) {
899
+ console.error("Vasille-SFP: User error", msg);
900
+ return err;
901
+ }
902
+ function wrongBinding(msg) {
903
+ return userError(msg, "wrong-binding");
904
+ }
905
+
906
+ window.notOverwritten = notOverwritten;
907
+ window.internalError = internalError;
908
+ window.userError = userError;
909
+ window.wrongBinding = wrongBinding;
910
+
911
+ // ./lib-es5/core/executor.js
912
+ /**
913
+ * Represents an executor unit interface
914
+ * @class Executor
915
+ */
916
+ var Executor = /** @class */ (function () {
917
+ function Executor() {
918
+ }
919
+ /**
920
+ * Adds a CSS class
921
+ * @param el {Element} element to manipulate
922
+ * @param cl {string} class to be added
923
+ */
924
+ Executor.prototype.addClass = function (el, cl) {
925
+ throw notOverwritten();
926
+ };
927
+ /**
928
+ * Removes a CSS class
929
+ * @param el {Element} element to manipulate
930
+ * @param cl {string} class to be removed
931
+ */
932
+ Executor.prototype.removeClass = function (el, cl) {
933
+ throw notOverwritten();
934
+ };
935
+ /**
936
+ * Sets a tag attribute
937
+ * @param el {Element} element to manipulate
938
+ * @param name {string} name of attribute
939
+ * @param value {string} value of attribute
940
+ */
941
+ Executor.prototype.setAttribute = function (el, name, value) {
942
+ throw notOverwritten();
943
+ };
944
+ /**
945
+ * Removes a tag attribute
946
+ * @param el {Element} element to manipulate
947
+ * @param name {string} name of attribute
948
+ */
949
+ Executor.prototype.removeAttribute = function (el, name) {
950
+ throw notOverwritten();
951
+ };
952
+ /**
953
+ * Sets a style attribute
954
+ * @param el {HTMLElement} element to manipulate
955
+ * @param prop {string} property name
956
+ * @param value {string} property value
957
+ */
958
+ Executor.prototype.setStyle = function (el, prop, value) {
959
+ throw notOverwritten();
960
+ };
961
+ /**
962
+ * Inserts a child before target
963
+ * @param target {Element} target element
964
+ * @param child {Node} element to insert before
965
+ */
966
+ Executor.prototype.insertBefore = function (target, child) {
967
+ throw notOverwritten();
968
+ };
969
+ /**
970
+ * Appends a child to element
971
+ * @param el {Element} element
972
+ * @param child {Node} child to be inserted
973
+ */
974
+ Executor.prototype.appendChild = function (el, child) {
975
+ throw notOverwritten();
976
+ };
977
+ /**
978
+ * Calls a call-back function
979
+ * @param cb {function} call-back function
980
+ */
981
+ Executor.prototype.callCallback = function (cb) {
982
+ throw notOverwritten();
983
+ };
984
+ return Executor;
985
+ }());
986
+
987
+ /**
988
+ * Executor which execute any commands immediately
989
+ * @class InstantExecutor
990
+ * @extends Executor
991
+ */
992
+ var InstantExecutor = /** @class */ (function (_super) {
993
+ __extends(InstantExecutor, _super);
994
+ function InstantExecutor() {
995
+ return _super !== null && _super.apply(this, arguments) || this;
996
+ }
997
+ InstantExecutor.prototype.addClass = function (el, cl) {
998
+ el.classList.add(cl);
999
+ };
1000
+ InstantExecutor.prototype.removeClass = function (el, cl) {
1001
+ el.classList.remove(cl);
1002
+ };
1003
+ InstantExecutor.prototype.setAttribute = function (el, name, value) {
1004
+ el.setAttribute(name, value);
1005
+ };
1006
+ InstantExecutor.prototype.removeAttribute = function (el, name) {
1007
+ el.removeAttribute(name);
1008
+ };
1009
+ InstantExecutor.prototype.setStyle = function (el, prop, value) {
1010
+ el.style.setProperty(prop, value);
1011
+ };
1012
+ InstantExecutor.prototype.insertBefore = function (target, child) {
1013
+ var parent = target.parentNode;
1014
+ if (!parent) {
1015
+ throw internalError('element don\'t have a parent node');
1016
+ }
1017
+ parent.insertBefore(child, target);
1018
+ };
1019
+ InstantExecutor.prototype.appendChild = function (el, child) {
1020
+ el.appendChild(child);
1021
+ };
1022
+ InstantExecutor.prototype.callCallback = function (cb) {
1023
+ cb();
1024
+ };
1025
+ return InstantExecutor;
1026
+ }(Executor));
1027
+
1028
+ /**
1029
+ * Executor which execute any commands over timeout
1030
+ * @class TimeoutExecutor
1031
+ * @extends InstantExecutor
1032
+ */
1033
+ var TimeoutExecutor = /** @class */ (function (_super) {
1034
+ __extends(TimeoutExecutor, _super);
1035
+ function TimeoutExecutor() {
1036
+ return _super !== null && _super.apply(this, arguments) || this;
1037
+ }
1038
+ TimeoutExecutor.prototype.addClass = function (el, cl) {
1039
+ var _this = this;
1040
+ setTimeout(function () {
1041
+ _super.prototype.addClass.call(_this, el, cl);
1042
+ }, 0);
1043
+ };
1044
+ TimeoutExecutor.prototype.removeClass = function (el, cl) {
1045
+ var _this = this;
1046
+ setTimeout(function () {
1047
+ _super.prototype.removeClass.call(_this, el, cl);
1048
+ }, 0);
1049
+ };
1050
+ TimeoutExecutor.prototype.setAttribute = function (el, name, value) {
1051
+ var _this = this;
1052
+ setTimeout(function () {
1053
+ _super.prototype.setAttribute.call(_this, el, name, value);
1054
+ }, 0);
1055
+ };
1056
+ TimeoutExecutor.prototype.removeAttribute = function (el, name) {
1057
+ var _this = this;
1058
+ setTimeout(function () {
1059
+ _super.prototype.removeAttribute.call(_this, el, name);
1060
+ }, 0);
1061
+ };
1062
+ TimeoutExecutor.prototype.setStyle = function (el, prop, value) {
1063
+ var _this = this;
1064
+ setTimeout(function () {
1065
+ _super.prototype.setStyle.call(_this, el, prop, value);
1066
+ }, 0);
1067
+ };
1068
+ TimeoutExecutor.prototype.insertBefore = function (target, child) {
1069
+ var _this = this;
1070
+ setTimeout(function () {
1071
+ _super.prototype.insertBefore.call(_this, target, child);
1072
+ }, 0);
1073
+ };
1074
+ TimeoutExecutor.prototype.appendChild = function (el, child) {
1075
+ var _this = this;
1076
+ setTimeout(function () {
1077
+ _super.prototype.appendChild.call(_this, el, child);
1078
+ }, 0);
1079
+ };
1080
+ TimeoutExecutor.prototype.callCallback = function (cb) {
1081
+ setTimeout(cb, 0);
1082
+ };
1083
+ return TimeoutExecutor;
1084
+ }(InstantExecutor));
1085
+
1086
+ var instantExecutor = new InstantExecutor();
1087
+ var timeoutExecutor = new TimeoutExecutor();
1088
+
1089
+ window.Executor = Executor;
1090
+ window.InstantExecutor = InstantExecutor;
1091
+ window.TimeoutExecutor = TimeoutExecutor;
1092
+ window.instantExecutor = instantExecutor;
1093
+ window.timeoutExecutor = timeoutExecutor;
1094
+
1095
+ // ./lib-es5/core/destroyable.js
1096
+ /**
1097
+ * Mark an object which can be destroyed
1098
+ * @class Destroyable
1099
+ */
1100
+ var Destroyable = /** @class */ (function () {
1101
+ function Destroyable() {
1102
+ }
1103
+ /**
1104
+ * Make object fields non configurable
1105
+ * @protected
1106
+ */
1107
+ Destroyable.prototype.$seal = function () {
1108
+ var _this = this;
1109
+ var $ = this;
1110
+ Object.keys($).forEach(function (i) {
1111
+ // eslint-disable-next-line no-prototype-builtins
1112
+ if (_this.hasOwnProperty(i)) {
1113
+ var config = Object.getOwnPropertyDescriptor($, i);
1114
+ if (config.configurable) {
1115
+ var descriptor = void 0;
1116
+ if (config.set || config.get) {
1117
+ descriptor = {
1118
+ configurable: false,
1119
+ get: config.get,
1120
+ set: config.set,
1121
+ enumerable: config.enumerable
1122
+ };
1123
+ }
1124
+ else {
1125
+ descriptor = {
1126
+ value: $[i],
1127
+ configurable: false,
1128
+ writable: config.writable,
1129
+ enumerable: config.enumerable
1130
+ };
1131
+ }
1132
+ Object.defineProperty($, i, descriptor);
1133
+ }
1134
+ }
1135
+ });
1136
+ };
1137
+ /**
1138
+ * Garbage collector method
1139
+ */
1140
+ Destroyable.prototype.$destroy = function () {
1141
+ // nothing here
1142
+ };
1143
+ return Destroyable;
1144
+ }());
1145
+
1146
+
1147
+ window.Destroyable = Destroyable;
1148
+
1149
+ // ./lib-es5/core/ivalue.js
1150
+ /**
1151
+ * Interface which describes a value
1152
+ * @class IValue
1153
+ * @extends Destroyable
1154
+ */
1155
+ var IValue = /** @class */ (function (_super) {
1156
+ __extends(IValue, _super);
1157
+ /**
1158
+ * @param isEnabled {boolean} initial is enabled state
1159
+ */
1160
+ function IValue(isEnabled) {
1161
+ var _this = this; _super.call(this);
1162
+ _this.isEnabled = isEnabled;
1163
+ return _this;
1164
+ }
1165
+ Object.defineProperty(IValue.prototype, "$", {
1166
+ /**
1167
+ * Get the encapsulated value
1168
+ * @return {*} the encapsulated value
1169
+ */
1170
+ get: function () {
1171
+ throw notOverwritten();
1172
+ },
1173
+ /**
1174
+ * Sets the encapsulated value
1175
+ * @param value {*} value to encapsulate
1176
+ */
1177
+ set: function (value) {
1178
+ throw notOverwritten();
1179
+ },
1180
+ enumerable: false,
1181
+ configurable: true
1182
+ });
1183
+ /**
1184
+ * Add a new handler to value change
1185
+ * @param handler {function(value : *)} the handler to add
1186
+ */
1187
+ IValue.prototype.on = function (handler) {
1188
+ throw notOverwritten();
1189
+ };
1190
+ /**
1191
+ * Removes a handler of value change
1192
+ * @param handler {function(value : *)} the handler to remove
1193
+ */
1194
+ IValue.prototype.off = function (handler) {
1195
+ throw notOverwritten();
1196
+ };
1197
+ /**
1198
+ * Enable update handlers triggering
1199
+ */
1200
+ IValue.prototype.enable = function () {
1201
+ throw notOverwritten();
1202
+ };
1203
+ /**
1204
+ * disable update handlers triggering
1205
+ */
1206
+ IValue.prototype.disable = function () {
1207
+ throw notOverwritten();
1208
+ };
1209
+ return IValue;
1210
+ }(Destroyable));
1211
+
1212
+
1213
+ window.IValue = IValue;
1214
+
1215
+ // ./lib-es5/index.js
1216
+
1217
+
1218
+
1219
+ // ./lib-es5/value/expression.js
1220
+ /**
1221
+ * Bind some values to one expression
1222
+ * @class Expression
1223
+ * @extends IValue
1224
+ */
1225
+ var Expression = /** @class */ (function (_super) {
1226
+ __extends(Expression, _super);
1227
+ function Expression(func, link, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
1228
+ var _this = _super.call(this, false) || this;
1229
+ /**
1230
+ * Expression will link different handler for each value of list
1231
+ */
1232
+ _this.linkedFunc = [];
1233
+ var values = [v1, v2, v3, v4, v5, v6, v7, v8, v9].filter(function (v) { return v instanceof IValue; });
1234
+ var handler = function (i) {
1235
+ if (i != null) {
1236
+ _this.valuesCache[i] = _this.values[i].$;
1237
+ }
1238
+ _this.sync.$ = func.apply(_this, _this.valuesCache);
1239
+ };
1240
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1241
+ // @ts-ignore
1242
+ _this.valuesCache = values.map(function (iValue) { return iValue.$; });
1243
+ _this.sync = new Reference(func.apply(_this, _this.valuesCache));
1244
+ var i = 0;
1245
+ values.forEach(function () {
1246
+ _this.linkedFunc.push(handler.bind(_this, Number(i++)));
1247
+ });
1248
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1249
+ // @ts-ignore
1250
+ _this.values = values;
1251
+ _this.func = handler;
1252
+ if (link) {
1253
+ _this.enable();
1254
+ }
1255
+ else {
1256
+ handler();
1257
+ }
1258
+ _this.$seal();
1259
+ return _this;
1260
+ }
1261
+ Object.defineProperty(Expression.prototype, "$", {
1262
+ get: function () {
1263
+ return this.sync.$;
1264
+ },
1265
+ set: function (value) {
1266
+ this.sync.$ = value;
1267
+ },
1268
+ enumerable: false,
1269
+ configurable: true
1270
+ });
1271
+ Expression.prototype.on = function (handler) {
1272
+ this.sync.on(handler);
1273
+ return this;
1274
+ };
1275
+ Expression.prototype.off = function (handler) {
1276
+ this.sync.off(handler);
1277
+ return this;
1278
+ };
1279
+ Expression.prototype.enable = function () {
1280
+ if (!this.isEnabled) {
1281
+ for (var i = 0; i < this.values.length; i++) {
1282
+ this.values[i].on(this.linkedFunc[i]);
1283
+ this.valuesCache[i] = this.values[i].$;
1284
+ }
1285
+ this.func();
1286
+ this.isEnabled = true;
1287
+ }
1288
+ return this;
1289
+ };
1290
+ Expression.prototype.disable = function () {
1291
+ if (this.isEnabled) {
1292
+ for (var i = 0; i < this.values.length; i++) {
1293
+ this.values[i].off(this.linkedFunc[i]);
1294
+ }
1295
+ this.isEnabled = false;
1296
+ }
1297
+ return this;
1298
+ };
1299
+ Expression.prototype.$destroy = function () {
1300
+ this.disable();
1301
+ this.values.splice(0);
1302
+ this.valuesCache.splice(0);
1303
+ this.linkedFunc.splice(0);
1304
+ _super.prototype.$destroy.call(this);
1305
+ };
1306
+ return Expression;
1307
+ }(IValue));
1308
+
1309
+
1310
+ window.Expression = Expression;
1311
+
1312
+ // ./lib-es5/value/reference.js
1313
+ /**
1314
+ * Declares a notifiable value
1315
+ * @class Reference
1316
+ * @extends IValue
1317
+ */
1318
+ var Reference = /** @class */ (function (_super) {
1319
+ __extends(Reference, _super);
1320
+ /**
1321
+ * @param value {any} the initial value
1322
+ */
1323
+ function Reference(value) {
1324
+ var _this = _super.call(this, true) || this;
1325
+ _this.value = value;
1326
+ _this.onchange = new Set;
1327
+ _this.$seal();
1328
+ return _this;
1329
+ }
1330
+ Object.defineProperty(Reference.prototype, "$", {
1331
+ get: function () {
1332
+ return this.value;
1333
+ },
1334
+ set: function (value) {
1335
+ if (this.value !== value) {
1336
+ this.value = value;
1337
+ if (this.isEnabled) {
1338
+ this.onchange.forEach(function (handler) {
1339
+ handler(value);
1340
+ });
1341
+ }
1342
+ }
1343
+ },
1344
+ enumerable: false,
1345
+ configurable: true
1346
+ });
1347
+ Reference.prototype.enable = function () {
1348
+ var _this = this;
1349
+ if (!this.isEnabled) {
1350
+ this.onchange.forEach(function (handler) {
1351
+ handler(_this.value);
1352
+ });
1353
+ this.isEnabled = true;
1354
+ }
1355
+ return this;
1356
+ };
1357
+ Reference.prototype.disable = function () {
1358
+ this.isEnabled = false;
1359
+ return this;
1360
+ };
1361
+ Reference.prototype.on = function (handler) {
1362
+ this.onchange.add(handler);
1363
+ return this;
1364
+ };
1365
+ Reference.prototype.off = function (handler) {
1366
+ this.onchange.delete(handler);
1367
+ return this;
1368
+ };
1369
+ Reference.prototype.$destroy = function () {
1370
+ _super.prototype.$destroy.call(this);
1371
+ this.onchange.clear();
1372
+ };
1373
+ return Reference;
1374
+ }(IValue));
1375
+
1376
+
1377
+ window.Reference = Reference;
1378
+
1379
+ // ./lib-es5/value/mirror.js
1380
+ /**
1381
+ * Declares a notifiable bind to a value
1382
+ * @class Mirror
1383
+ * @extends IValue
1384
+ * @version 2
1385
+ */
1386
+ var Mirror = /** @class */ (function (_super) {
1387
+ __extends(Mirror, _super);
1388
+ /**
1389
+ * Constructs a notifiable bind to a value
1390
+ * @param value {IValue} is initial value
1391
+ * @param forwardOnly {boolean} ensure forward only synchronization
1392
+ */
1393
+ function Mirror(value, forwardOnly) {
1394
+ if (forwardOnly === void 0) { forwardOnly = false; }
1395
+ var _this = _super.call(this, value.$) || this;
1396
+ _this.handler = function (v) {
1397
+ _this.$ = v;
1398
+ };
1399
+ _this.pointedValue = value;
1400
+ _this.forwardOnly = forwardOnly;
1401
+ value.on(_this.handler);
1402
+ _this.$seal();
1403
+ return _this;
1404
+ }
1405
+ Object.defineProperty(Mirror.prototype, "$", {
1406
+ get: function () {
1407
+ // this is a ts bug
1408
+ // eslint-disable-next-line
1409
+ // @ts-ignore
1410
+ return _super.prototype.$;
1411
+ },
1412
+ set: function (v) {
1413
+ // this is a ts bug
1414
+ // eslint-disable-next-line
1415
+ // @ts-ignore
1416
+ _super.prototype.$ = v;
1417
+ if (!this.forwardOnly) {
1418
+ this.pointedValue.$ = v;
1419
+ }
1420
+ },
1421
+ enumerable: false,
1422
+ configurable: true
1423
+ });
1424
+ Mirror.prototype.enable = function () {
1425
+ if (!this.isEnabled) {
1426
+ this.isEnabled = true;
1427
+ this.pointedValue.on(this.handler);
1428
+ this.$ = this.pointedValue.$;
1429
+ }
1430
+ return this;
1431
+ };
1432
+ Mirror.prototype.disable = function () {
1433
+ if (this.isEnabled) {
1434
+ this.pointedValue.off(this.handler);
1435
+ this.isEnabled = false;
1436
+ }
1437
+ return this;
1438
+ };
1439
+ Mirror.prototype.$destroy = function () {
1440
+ this.disable();
1441
+ _super.prototype.$destroy.call(this);
1442
+ };
1443
+ return Mirror;
1444
+ }(Reference));
1445
+
1446
+
1447
+ window.Mirror = Mirror;
1448
+
1449
+ // ./lib-es5/value/pointer.js
1450
+ /**
1451
+ * r/w pointer to a value
1452
+ * @class Pointer
1453
+ * @extends Mirror
1454
+ */
1455
+ var Pointer = /** @class */ (function (_super) {
1456
+ __extends(Pointer, _super);
1457
+ /**
1458
+ * @param value {IValue} value to point
1459
+ * @param forwardOnly {boolean} forward only data flow
1460
+ */
1461
+ function Pointer(value, forwardOnly) {
1462
+ if (forwardOnly === void 0) { forwardOnly = false; }
1463
+ return _super.call(this, value, forwardOnly) || this;
1464
+ }
1465
+ /**
1466
+ * Point a new ivalue
1467
+ * @param value {IValue} value to point
1468
+ */
1469
+ Pointer.prototype.point = function (value) {
1470
+ if (this.pointedValue !== value) {
1471
+ this.disable();
1472
+ this.pointedValue = value;
1473
+ this.enable();
1474
+ }
1475
+ };
1476
+ return Pointer;
1477
+ }(Mirror));
1478
+
1479
+
1480
+ window.Pointer = Pointer;
1481
+
1482
+ // ./lib-es5/binding/binding.js
1483
+ /**
1484
+ * Describe a common binding logic
1485
+ * @class Binding
1486
+ * @extends Destroyable
1487
+ */
1488
+ var Binding = /** @class */ (function (_super) {
1489
+ __extends(Binding, _super);
1490
+ /**
1491
+ * Constructs a common binding logic
1492
+ * @param node {INode} the vasille node
1493
+ * @param name {String} the name of property/attribute/class
1494
+ * @param value {IValue} the value to bind
1495
+ */
1496
+ function Binding(node, name, value) {
1497
+ var _this = this; _super.call(this);
1498
+ _this.updateFunc = _this.bound(name).bind(null, node);
1499
+ _this.binding = value;
1500
+ _this.binding.on(_this.updateFunc);
1501
+ _this.updateFunc(_this.binding.$);
1502
+ _this.$seal();
1503
+ return _this;
1504
+ }
1505
+ /**
1506
+ * Is a virtual function to get the specific bind function
1507
+ * @param name {String} the name of attribute/property
1508
+ * @returns {Function} a function to update attribute/property value
1509
+ * @throws Always throws and must be overloaded in child class
1510
+ */
1511
+ Binding.prototype.bound = function (name) {
1512
+ throw notOverwritten();
1513
+ };
1514
+ /**
1515
+ * Just clear bindings
1516
+ */
1517
+ Binding.prototype.$destroy = function () {
1518
+ this.binding.off(this.updateFunc);
1519
+ _super.prototype.$destroy.call(this);
1520
+ };
1521
+ return Binding;
1522
+ }(Destroyable));
1523
+
1524
+
1525
+ window.Binding = Binding;
1526
+
1527
+ // ./lib-es5/core/core.js
1528
+ /**
1529
+ * Private stuff of a reactive object
1530
+ * @class ReactivePrivate
1531
+ * @extends Destroyable
1532
+ */
1533
+ var ReactivePrivate = /** @class */ (function (_super) {
1534
+ __extends(ReactivePrivate, _super);
1535
+ function ReactivePrivate() {
1536
+ var _this = this; _super.call(this);
1537
+ /**
1538
+ * A list of user-defined values
1539
+ * @type {Set}
1540
+ */
1541
+ _this.watch = new Set;
1542
+ /**
1543
+ * A list of user-defined bindings
1544
+ * @type {Set}
1545
+ */
1546
+ _this.bindings = new Set;
1547
+ /**
1548
+ * A list of user defined models
1549
+ */
1550
+ _this.models = new Set;
1551
+ /**
1552
+ * Reactivity switch state
1553
+ * @type {boolean}
1554
+ */
1555
+ _this.enabled = true;
1556
+ /**
1557
+ * The frozen state of object
1558
+ * @type {boolean}
1559
+ */
1560
+ _this.frozen = false;
1561
+ _this.$seal();
1562
+ return _this;
1563
+ }
1564
+ ReactivePrivate.prototype.$destroy = function () {
1565
+ var _a;
1566
+ this.watch.forEach(function (value) { return value.$destroy(); });
1567
+ this.watch.clear();
1568
+ this.bindings.forEach(function (binding) { return binding.$destroy(); });
1569
+ this.bindings.clear();
1570
+ (_a = this.freezeExpr) === null || _a === void 0 ? void 0 : _a.$destroy();
1571
+ _super.prototype.$destroy.call(this);
1572
+ };
1573
+ return ReactivePrivate;
1574
+ }(Destroyable));
1575
+
1576
+ /**
1577
+ * A reactive object
1578
+ * @class Reactive
1579
+ * @extends Destroyable
1580
+ */
1581
+ var Reactive = /** @class */ (function (_super) {
1582
+ __extends(Reactive, _super);
1583
+ function Reactive($) {
1584
+ var _this = this; _super.call(this);
1585
+ _this.$ = $ || new ReactivePrivate;
1586
+ return _this;
1587
+ }
1588
+ /**
1589
+ * Create a reference
1590
+ * @param value {*} value to reference
1591
+ */
1592
+ Reactive.prototype.$ref = function (value) {
1593
+ var $ = this.$;
1594
+ var ref = new Reference(value);
1595
+ $.watch.add(ref);
1596
+ return ref;
1597
+ };
1598
+ /**
1599
+ * Create a mirror
1600
+ * @param value {IValue} value to mirror
1601
+ */
1602
+ Reactive.prototype.$mirror = function (value) {
1603
+ var mirror = new Mirror(value, false);
1604
+ this.$.watch.add(mirror);
1605
+ return mirror;
1606
+ };
1607
+ /**
1608
+ * Create a forward-only mirror
1609
+ * @param value {IValue} value to mirror
1610
+ */
1611
+ Reactive.prototype.$forward = function (value) {
1612
+ var mirror = new Mirror(value, true);
1613
+ this.$.watch.add(mirror);
1614
+ return mirror;
1615
+ };
1616
+ /**
1617
+ * Creates a pointer
1618
+ * @param value {*} default value to point
1619
+ * @param forwardOnly {boolean} forward only sync
1620
+ */
1621
+ Reactive.prototype.$point = function (value, forwardOnly) {
1622
+ if (forwardOnly === void 0) { forwardOnly = false; }
1623
+ var $ = this.$;
1624
+ var ref = value instanceof IValue ? value : new Reference(value);
1625
+ var pointer = new Pointer(ref, forwardOnly);
1626
+ // when value is an ivalue will be equal to ref
1627
+ if (value !== ref) {
1628
+ $.watch.add(ref);
1629
+ }
1630
+ $.watch.add(pointer);
1631
+ return pointer;
1632
+ };
1633
+ /**
1634
+ * Register a model
1635
+ * @param model
1636
+ */
1637
+ Reactive.prototype.$register = function (model) {
1638
+ this.$.models.add(model);
1639
+ return model;
1640
+ };
1641
+ Reactive.prototype.$watch = function (func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
1642
+ var $ = this.$;
1643
+ $.watch.add(new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9));
1644
+ };
1645
+ Reactive.prototype.$bind = function (func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
1646
+ var res = new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9);
1647
+ var $ = this.$;
1648
+ $.watch.add(res);
1649
+ return res;
1650
+ };
1651
+ /**
1652
+ * Enable reactivity of fields
1653
+ */
1654
+ Reactive.prototype.$enable = function () {
1655
+ var $ = this.$;
1656
+ if (!$.enabled) {
1657
+ $.watch.forEach(function (watcher) {
1658
+ watcher.enable();
1659
+ });
1660
+ $.models.forEach(function (model) {
1661
+ model.enableReactivity();
1662
+ });
1663
+ $.enabled = true;
1664
+ }
1665
+ };
1666
+ /**
1667
+ * Disable reactivity of fields
1668
+ */
1669
+ Reactive.prototype.$disable = function () {
1670
+ var $ = this.$;
1671
+ if ($.enabled) {
1672
+ $.watch.forEach(function (watcher) {
1673
+ watcher.disable();
1674
+ });
1675
+ $.models.forEach(function (model) {
1676
+ model.disableReactivity();
1677
+ });
1678
+ $.enabled = false;
1679
+ }
1680
+ };
1681
+ /**
1682
+ * Disable/Enable reactivity of object fields with feedback
1683
+ * @param cond {IValue} show condition
1684
+ * @param onOff {function} on show feedback
1685
+ * @param onOn {function} on hide feedback
1686
+ */
1687
+ Reactive.prototype.$bindAlive = function (cond, onOff, onOn) {
1688
+ var _this = this;
1689
+ var $ = this.$;
1690
+ if ($.freezeExpr) {
1691
+ throw wrongBinding("this component already have a freeze state");
1692
+ }
1693
+ if ($.watch.has(cond)) {
1694
+ throw wrongBinding("freeze state must be bound to an external component");
1695
+ }
1696
+ $.freezeExpr = new Expression(function (cond) {
1697
+ $.frozen = !cond;
1698
+ if (cond) {
1699
+ onOn === null || onOn === void 0 ? void 0 : onOn();
1700
+ _this.$enable();
1701
+ }
1702
+ else {
1703
+ onOff === null || onOff === void 0 ? void 0 : onOff();
1704
+ _this.$disable();
1705
+ }
1706
+ }, true, cond);
1707
+ return this;
1708
+ };
1709
+ Reactive.prototype.$destroy = function () {
1710
+ _super.prototype.$destroy.call(this);
1711
+ this.$.$destroy();
1712
+ this.$ = null;
1713
+ };
1714
+ return Reactive;
1715
+ }(Destroyable));
1716
+
1717
+
1718
+ window.ReactivePrivate = ReactivePrivate;
1719
+ window.Reactive = Reactive;
1720
+
1721
+ // ./lib-es5/node/node.js
1722
+ /**
1723
+ * Represents a Vasille.js node
1724
+ * @class FragmentPrivate
1725
+ * @extends ReactivePrivate
1726
+ */
1727
+ var FragmentPrivate = /** @class */ (function (_super) {
1728
+ __extends(FragmentPrivate, _super);
1729
+ function FragmentPrivate() {
1730
+ var _this = this; _super.call(this);
1731
+ _this.$seal();
1732
+ return _this;
1733
+ }
1734
+ /**
1735
+ * Pre-initializes the base of a fragment
1736
+ * @param app {App} the app node
1737
+ * @param parent {Fragment} the parent node
1738
+ */
1739
+ FragmentPrivate.prototype.preinit = function (app, parent) {
1740
+ this.app = app;
1741
+ this.parent = parent;
1742
+ };
1743
+ /**
1744
+ * Unlinks all bindings
1745
+ */
1746
+ FragmentPrivate.prototype.$destroy = function () {
1747
+ this.next = null;
1748
+ this.prev = null;
1749
+ _super.prototype.$destroy.call(this);
1750
+ };
1751
+ return FragmentPrivate;
1752
+ }(ReactivePrivate));
1753
+
1754
+ /**
1755
+ * This class is symbolic
1756
+ * @extends Reactive
1757
+ */
1758
+ var Fragment = /** @class */ (function (_super) {
1759
+ __extends(Fragment, _super);
1760
+ /**
1761
+ * Constructs a Vasille Node
1762
+ * @param $ {FragmentPrivate}
1763
+ */
1764
+ function Fragment($) {
1765
+ var _this = this; _super.call(this);
1766
+ /**
1767
+ * The children list
1768
+ * @type Array
1769
+ */
1770
+ _this.$children = [];
1771
+ _this.$ = $ || new FragmentPrivate;
1772
+ return _this;
1773
+ }
1774
+ Object.defineProperty(Fragment.prototype, "app", {
1775
+ /**
1776
+ * Gets the app of node
1777
+ */
1778
+ get: function () {
1779
+ return this.$.app;
1780
+ },
1781
+ enumerable: false,
1782
+ configurable: true
1783
+ });
1784
+ /**
1785
+ * Prepare to init fragment
1786
+ * @param app {AppNode} app of node
1787
+ * @param parent {Fragment} parent of node
1788
+ * @param data {*} additional data
1789
+ */
1790
+ Fragment.prototype.$preinit = function (app, parent, data) {
1791
+ var $ = this.$;
1792
+ $.preinit(app, parent);
1793
+ };
1794
+ /**
1795
+ * Initialize node
1796
+ */
1797
+ Fragment.prototype.$init = function () {
1798
+ this.$createSignals();
1799
+ this.$createWatchers();
1800
+ this.$created();
1801
+ this.$compose();
1802
+ this.$mounted();
1803
+ return this;
1804
+ };
1805
+ /** To be overloaded: created event handler */
1806
+ Fragment.prototype.$created = function () {
1807
+ // empty
1808
+ };
1809
+ /** To be overloaded: mounted event handler */
1810
+ Fragment.prototype.$mounted = function () {
1811
+ // empty
1812
+ };
1813
+ /** To be overloaded: ready event handler */
1814
+ Fragment.prototype.$ready = function () {
1815
+ // empty
1816
+ };
1817
+ /** To be overloaded: signals creation milestone */
1818
+ Fragment.prototype.$createSignals = function () {
1819
+ // empty
1820
+ };
1821
+ /** To be overloaded: watchers creation milestone */
1822
+ Fragment.prototype.$createWatchers = function () {
1823
+ // empty
1824
+ };
1825
+ /** To be overloaded: DOM creation milestone */
1826
+ Fragment.prototype.$compose = function () {
1827
+ // empty
1828
+ };
1829
+ /**
1830
+ * Pushes a node to children immediately
1831
+ * @param node {Fragment} A node to push
1832
+ * @protected
1833
+ */
1834
+ Fragment.prototype.$$pushNode = function (node) {
1835
+ var lastChild = null;
1836
+ if (this.$children.length) {
1837
+ lastChild = this.$children[this.$children.length - 1];
1838
+ }
1839
+ if (lastChild) {
1840
+ lastChild.$.next = node;
1841
+ }
1842
+ node.$.prev = lastChild;
1843
+ node.$.parent = this;
1844
+ this.$children.push(node);
1845
+ };
1846
+ /**
1847
+ * Find first node in element if so exists
1848
+ * @return {?Element}
1849
+ * @protected
1850
+ */
1851
+ Fragment.prototype.$$findFirstChild = function () {
1852
+ var first;
1853
+ this.$children.forEach(function (child) {
1854
+ first = first || child.$$findFirstChild();
1855
+ });
1856
+ return first;
1857
+ };
1858
+ /**
1859
+ * Append a node to end of element
1860
+ * @param node {Node} node to insert
1861
+ */
1862
+ Fragment.prototype.$$appendNode = function (node) {
1863
+ var $ = this.$;
1864
+ if ($.next) {
1865
+ $.next.$$insertAdjacent(node);
1866
+ }
1867
+ else {
1868
+ $.parent.$$appendNode(node);
1869
+ }
1870
+ };
1871
+ /**
1872
+ * Insert a node as a sibling of this
1873
+ * @param node {Node} node to insert
1874
+ */
1875
+ Fragment.prototype.$$insertAdjacent = function (node) {
1876
+ var child = this.$$findFirstChild();
1877
+ var $ = this.$;
1878
+ if (child) {
1879
+ $.app.$run.insertBefore(child, node);
1880
+ }
1881
+ else if ($.next) {
1882
+ $.next.$$insertAdjacent(node);
1883
+ }
1884
+ else {
1885
+ $.parent.$$appendNode(node);
1886
+ }
1887
+ };
1888
+ /**
1889
+ * Defines a text fragment
1890
+ * @param text {String | IValue} A text fragment string
1891
+ * @param cb {function (TextNode)} Callback if previous is slot name
1892
+ */
1893
+ Fragment.prototype.$text = function (text, cb) {
1894
+ var $ = this.$;
1895
+ var node = new TextNode();
1896
+ var textValue = text instanceof IValue ? text : this.$ref(text);
1897
+ node.$preinit($.app, this, textValue);
1898
+ this.$$pushNode(node);
1899
+ if (cb) {
1900
+ $.app.$run.callCallback(function () {
1901
+ cb(node);
1902
+ });
1903
+ }
1904
+ return this;
1905
+ };
1906
+ Fragment.prototype.$debug = function (text) {
1907
+ if (this.$.app.$debugUi) {
1908
+ var node = new DebugNode();
1909
+ node.$preinit(this.$.app, this, text);
1910
+ this.$$pushNode(node);
1911
+ }
1912
+ return this;
1913
+ };
1914
+ Fragment.prototype.$tag = function (tagName, cb) {
1915
+ var $ = this.$;
1916
+ var node = new Tag();
1917
+ node.$preinit($.app, this, tagName);
1918
+ node.$init();
1919
+ this.$$pushNode(node);
1920
+ $.app.$run.callCallback(function () {
1921
+ if (cb) {
1922
+ cb(node, node.node);
1923
+ }
1924
+ node.$ready();
1925
+ });
1926
+ return this;
1927
+ };
1928
+ /**
1929
+ * Defines a custom element
1930
+ * @param node {Fragment} vasille element to insert
1931
+ * @param callback {function($ : *)}
1932
+ * @param callback1 {function($ : *)}
1933
+ */
1934
+ Fragment.prototype.$create = function (node, callback, callback1) {
1935
+ var $ = this.$;
1936
+ node.$.parent = this;
1937
+ node.$preinit($.app, this);
1938
+ if (callback) {
1939
+ callback(node);
1940
+ }
1941
+ if (callback1) {
1942
+ callback1(node);
1943
+ }
1944
+ this.$$pushNode(node);
1945
+ node.$init().$ready();
1946
+ return this;
1947
+ };
1948
+ /**
1949
+ * Defines an if node
1950
+ * @param cond {IValue} condition
1951
+ * @param cb {function(Fragment)} callback to run on true
1952
+ * @return {this}
1953
+ */
1954
+ Fragment.prototype.$if = function (cond, cb) {
1955
+ return this.$switch({ cond: cond, cb: cb });
1956
+ };
1957
+ /**
1958
+ * Defines a if-else node
1959
+ * @param ifCond {IValue} `if` condition
1960
+ * @param ifCb {function(Fragment)} Call-back to create `if` child nodes
1961
+ * @param elseCb {function(Fragment)} Call-back to create `else` child nodes
1962
+ */
1963
+ Fragment.prototype.$if_else = function (ifCond, ifCb, elseCb) {
1964
+ return this.$switch({ cond: ifCond, cb: ifCb }, { cond: trueIValue, cb: elseCb });
1965
+ };
1966
+ /**
1967
+ * Defines a switch nodes: Will break after first true condition
1968
+ * @param cases {...{ cond : IValue, cb : function(Fragment) }} cases
1969
+ * @return {INode}
1970
+ */
1971
+ Fragment.prototype.$switch = function () {
1972
+ var cases = [];
1973
+ for (var _i = 0; _i < arguments.length; _i++) {
1974
+ cases[_i] = arguments[_i];
1975
+ }
1976
+ var $ = this.$;
1977
+ var node = new SwitchedNode();
1978
+ node.$preinit($.app, this);
1979
+ node.$init();
1980
+ this.$$pushNode(node);
1981
+ node.setCases(cases);
1982
+ node.$ready();
1983
+ return this;
1984
+ };
1985
+ /**
1986
+ * Create a case for switch
1987
+ * @param cond {IValue<boolean>}
1988
+ * @param cb {function(Fragment) : void}
1989
+ * @return {{cond : IValue, cb : (function(Fragment) : void)}}
1990
+ */
1991
+ Fragment.prototype.$case = function (cond, cb) {
1992
+ return { cond: cond, cb: cb };
1993
+ };
1994
+ /**
1995
+ * @param cb {(function(Fragment) : void)}
1996
+ * @return {{cond : IValue, cb : (function(Fragment) : void)}}
1997
+ */
1998
+ Fragment.prototype.$default = function (cb) {
1999
+ return { cond: trueIValue, cb: cb };
2000
+ };
2001
+ Fragment.prototype.$destroy = function () {
2002
+ for (var _i = 0, _a = this.$children; _i < _a.length; _i++) {
2003
+ var child = _a[_i];
2004
+ child.$destroy();
2005
+ }
2006
+ this.$children.splice(0);
2007
+ _super.prototype.$destroy.call(this);
2008
+ };
2009
+ return Fragment;
2010
+ }(Reactive));
2011
+
2012
+ var trueIValue = new Reference(true);
2013
+ /**
2014
+ * The private part of a text node
2015
+ * @class TextNodePrivate
2016
+ * @extends FragmentPrivate
2017
+ */
2018
+ var TextNodePrivate = /** @class */ (function (_super) {
2019
+ __extends(TextNodePrivate, _super);
2020
+ function TextNodePrivate() {
2021
+ var _this = this; _super.call(this);
2022
+ _this.$seal();
2023
+ return _this;
2024
+ }
2025
+ /**
2026
+ * Pre-initializes a text node
2027
+ * @param app {AppNode} the app node
2028
+ * @param text {IValue}
2029
+ */
2030
+ TextNodePrivate.prototype.preinitText = function (app, parent, text) {
2031
+ var _this = this;
2032
+ _super.prototype.preinit.call(this, app, parent);
2033
+ this.node = document.createTextNode(text.$);
2034
+ this.bindings.add(new Expression(function (v) {
2035
+ _this.node.replaceData(0, -1, v);
2036
+ }, true, text));
2037
+ this.parent.$$appendNode(this.node);
2038
+ };
2039
+ /**
2040
+ * Clear node data
2041
+ */
2042
+ TextNodePrivate.prototype.$destroy = function () {
2043
+ _super.prototype.$destroy.call(this);
2044
+ };
2045
+ return TextNodePrivate;
2046
+ }(FragmentPrivate));
2047
+
2048
+ /**
2049
+ * Represents a text node
2050
+ * @class TextNode
2051
+ * @extends Fragment
2052
+ */
2053
+ var TextNode = /** @class */ (function (_super) {
2054
+ __extends(TextNode, _super);
2055
+ function TextNode() {
2056
+ var _this = this; _super.call(this);
2057
+ _this.$ = new TextNodePrivate();
2058
+ _this.$seal();
2059
+ return _this;
2060
+ }
2061
+ TextNode.prototype.$preinit = function (app, parent, text) {
2062
+ var $ = this.$;
2063
+ if (!text) {
2064
+ throw internalError('wrong TextNode::$preninit call');
2065
+ }
2066
+ $.preinitText(app, parent, text);
2067
+ };
2068
+ TextNode.prototype.$$findFirstChild = function () {
2069
+ return this.$.node;
2070
+ };
2071
+ TextNode.prototype.$destroy = function () {
2072
+ this.$.node.remove();
2073
+ this.$.$destroy();
2074
+ _super.prototype.$destroy.call(this);
2075
+ };
2076
+ return TextNode;
2077
+ }(Fragment));
2078
+
2079
+ /**
2080
+ * The private part of a base node
2081
+ * @class INodePrivate
2082
+ * @extends FragmentPrivate
2083
+ */
2084
+ var INodePrivate = /** @class */ (function (_super) {
2085
+ __extends(INodePrivate, _super);
2086
+ function INodePrivate() {
2087
+ var _this = this; _super.call(this);
2088
+ /**
2089
+ * Defines if node is unmounted
2090
+ * @type {boolean}
2091
+ */
2092
+ _this.unmounted = false;
2093
+ _this.$seal();
2094
+ return _this;
2095
+ }
2096
+ INodePrivate.prototype.$destroy = function () {
2097
+ _super.prototype.$destroy.call(this);
2098
+ };
2099
+ return INodePrivate;
2100
+ }(FragmentPrivate));
2101
+
2102
+ /**
2103
+ * Vasille node which can manipulate an element node
2104
+ * @class INode
2105
+ * @extends Fragment
2106
+ */
2107
+ var INode = /** @class */ (function (_super) {
2108
+ __extends(INode, _super);
2109
+ /**
2110
+ * Constructs a base node
2111
+ * @param $ {?INodePrivate}
2112
+ */
2113
+ function INode($) {
2114
+ var _this = _super.call(this, $ || new INodePrivate) || this;
2115
+ _this.$seal();
2116
+ return _this;
2117
+ }
2118
+ Object.defineProperty(INode.prototype, "node", {
2119
+ /**
2120
+ * Get the bound node
2121
+ */
2122
+ get: function () {
2123
+ return this.$.node;
2124
+ },
2125
+ enumerable: false,
2126
+ configurable: true
2127
+ });
2128
+ /**
2129
+ * Initialize node
2130
+ */
2131
+ INode.prototype.$init = function () {
2132
+ this.$createSignals();
2133
+ this.$createWatchers();
2134
+ this.$createAttrs();
2135
+ this.$createStyle();
2136
+ this.$created();
2137
+ this.$compose();
2138
+ this.$mounted();
2139
+ return this;
2140
+ };
2141
+ /** To be overloaded: attributes creation milestone */
2142
+ INode.prototype.$createAttrs = function () {
2143
+ // empty
2144
+ };
2145
+ /** To be overloaded: $style attributes creation milestone */
2146
+ INode.prototype.$createStyle = function () {
2147
+ // empty
2148
+ };
2149
+ /**
2150
+ * Bind attribute value
2151
+ * @param name {String} name of attribute
2152
+ * @param value {IValue} value
2153
+ */
2154
+ INode.prototype.$attr = function (name, value) {
2155
+ var $ = this.$;
2156
+ var attr = new AttributeBinding(this, name, value);
2157
+ $.bindings.add(attr);
2158
+ return this;
2159
+ };
2160
+ INode.prototype.$bindAttr = function (name, calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
2161
+ var $ = this.$;
2162
+ var expr = this.$bind(calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9);
2163
+ $.bindings.add(new AttributeBinding(this, name, expr));
2164
+ return this;
2165
+ };
2166
+ /**
2167
+ * Set attribute value
2168
+ * @param name {string} name of attribute
2169
+ * @param value {string} value
2170
+ */
2171
+ INode.prototype.$setAttr = function (name, value) {
2172
+ this.$.app.$run.setAttribute(this.$.node, name, value);
2173
+ return this;
2174
+ };
2175
+ /**
2176
+ * Adds a CSS class
2177
+ * @param cl {string} Class name
2178
+ */
2179
+ INode.prototype.$addClass = function (cl) {
2180
+ this.$.app.$run.addClass(this.$.node, cl);
2181
+ return this;
2182
+ };
2183
+ /**
2184
+ * Adds some CSS classes
2185
+ * @param cls {...string} classes names
2186
+ */
2187
+ INode.prototype.$addClasses = function () {
2188
+ var _this = this;
2189
+ var cls = [];
2190
+ for (var _i = 0; _i < arguments.length; _i++) {
2191
+ cls[_i] = arguments[_i];
2192
+ }
2193
+ cls.forEach(function (cl) {
2194
+ _this.$.app.$run.addClass(_this.$.node, cl);
2195
+ });
2196
+ return this;
2197
+ };
2198
+ /**
2199
+ * Bind a CSS class
2200
+ * @param className {IValue}
2201
+ */
2202
+ INode.prototype.$bindClass = function (className) {
2203
+ var $ = this.$;
2204
+ $.bindings.add(new ClassBinding(this, "", className));
2205
+ return this;
2206
+ };
2207
+ /**
2208
+ * Bind a floating class name
2209
+ * @param cond {IValue} condition
2210
+ * @param className {string} class name
2211
+ */
2212
+ INode.prototype.$floatingClass = function (cond, className) {
2213
+ this.$.bindings.add(new ClassBinding(this, className, cond));
2214
+ return this;
2215
+ };
2216
+ /**
2217
+ * Defines a style attribute
2218
+ * @param name {String} name of style attribute
2219
+ * @param value {IValue} value
2220
+ */
2221
+ INode.prototype.$style = function (name, value) {
2222
+ var $ = this.$;
2223
+ if ($.node instanceof HTMLElement) {
2224
+ $.bindings.add(new StyleBinding(this, name, value));
2225
+ }
2226
+ else {
2227
+ throw userError('style can be applied to HTML elements only', 'non-html-element');
2228
+ }
2229
+ return this;
2230
+ };
2231
+ INode.prototype.$bindStyle = function (name, calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
2232
+ var $ = this.$;
2233
+ var expr = this.$bind(calculator, v1, v2, v3, v4, v5, v6, v7, v8, v9);
2234
+ if ($.node instanceof HTMLElement) {
2235
+ $.bindings.add(new StyleBinding(this, name, expr));
2236
+ }
2237
+ else {
2238
+ throw userError('style can be applied to HTML elements only', 'non-html-element');
2239
+ }
2240
+ return this;
2241
+ };
2242
+ /**
2243
+ * Sets a style property value
2244
+ * @param prop {string} Property name
2245
+ * @param value {string} Property value
2246
+ */
2247
+ INode.prototype.$setStyle = function (prop, value) {
2248
+ if (this.$.node instanceof HTMLElement) {
2249
+ this.$.app.$run.setStyle(this.$.node, prop, value);
2250
+ }
2251
+ else {
2252
+ throw userError("Style can be setted for HTML elements only", "non-html-element");
2253
+ }
2254
+ return this;
2255
+ };
2256
+ /**
2257
+ * Add a listener for an event
2258
+ * @param name {string} Event name
2259
+ * @param handler {function (Event)} Event handler
2260
+ * @param options {Object | boolean} addEventListener options
2261
+ */
2262
+ INode.prototype.$listen = function (name, handler, options) {
2263
+ this.$.node.addEventListener(name, handler, options);
2264
+ return this;
2265
+ };
2266
+ /**
2267
+ * @param handler {function (MouseEvent)}
2268
+ * @param options {Object | boolean}
2269
+ */
2270
+ INode.prototype.$oncontextmenu = function (handler, options) {
2271
+ return this.$listen("contextmenu", handler, options);
2272
+ };
2273
+ /**
2274
+ * @param handler {function (MouseEvent)}
2275
+ * @param options {Object | boolean}
2276
+ */
2277
+ INode.prototype.$onmousedown = function (handler, options) {
2278
+ return this.$listen("mousedown", handler, options);
2279
+ };
2280
+ /**
2281
+ * @param handler {function (MouseEvent)}
2282
+ * @param options {Object | boolean}
2283
+ */
2284
+ INode.prototype.$onmouseenter = function (handler, options) {
2285
+ return this.$listen("mouseenter", handler, options);
2286
+ };
2287
+ /**
2288
+ * @param handler {function (MouseEvent)}
2289
+ * @param options {Object | boolean}
2290
+ */
2291
+ INode.prototype.$onmouseleave = function (handler, options) {
2292
+ return this.$listen("mouseleave", handler, options);
2293
+ };
2294
+ /**
2295
+ * @param handler {function (MouseEvent)}
2296
+ * @param options {Object | boolean}
2297
+ */
2298
+ INode.prototype.$onmousemove = function (handler, options) {
2299
+ return this.$listen("mousemove", handler, options);
2300
+ };
2301
+ /**
2302
+ * @param handler {function (MouseEvent)}
2303
+ * @param options {Object | boolean}
2304
+ */
2305
+ INode.prototype.$onmouseout = function (handler, options) {
2306
+ return this.$listen("mouseout", handler, options);
2307
+ };
2308
+ /**
2309
+ * @param handler {function (MouseEvent)}
2310
+ * @param options {Object | boolean}
2311
+ */
2312
+ INode.prototype.$onmouseover = function (handler, options) {
2313
+ return this.$listen("mouseover", handler, options);
2314
+ };
2315
+ /**
2316
+ * @param handler {function (MouseEvent)}
2317
+ * @param options {Object | boolean}
2318
+ */
2319
+ INode.prototype.$onmouseup = function (handler, options) {
2320
+ return this.$listen("mouseup", handler, options);
2321
+ };
2322
+ /**
2323
+ * @param handler {function (MouseEvent)}
2324
+ * @param options {Object | boolean}
2325
+ */
2326
+ INode.prototype.$onclick = function (handler, options) {
2327
+ return this.$listen("click", handler, options);
2328
+ };
2329
+ /**
2330
+ * @param handler {function (MouseEvent)}
2331
+ * @param options {Object | boolean}
2332
+ */
2333
+ INode.prototype.$ondblclick = function (handler, options) {
2334
+ return this.$listen("dblclick", handler, options);
2335
+ };
2336
+ /**
2337
+ * @param handler {function (FocusEvent)}
2338
+ * @param options {Object | boolean}
2339
+ */
2340
+ INode.prototype.$onblur = function (handler, options) {
2341
+ return this.$listen("blur", handler, options);
2342
+ };
2343
+ /**
2344
+ * @param handler {function (FocusEvent)}
2345
+ * @param options {Object | boolean}
2346
+ */
2347
+ INode.prototype.$onfocus = function (handler, options) {
2348
+ return this.$listen("focus", handler, options);
2349
+ };
2350
+ /**
2351
+ * @param handler {function (FocusEvent)}
2352
+ * @param options {Object | boolean}
2353
+ */
2354
+ INode.prototype.$onfocusin = function (handler, options) {
2355
+ return this.$listen("focusin", handler, options);
2356
+ };
2357
+ /**
2358
+ * @param handler {function (FocusEvent)}
2359
+ * @param options {Object | boolean}
2360
+ */
2361
+ INode.prototype.$onfocusout = function (handler, options) {
2362
+ return this.$listen("focusout", handler, options);
2363
+ };
2364
+ /**
2365
+ * @param handler {function (KeyboardEvent)}
2366
+ * @param options {Object | boolean}
2367
+ */
2368
+ INode.prototype.$onkeydown = function (handler, options) {
2369
+ return this.$listen("keydown", handler, options);
2370
+ };
2371
+ /**
2372
+ * @param handler {function (KeyboardEvent)}
2373
+ * @param options {Object | boolean}
2374
+ */
2375
+ INode.prototype.$onkeyup = function (handler, options) {
2376
+ return this.$listen("keyup", handler, options);
2377
+ };
2378
+ /**
2379
+ * @param handler {function (KeyboardEvent)}
2380
+ * @param options {Object | boolean}
2381
+ */
2382
+ INode.prototype.$onkeypress = function (handler, options) {
2383
+ return this.$listen("keypress", handler, options);
2384
+ };
2385
+ /**
2386
+ * @param handler {function (TouchEvent)}
2387
+ * @param options {Object | boolean}
2388
+ */
2389
+ INode.prototype.$ontouchstart = function (handler, options) {
2390
+ return this.$listen("touchstart", handler, options);
2391
+ };
2392
+ /**
2393
+ * @param handler {function (TouchEvent)}
2394
+ * @param options {Object | boolean}
2395
+ */
2396
+ INode.prototype.$ontouchmove = function (handler, options) {
2397
+ return this.$listen("touchmove", handler, options);
2398
+ };
2399
+ /**
2400
+ * @param handler {function (TouchEvent)}
2401
+ * @param options {Object | boolean}
2402
+ */
2403
+ INode.prototype.$ontouchend = function (handler, options) {
2404
+ return this.$listen("touchend", handler, options);
2405
+ };
2406
+ /**
2407
+ * @param handler {function (TouchEvent)}
2408
+ * @param options {Object | boolean}
2409
+ */
2410
+ INode.prototype.$ontouchcancel = function (handler, options) {
2411
+ return this.$listen("touchcancel", handler, options);
2412
+ };
2413
+ /**
2414
+ * @param handler {function (WheelEvent)}
2415
+ * @param options {Object | boolean}
2416
+ */
2417
+ INode.prototype.$onwheel = function (handler, options) {
2418
+ return this.$listen("wheel", handler, options);
2419
+ };
2420
+ /**
2421
+ * @param handler {function (ProgressEvent)}
2422
+ * @param options {Object | boolean}
2423
+ */
2424
+ INode.prototype.$onabort = function (handler, options) {
2425
+ return this.$listen("abort", handler, options);
2426
+ };
2427
+ /**
2428
+ * @param handler {function (ProgressEvent)}
2429
+ * @param options {Object | boolean}
2430
+ */
2431
+ INode.prototype.$onerror = function (handler, options) {
2432
+ return this.$listen("error", handler, options);
2433
+ };
2434
+ /**
2435
+ * @param handler {function (ProgressEvent)}
2436
+ * @param options {Object | boolean}
2437
+ */
2438
+ INode.prototype.$onload = function (handler, options) {
2439
+ return this.$listen("load", handler, options);
2440
+ };
2441
+ /**
2442
+ * @param handler {function (ProgressEvent)}
2443
+ * @param options {Object | boolean}
2444
+ */
2445
+ INode.prototype.$onloadend = function (handler, options) {
2446
+ return this.$listen("loadend", handler, options);
2447
+ };
2448
+ /**
2449
+ * @param handler {function (ProgressEvent)}
2450
+ * @param options {Object | boolean}
2451
+ */
2452
+ INode.prototype.$onloadstart = function (handler, options) {
2453
+ return this.$listen("loadstart", handler, options);
2454
+ };
2455
+ /**
2456
+ * @param handler {function (ProgressEvent)}
2457
+ * @param options {Object | boolean}
2458
+ */
2459
+ INode.prototype.$onprogress = function (handler, options) {
2460
+ return this.$listen("progress", handler, options);
2461
+ };
2462
+ /**
2463
+ * @param handler {function (ProgressEvent)}
2464
+ * @param options {Object | boolean}
2465
+ */
2466
+ INode.prototype.$ontimeout = function (handler, options) {
2467
+ return this.$listen("timeout", handler, options);
2468
+ };
2469
+ /**
2470
+ * @param handler {function (DragEvent)}
2471
+ * @param options {Object | boolean}
2472
+ */
2473
+ INode.prototype.$ondrag = function (handler, options) {
2474
+ return this.$listen("drag", handler, options);
2475
+ };
2476
+ /**
2477
+ * @param handler {function (DragEvent)}
2478
+ * @param options {Object | boolean}
2479
+ */
2480
+ INode.prototype.$ondragend = function (handler, options) {
2481
+ return this.$listen("dragend", handler, options);
2482
+ };
2483
+ /**
2484
+ * @param handler {function (DragEvent)}
2485
+ * @param options {Object | boolean}
2486
+ */
2487
+ INode.prototype.$ondragenter = function (handler, options) {
2488
+ return this.$listen("dragenter", handler, options);
2489
+ };
2490
+ /**
2491
+ * @param handler {function (DragEvent)}
2492
+ * @param options {Object | boolean}
2493
+ */
2494
+ INode.prototype.$ondragexit = function (handler, options) {
2495
+ return this.$listen("dragexit", handler, options);
2496
+ };
2497
+ /**
2498
+ * @param handler {function (DragEvent)}
2499
+ * @param options {Object | boolean}
2500
+ */
2501
+ INode.prototype.$ondragleave = function (handler, options) {
2502
+ return this.$listen("dragleave", handler, options);
2503
+ };
2504
+ /**
2505
+ * @param handler {function (DragEvent)}
2506
+ * @param options {Object | boolean}
2507
+ */
2508
+ INode.prototype.$ondragover = function (handler, options) {
2509
+ return this.$listen("dragover", handler, options);
2510
+ };
2511
+ /**
2512
+ * @param handler {function (DragEvent)}
2513
+ * @param options {Object | boolean}
2514
+ */
2515
+ INode.prototype.$ondragstart = function (handler, options) {
2516
+ return this.$listen("dragstart", handler, options);
2517
+ };
2518
+ /**
2519
+ * @param handler {function (DragEvent)}
2520
+ * @param options {Object | boolean}
2521
+ */
2522
+ INode.prototype.$ondrop = function (handler, options) {
2523
+ return this.$listen("drop", handler, options);
2524
+ };
2525
+ /**
2526
+ * @param handler {function (PointerEvent)}
2527
+ * @param options {Object | boolean}
2528
+ */
2529
+ INode.prototype.$onpointerover = function (handler, options) {
2530
+ return this.$listen("pointerover", handler, options);
2531
+ };
2532
+ /**
2533
+ * @param handler {function (PointerEvent)}
2534
+ * @param options {Object | boolean}
2535
+ */
2536
+ INode.prototype.$onpointerenter = function (handler, options) {
2537
+ return this.$listen("pointerenter", handler, options);
2538
+ };
2539
+ /**
2540
+ * @param handler {function (PointerEvent)}
2541
+ * @param options {Object | boolean}
2542
+ */
2543
+ INode.prototype.$onpointerdown = function (handler, options) {
2544
+ return this.$listen("pointerdown", handler, options);
2545
+ };
2546
+ /**
2547
+ * @param handler {function (PointerEvent)}
2548
+ * @param options {Object | boolean}
2549
+ */
2550
+ INode.prototype.$onpointermove = function (handler, options) {
2551
+ return this.$listen("pointermove", handler, options);
2552
+ };
2553
+ /**
2554
+ * @param handler {function (PointerEvent)}
2555
+ * @param options {Object | boolean}
2556
+ */
2557
+ INode.prototype.$onpointerup = function (handler, options) {
2558
+ return this.$listen("pointerup", handler, options);
2559
+ };
2560
+ /**
2561
+ * @param handler {function (PointerEvent)}
2562
+ * @param options {Object | boolean}
2563
+ */
2564
+ INode.prototype.$onpointercancel = function (handler, options) {
2565
+ return this.$listen("pointercancel", handler, options);
2566
+ };
2567
+ /**
2568
+ * @param handler {function (PointerEvent)}
2569
+ * @param options {Object | boolean}
2570
+ */
2571
+ INode.prototype.$onpointerout = function (handler, options) {
2572
+ return this.$listen("pointerout", handler, options);
2573
+ };
2574
+ /**
2575
+ * @param handler {function (PointerEvent)}
2576
+ * @param options {Object | boolean}
2577
+ */
2578
+ INode.prototype.$onpointerleave = function (handler, options) {
2579
+ return this.$listen("pointerleave", handler, options);
2580
+ };
2581
+ /**
2582
+ * @param handler {function (PointerEvent)}
2583
+ * @param options {Object | boolean}
2584
+ */
2585
+ INode.prototype.$ongotpointercapture = function (handler, options) {
2586
+ return this.$listen("gotpointercapture", handler, options);
2587
+ };
2588
+ /**
2589
+ * @param handler {function (PointerEvent)}
2590
+ * @param options {Object | boolean}
2591
+ */
2592
+ INode.prototype.$onlostpointercapture = function (handler, options) {
2593
+ return this.$listen("lostpointercapture", handler, options);
2594
+ };
2595
+ /**
2596
+ * @param handler {function (AnimationEvent)}
2597
+ * @param options {Object | boolean}
2598
+ */
2599
+ INode.prototype.$onanimationstart = function (handler, options) {
2600
+ return this.$listen("animationstart", handler, options);
2601
+ };
2602
+ /**
2603
+ * @param handler {function (AnimationEvent)}
2604
+ * @param options {Object | boolean}
2605
+ */
2606
+ INode.prototype.$onanimationend = function (handler, options) {
2607
+ return this.$listen("animationend", handler, options);
2608
+ };
2609
+ /**
2610
+ * @param handler {function (AnimationEvent)}
2611
+ * @param options {Object | boolean}
2612
+ */
2613
+ INode.prototype.$onanimationiteraton = function (handler, options) {
2614
+ return this.$listen("animationiteration", handler, options);
2615
+ };
2616
+ /**
2617
+ * @param handler {function (ClipboardEvent)}
2618
+ * @param options {Object | boolean}
2619
+ */
2620
+ INode.prototype.$onclipboardchange = function (handler, options) {
2621
+ return this.$listen("clipboardchange", handler, options);
2622
+ };
2623
+ /**
2624
+ * @param handler {function (ClipboardEvent)}
2625
+ * @param options {Object | boolean}
2626
+ */
2627
+ INode.prototype.$oncut = function (handler, options) {
2628
+ return this.$listen("cut", handler, options);
2629
+ };
2630
+ /**
2631
+ * @param handler {function (ClipboardEvent)}
2632
+ * @param options {Object | boolean}
2633
+ */
2634
+ INode.prototype.$oncopy = function (handler, options) {
2635
+ return this.$listen("copy", handler, options);
2636
+ };
2637
+ /**
2638
+ * @param handler {function (ClipboardEvent)}
2639
+ * @param options {Object | boolean}
2640
+ */
2641
+ INode.prototype.$onpaste = function (handler, options) {
2642
+ return this.$listen("paste", handler, options);
2643
+ };
2644
+ INode.prototype.$$insertAdjacent = function (node) {
2645
+ var $ = this.$;
2646
+ $.app.$run.insertBefore($.node, node);
2647
+ };
2648
+ /**
2649
+ * A v-show & ngShow alternative
2650
+ * @param cond {IValue} show condition
2651
+ */
2652
+ INode.prototype.$bindShow = function (cond) {
2653
+ var $ = this.$;
2654
+ var node = $.node;
2655
+ if (node instanceof HTMLElement) {
2656
+ var lastDisplay_1 = node.style.display;
2657
+ var htmlNode_1 = node;
2658
+ return this.$bindAlive(cond, function () {
2659
+ lastDisplay_1 = htmlNode_1.style.display;
2660
+ htmlNode_1.style.display = 'none';
2661
+ }, function () {
2662
+ htmlNode_1.style.display = lastDisplay_1;
2663
+ });
2664
+ }
2665
+ else {
2666
+ throw userError('the element must be a html element', 'bind-show');
2667
+ }
2668
+ };
2669
+ /**
2670
+ * bind HTML
2671
+ * @param value {IValue}
2672
+ */
2673
+ INode.prototype.$html = function (value) {
2674
+ var $ = this.$;
2675
+ var node = $.node;
2676
+ if (node instanceof HTMLElement) {
2677
+ node.innerHTML = value.$;
2678
+ this.$watch(function (v) {
2679
+ node.innerHTML = v;
2680
+ }, value);
2681
+ }
2682
+ else {
2683
+ throw userError("HTML can be bound for HTML nodes only", "dom-error");
2684
+ }
2685
+ };
2686
+ return INode;
2687
+ }(Fragment));
2688
+
2689
+ /**
2690
+ * Represents an Vasille.js HTML element node
2691
+ * @class Tag
2692
+ * @extends INode
2693
+ */
2694
+ var Tag = /** @class */ (function (_super) {
2695
+ __extends(Tag, _super);
2696
+ function Tag() {
2697
+ var _this = this; _super.call(this);
2698
+ _this.$seal();
2699
+ return _this;
2700
+ }
2701
+ Tag.prototype.$preinit = function (app, parent, tagName) {
2702
+ if (!tagName || typeof tagName !== "string") {
2703
+ throw internalError('wrong Tag::$preinit call');
2704
+ }
2705
+ var node = document.createElement(tagName);
2706
+ var $ = this.$;
2707
+ $.preinit(app, parent);
2708
+ $.node = node;
2709
+ $.parent.$$appendNode(node);
2710
+ };
2711
+ Tag.prototype.$$findFirstChild = function () {
2712
+ return this.$.unmounted ? null : this.$.node;
2713
+ };
2714
+ Tag.prototype.$$insertAdjacent = function (node) {
2715
+ if (this.$.unmounted) {
2716
+ if (this.$.next) {
2717
+ this.$.next.$$insertAdjacent(node);
2718
+ }
2719
+ else {
2720
+ this.$.parent.$$appendNode(node);
2721
+ }
2722
+ }
2723
+ else {
2724
+ _super.prototype.$$insertAdjacent.call(this, node);
2725
+ }
2726
+ };
2727
+ Tag.prototype.$$appendNode = function (node) {
2728
+ var $ = this.$;
2729
+ $.app.$run.appendChild($.node, node);
2730
+ };
2731
+ /**
2732
+ * Mount/Unmount a node
2733
+ * @param cond {IValue} show condition
2734
+ */
2735
+ Tag.prototype.$bindMount = function (cond) {
2736
+ var $ = this.$;
2737
+ return this.$bindAlive(cond, function () {
2738
+ $.node.remove();
2739
+ $.unmounted = true;
2740
+ }, function () {
2741
+ if (!$.unmounted)
2742
+ return;
2743
+ if ($.next) {
2744
+ $.next.$$insertAdjacent($.node);
2745
+ }
2746
+ else {
2747
+ $.parent.$$appendNode($.node);
2748
+ }
2749
+ $.unmounted = false;
2750
+ });
2751
+ };
2752
+ /**
2753
+ * Runs GC
2754
+ */
2755
+ Tag.prototype.$destroy = function () {
2756
+ this.node.remove();
2757
+ _super.prototype.$destroy.call(this);
2758
+ };
2759
+ return Tag;
2760
+ }(INode));
2761
+
2762
+ /**
2763
+ * Represents a vasille extension node
2764
+ * @class Extension
2765
+ * @extends INode
2766
+ */
2767
+ var Extension = /** @class */ (function (_super) {
2768
+ __extends(Extension, _super);
2769
+ function Extension($) {
2770
+ var _this = _super.call(this, $) || this;
2771
+ _this.$seal();
2772
+ return _this;
2773
+ }
2774
+ Extension.prototype.$preinit = function (app, parent) {
2775
+ if (parent instanceof INode) {
2776
+ var $ = this.$;
2777
+ $.preinit(app, parent);
2778
+ $.node = parent.node;
2779
+ }
2780
+ else {
2781
+ throw internalError("A extension node can be encapsulated only in a tag/extension/component");
2782
+ }
2783
+ };
2784
+ Extension.prototype.$destroy = function () {
2785
+ _super.prototype.$destroy.call(this);
2786
+ };
2787
+ return Extension;
2788
+ }(INode));
2789
+
2790
+ /**
2791
+ * Node which cas has just a child
2792
+ * @class Component
2793
+ * @extends Extension
2794
+ */
2795
+ var Component = /** @class */ (function (_super) {
2796
+ __extends(Component, _super);
2797
+ function Component() {
2798
+ var _this = this; _super.call(this);
2799
+ _this.$seal();
2800
+ return _this;
2801
+ }
2802
+ Component.prototype.$mounted = function () {
2803
+ _super.prototype.$mounted.call(this);
2804
+ if (this.$children.length !== 1) {
2805
+ throw userError("UserNode must have a child only", "dom-error");
2806
+ }
2807
+ var child = this.$children[0];
2808
+ if (child instanceof Tag || child instanceof Component) {
2809
+ var $ = this.$;
2810
+ $.node = child.node;
2811
+ }
2812
+ else {
2813
+ throw userError("UserNode child must be Tag or Component", "dom-error");
2814
+ }
2815
+ };
2816
+ return Component;
2817
+ }(Extension));
2818
+
2819
+ /**
2820
+ * Private part of switch node
2821
+ * @class SwitchedNodePrivate
2822
+ * @extends INodePrivate
2823
+ */
2824
+ var SwitchedNodePrivate = /** @class */ (function (_super) {
2825
+ __extends(SwitchedNodePrivate, _super);
2826
+ function SwitchedNodePrivate() {
2827
+ var _this = this; _super.call(this);
2828
+ _this.$seal();
2829
+ return _this;
2830
+ }
2831
+ /**
2832
+ * Runs GC
2833
+ */
2834
+ SwitchedNodePrivate.prototype.$destroy = function () {
2835
+ this.cases.forEach(function (c) {
2836
+ delete c.cond;
2837
+ delete c.cb;
2838
+ });
2839
+ this.cases.splice(0);
2840
+ _super.prototype.$destroy.call(this);
2841
+ };
2842
+ return SwitchedNodePrivate;
2843
+ }(INodePrivate));
2844
+
2845
+ /**
2846
+ * Defines a node witch can switch its children conditionally
2847
+ */
2848
+ var SwitchedNode = /** @class */ (function (_super) {
2849
+ __extends(SwitchedNode, _super);
2850
+ /**
2851
+ * Constructs a switch node and define a sync function
2852
+ */
2853
+ function SwitchedNode() {
2854
+ var _this = _super.call(this, new SwitchedNodePrivate) || this;
2855
+ _this.$.sync = function () {
2856
+ var $ = _this.$;
2857
+ var i = 0;
2858
+ for (; i < $.cases.length; i++) {
2859
+ if ($.cases[i].cond.$) {
2860
+ break;
2861
+ }
2862
+ }
2863
+ if (i === $.index) {
2864
+ return;
2865
+ }
2866
+ if ($.fragment) {
2867
+ $.fragment.$destroy();
2868
+ _this.$children.splice(0);
2869
+ $.fragment = null;
2870
+ }
2871
+ if (i !== $.cases.length) {
2872
+ $.index = i;
2873
+ _this.createChild($.cases[i].cb);
2874
+ }
2875
+ else {
2876
+ $.index = -1;
2877
+ }
2878
+ };
2879
+ _this.$seal();
2880
+ return _this;
2881
+ }
2882
+ /**
2883
+ * Set up switch cases
2884
+ * @param cases {{ cond : IValue, cb : function(Fragment) }}
2885
+ */
2886
+ SwitchedNode.prototype.setCases = function (cases) {
2887
+ var $ = this.$;
2888
+ $.cases = __spreadArray([], cases, true);
2889
+ };
2890
+ /**
2891
+ * Creates a child node
2892
+ * @param cb {function(Fragment)} Call-back
2893
+ */
2894
+ SwitchedNode.prototype.createChild = function (cb) {
2895
+ var node = new Fragment();
2896
+ node.$preinit(this.$.app, this);
2897
+ node.$init();
2898
+ node.$ready();
2899
+ this.$.fragment = node;
2900
+ this.$children.push(node);
2901
+ cb(node);
2902
+ };
2903
+ SwitchedNode.prototype.$ready = function () {
2904
+ var $ = this.$;
2905
+ _super.prototype.$ready.call(this);
2906
+ $.cases.forEach(function (c) {
2907
+ c.cond.on($.sync);
2908
+ });
2909
+ $.sync();
2910
+ };
2911
+ SwitchedNode.prototype.$destroy = function () {
2912
+ var $ = this.$;
2913
+ $.cases.forEach(function (c) {
2914
+ c.cond.off($.sync);
2915
+ });
2916
+ _super.prototype.$destroy.call(this);
2917
+ };
2918
+ return SwitchedNode;
2919
+ }(Fragment));
2920
+ /**
2921
+ * The private part of a text node
2922
+ */
2923
+ var DebugPrivate = /** @class */ (function (_super) {
2924
+ __extends(DebugPrivate, _super);
2925
+ function DebugPrivate() {
2926
+ var _this = this; _super.call(this);
2927
+ _this.$seal();
2928
+ return _this;
2929
+ }
2930
+ /**
2931
+ * Pre-initializes a text node
2932
+ * @param app {App} the app node
2933
+ * @param parent {Fragment} parent node
2934
+ * @param text {String | IValue}
2935
+ */
2936
+ DebugPrivate.prototype.preinitComment = function (app, parent, text) {
2937
+ var _this = this;
2938
+ _super.prototype.preinit.call(this, app, parent);
2939
+ this.node = document.createComment(text.$);
2940
+ this.bindings.add(new Expression(function (v) {
2941
+ _this.node.replaceData(0, -1, v);
2942
+ }, true, text));
2943
+ this.parent.$$appendNode(this.node);
2944
+ };
2945
+ /**
2946
+ * Clear node data
2947
+ */
2948
+ DebugPrivate.prototype.$destroy = function () {
2949
+ this.node.remove();
2950
+ _super.prototype.$destroy.call(this);
2951
+ };
2952
+ return DebugPrivate;
2953
+ }(FragmentPrivate));
2954
+
2955
+ /**
2956
+ * Represents a debug node
2957
+ * @class DebugNode
2958
+ * @extends Fragment
2959
+ */
2960
+ var DebugNode = /** @class */ (function (_super) {
2961
+ __extends(DebugNode, _super);
2962
+ function DebugNode() {
2963
+ var _this = this; _super.call(this);
2964
+ /**
2965
+ * private data
2966
+ * @type {DebugNode}
2967
+ */
2968
+ _this.$ = new DebugPrivate();
2969
+ _this.$seal();
2970
+ return _this;
2971
+ }
2972
+ DebugNode.prototype.$preinit = function (app, parent, text) {
2973
+ var $ = this.$;
2974
+ if (!text) {
2975
+ throw internalError('wrong DebugNode::$preninit call');
2976
+ }
2977
+ $.preinitComment(app, parent, text);
2978
+ };
2979
+ /**
2980
+ * Runs garbage collector
2981
+ */
2982
+ DebugNode.prototype.$destroy = function () {
2983
+ this.$.$destroy();
2984
+ _super.prototype.$destroy.call(this);
2985
+ };
2986
+ return DebugNode;
2987
+ }(Fragment));
2988
+
2989
+
2990
+ window.FragmentPrivate = FragmentPrivate;
2991
+ window.Fragment = Fragment;
2992
+ window.TextNodePrivate = TextNodePrivate;
2993
+ window.TextNode = TextNode;
2994
+ window.INodePrivate = INodePrivate;
2995
+ window.INode = INode;
2996
+ window.Tag = Tag;
2997
+ window.Extension = Extension;
2998
+ window.Component = Component;
2999
+ window.SwitchedNodePrivate = SwitchedNodePrivate;
3000
+ window.DebugPrivate = DebugPrivate;
3001
+ window.DebugNode = DebugNode;
3002
+
3003
+ // ./lib-es5/node/app.js
3004
+ /**
3005
+ * Application Node
3006
+ * @class AppNode
3007
+ * @extends INode
3008
+ */
3009
+ var AppNode = /** @class */ (function (_super) {
3010
+ __extends(AppNode, _super);
3011
+ /**
3012
+ * @param options {Object} Application options
3013
+ */
3014
+ function AppNode(options) {
3015
+ var _this = this; _super.call(this);
3016
+ _this.$run = (options === null || options === void 0 ? void 0 : options.executor) || ((options === null || options === void 0 ? void 0 : options.freezeUi) === false ? timeoutExecutor : instantExecutor);
3017
+ _this.$debugUi = (options === null || options === void 0 ? void 0 : options.debugUi) || false;
3018
+ return _this;
3019
+ }
3020
+ return AppNode;
3021
+ }(INode));
3022
+
3023
+ /**
3024
+ * Represents a Vasille.js application
3025
+ * @class App
3026
+ * @extends AppNode
3027
+ */
3028
+ var App = /** @class */ (function (_super) {
3029
+ __extends(App, _super);
3030
+ /**
3031
+ * Constructs an app node
3032
+ * @param node {Element} The root of application
3033
+ * @param options {Object} Application options
3034
+ */
3035
+ function App(node, options) {
3036
+ var _this = _super.call(this, options) || this;
3037
+ _this.$.node = node;
3038
+ _this.$preinit(_this, _this);
3039
+ _this.$seal();
3040
+ return _this;
3041
+ }
3042
+ App.prototype.$$appendNode = function (node) {
3043
+ var $ = this.$;
3044
+ $.app.$run.appendChild($.node, node);
3045
+ };
3046
+ return App;
3047
+ }(AppNode));
3048
+
3049
+
3050
+ window.AppNode = AppNode;
3051
+ window.App = App;
3052
+
3053
+ // ./lib-es5/node/interceptor.js
3054
+ /**
3055
+ * Interceptor is designed to connect signals & methods of children elements
3056
+ * @class Interceptor
3057
+ * @extends Destroyable
3058
+ */
3059
+ var Interceptor = /** @class */ (function (_super) {
3060
+ __extends(Interceptor, _super);
3061
+ function Interceptor() {
3062
+ var _this = _super !== null && _super.apply(this, arguments) || this;
3063
+ /**
3064
+ * Set of signals
3065
+ * @type Set
3066
+ */
3067
+ _this.signals = new Set;
3068
+ /**
3069
+ * Set of handlers
3070
+ * @type Set
3071
+ */
3072
+ _this.handlers = new Set;
3073
+ return _this;
3074
+ }
3075
+ /**
3076
+ * Connect a signal or a handler
3077
+ * @param thing {Signal | function}
3078
+ */
3079
+ Interceptor.prototype.connect = function (thing) {
3080
+ // interceptor will connect signals and handlers together
3081
+ if (thing instanceof Signal) {
3082
+ this.handlers.forEach(function (handler) {
3083
+ thing.subscribe(handler);
3084
+ });
3085
+ this.signals.add(thing);
3086
+ }
3087
+ else {
3088
+ this.signals.forEach(function (signal) {
3089
+ signal.subscribe(thing);
3090
+ });
3091
+ this.handlers.add(thing);
3092
+ }
3093
+ };
3094
+ /**
3095
+ * Disconnect a handler from signals
3096
+ * @param handler {function}
3097
+ */
3098
+ Interceptor.prototype.disconnect = function (handler) {
3099
+ this.signals.forEach(function (signal) {
3100
+ signal.unsubscribe(handler);
3101
+ });
3102
+ };
3103
+ Interceptor.prototype.$destroy = function () {
3104
+ var _this = this;
3105
+ _super.prototype.$destroy.call(this);
3106
+ this.signals.forEach(function (signal) {
3107
+ _this.handlers.forEach(function (handler) {
3108
+ signal.unsubscribe(handler);
3109
+ });
3110
+ });
3111
+ };
3112
+ return Interceptor;
3113
+ }(Destroyable));
3114
+
3115
+ /**
3116
+ * Interceptor node to implement directly to vasille DOM
3117
+ * @class InterceptorNode
3118
+ * @extends Extension
3119
+ */
3120
+ var InterceptorNode = /** @class */ (function (_super) {
3121
+ __extends(InterceptorNode, _super);
3122
+ function InterceptorNode() {
3123
+ var _this = _super !== null && _super.apply(this, arguments) || this;
3124
+ /**
3125
+ * Internal interceptor
3126
+ * @type Interceptor
3127
+ */
3128
+ _this.interceptor = new Interceptor;
3129
+ /**
3130
+ * The default slot of node
3131
+ * @type Slot
3132
+ */
3133
+ _this.slot = new Slot;
3134
+ return _this;
3135
+ }
3136
+ InterceptorNode.prototype.$compose = function () {
3137
+ this.slot.release(this, this.interceptor);
3138
+ };
3139
+ return InterceptorNode;
3140
+ }(Fragment));
3141
+
3142
+
3143
+ window.Interceptor = Interceptor;
3144
+ window.InterceptorNode = InterceptorNode;
3145
+
3146
+ // ./lib-es5/binding/attribute.js
3147
+ /**
3148
+ * Represents an Attribute binding description
3149
+ * @class AttributeBinding
3150
+ * @extends Binding
3151
+ */
3152
+ var AttributeBinding = /** @class */ (function (_super) {
3153
+ __extends(AttributeBinding, _super);
3154
+ /**
3155
+ * Constructs an attribute binding description
3156
+ * @param node {INode} the vasille node
3157
+ * @param name {String} the name of attribute
3158
+ * @param value {IValue} value to bind
3159
+ */
3160
+ function AttributeBinding(node, name, value) {
3161
+ return _super.call(this, node, name, value) || this;
3162
+ }
3163
+ /**
3164
+ * Generates a function which updates the attribute value
3165
+ * @param name {String} The name of attribute
3166
+ * @returns {Function} a function which will update attribute value
3167
+ */
3168
+ AttributeBinding.prototype.bound = function (name) {
3169
+ return function (node, value) {
3170
+ if (value) {
3171
+ node.app.$run.setAttribute(node.node, name, value);
3172
+ }
3173
+ else {
3174
+ node.app.$run.removeAttribute(node.node, name);
3175
+ }
3176
+ };
3177
+ };
3178
+ return AttributeBinding;
3179
+ }(Binding));
3180
+
3181
+
3182
+ window.AttributeBinding = AttributeBinding;
3183
+
3184
+ // ./lib-es5/binding/style.js
3185
+ /**
3186
+ * Describes a style attribute binding
3187
+ * @class StyleBinding
3188
+ * @extends Binding
3189
+ */
3190
+ var StyleBinding = /** @class */ (function (_super) {
3191
+ __extends(StyleBinding, _super);
3192
+ /**
3193
+ * Constructs a style binding attribute
3194
+ * @param node {INode} the vasille node
3195
+ * @param name {string} the name of style property
3196
+ * @param value {IValue} the value to bind
3197
+ */
3198
+ function StyleBinding(node, name, value) {
3199
+ return _super.call(this, node, name, value) || this;
3200
+ }
3201
+ /**
3202
+ * Generates a function to update style property value
3203
+ * @param name {string}
3204
+ * @returns {Function} a function to update style property
3205
+ */
3206
+ StyleBinding.prototype.bound = function (name) {
3207
+ return function (node, value) {
3208
+ if (node.node instanceof HTMLElement) {
3209
+ node.app.$run.setStyle(node.node, name, value);
3210
+ }
3211
+ };
3212
+ };
3213
+ return StyleBinding;
3214
+ }(Binding));
3215
+
3216
+
3217
+ window.StyleBinding = StyleBinding;
3218
+
3219
+ // ./lib-es5/binding/class.js
3220
+ /**
3221
+ * Represents a HTML class binding description
3222
+ * @class ClassBinding
3223
+ * @extends Binding
3224
+ */
3225
+ var ClassBinding = /** @class */ (function (_super) {
3226
+ __extends(ClassBinding, _super);
3227
+ /**
3228
+ * Constructs an HTML class binding description
3229
+ * @param node {INode} the vasille node
3230
+ * @param name {String} the name of class
3231
+ * @param value {IValue} the value to bind
3232
+ */
3233
+ function ClassBinding(node, name, value) {
3234
+ var _this = _super.call(this, node, name, value) || this;
3235
+ _this.$seal();
3236
+ return _this;
3237
+ }
3238
+ /**
3239
+ * Generates a function which updates the html class value
3240
+ * @param name {String} The name of attribute
3241
+ * @returns {Function} a function which will update attribute value
3242
+ */
3243
+ ClassBinding.prototype.bound = function (name) {
3244
+ var current = null;
3245
+ function addClass(node, cl) {
3246
+ node.app.$run.addClass(node.node, cl);
3247
+ }
3248
+ function removeClass(node, cl) {
3249
+ node.app.$run.removeClass(node.node, cl);
3250
+ }
3251
+ return function (node, value) {
3252
+ if (value !== current) {
3253
+ if (typeof current === "string" && current !== "") {
3254
+ removeClass(node, current);
3255
+ }
3256
+ if (typeof value === "boolean") {
3257
+ if (value) {
3258
+ addClass(node, name);
3259
+ }
3260
+ else {
3261
+ removeClass(node, name);
3262
+ }
3263
+ }
3264
+ else if (typeof value === "string" && value !== "") {
3265
+ addClass(node, value);
3266
+ }
3267
+ current = value;
3268
+ }
3269
+ };
3270
+ };
3271
+ return ClassBinding;
3272
+ }(Binding));
3273
+
3274
+
3275
+ window.ClassBinding = ClassBinding;
3276
+
3277
+ // ./lib-es5/views/repeat-node.js
3278
+ /**
3279
+ * Private part of repeat node
3280
+ * @class RepeatNodePrivate
3281
+ * @extends INodePrivate
3282
+ */
3283
+ var RepeatNodePrivate = /** @class */ (function (_super) {
3284
+ __extends(RepeatNodePrivate, _super);
3285
+ function RepeatNodePrivate() {
3286
+ var _this = this; _super.call(this);
3287
+ /**
3288
+ * Children node hash
3289
+ * @type {Map}
3290
+ */
3291
+ _this.nodes = new Map();
3292
+ _this.$seal();
3293
+ return _this;
3294
+ }
3295
+ RepeatNodePrivate.prototype.$destroy = function () {
3296
+ this.nodes.clear();
3297
+ _super.prototype.$destroy.call(this);
3298
+ };
3299
+ return RepeatNodePrivate;
3300
+ }(INodePrivate));
3301
+
3302
+ /**
3303
+ * Repeat node repeats its children
3304
+ * @class RepeatNode
3305
+ * @extends Fragment
3306
+ */
3307
+ var RepeatNode = /** @class */ (function (_super) {
3308
+ __extends(RepeatNode, _super);
3309
+ function RepeatNode($) {
3310
+ var _this = _super.call(this, $ || new RepeatNodePrivate) || this;
3311
+ /**
3312
+ * If false will use timeout executor, otherwise the app executor
3313
+ */
3314
+ _this.freezeUi = true;
3315
+ _this.slot = new Slot;
3316
+ return _this;
3317
+ }
3318
+ RepeatNode.prototype.createChild = function (id, item, before) {
3319
+ // TODO: Refactor: remove @ts-ignore
3320
+ var _this = this;
3321
+ var node = new Fragment();
3322
+ // eslint-disable-next-line
3323
+ // @ts-ignore
3324
+ var $ = node.$;
3325
+ this.destroyChild(id, item);
3326
+ if (before) {
3327
+ $.next = before;
3328
+ // eslint-disable-next-line
3329
+ // @ts-ignore
3330
+ $.prev = before.$.prev;
3331
+ // eslint-disable-next-line
3332
+ // @ts-ignore
3333
+ before.$.prev = node;
3334
+ if ($.prev) {
3335
+ // eslint-disable-next-line
3336
+ // @ts-ignore
3337
+ $.prev.$.next = node;
3338
+ }
3339
+ this.$children.splice(this.$children.indexOf(before), 0, node);
3340
+ }
3341
+ else {
3342
+ var lastChild = this.$children[this.$children.length - 1];
3343
+ if (lastChild) {
3344
+ // eslint-disable-next-line
3345
+ // @ts-ignore
3346
+ lastChild.$.next = node;
3347
+ }
3348
+ $.prev = lastChild;
3349
+ this.$children.push(node);
3350
+ }
3351
+ node.$preinit(this.$.app, this);
3352
+ node.$init();
3353
+ var callback = function () {
3354
+ _this.slot.release(node, item, id);
3355
+ node.$ready();
3356
+ };
3357
+ if (this.freezeUi) {
3358
+ this.$.app.$run.callCallback(callback);
3359
+ }
3360
+ else {
3361
+ timeoutExecutor.callCallback(callback);
3362
+ }
3363
+ this.$.nodes.set(id, node);
3364
+ };
3365
+ RepeatNode.prototype.destroyChild = function (id, item) {
3366
+ var $ = this.$;
3367
+ var child = $.nodes.get(id);
3368
+ if (child) {
3369
+ // eslint-disable-next-line
3370
+ // @ts-ignore
3371
+ var $_1 = child.$;
3372
+ if ($_1.prev) {
3373
+ // eslint-disable-next-line
3374
+ // @ts-ignore
3375
+ $_1.prev.$.next = $_1.next;
3376
+ }
3377
+ if ($_1.next) {
3378
+ // eslint-disable-next-line
3379
+ // @ts-ignore
3380
+ $_1.next.$.prev = $_1.prev;
3381
+ }
3382
+ child.$destroy();
3383
+ this.$.nodes.delete(id);
3384
+ this.$children.splice(this.$children.indexOf(child), 1);
3385
+ }
3386
+ };
3387
+ return RepeatNode;
3388
+ }(Fragment));
3389
+
3390
+
3391
+ window.RepeatNodePrivate = RepeatNodePrivate;
3392
+ window.RepeatNode = RepeatNode;
3393
+
3394
+ // ./lib-es5/views/repeater.js
3395
+ /**
3396
+ * Private part of repeater
3397
+ * @class RepeaterPrivate
3398
+ * @extends RepeatNodePrivate
3399
+ */
3400
+ var RepeaterPrivate = /** @class */ (function (_super) {
3401
+ __extends(RepeaterPrivate, _super);
3402
+ function RepeaterPrivate() {
3403
+ var _this = this; _super.call(this);
3404
+ /**
3405
+ * Current count of child nodes
3406
+ */
3407
+ _this.currentCount = 0;
3408
+ _this.$seal();
3409
+ return _this;
3410
+ }
3411
+ return RepeaterPrivate;
3412
+ }(RepeatNodePrivate));
3413
+
3414
+ /**
3415
+ * The simplest repeat node interpretation, repeat children pack a several times
3416
+ * @class Repeater
3417
+ * @extends RepeatNode
3418
+ */
3419
+ var Repeater = /** @class */ (function (_super) {
3420
+ __extends(Repeater, _super);
3421
+ function Repeater($) {
3422
+ var _this = _super.call(this, $ || new RepeaterPrivate) || this;
3423
+ /**
3424
+ * The count of children
3425
+ */
3426
+ _this.count = new Reference(0);
3427
+ _this.$seal();
3428
+ return _this;
3429
+ }
3430
+ /**
3431
+ * Changes the children count
3432
+ */
3433
+ Repeater.prototype.changeCount = function (number) {
3434
+ var $ = this.$;
3435
+ if (number > $.currentCount) {
3436
+ for (var i = $.currentCount; i < number; i++) {
3437
+ this.createChild(i, i);
3438
+ }
3439
+ }
3440
+ else {
3441
+ for (var i = $.currentCount - 1; i >= number; i--) {
3442
+ this.destroyChild(i, i);
3443
+ }
3444
+ }
3445
+ $.currentCount = number;
3446
+ };
3447
+ Repeater.prototype.$created = function () {
3448
+ var $ = this.$;
3449
+ _super.prototype.$created.call(this);
3450
+ $.updateHandler = this.changeCount.bind(this);
3451
+ this.count.on($.updateHandler);
3452
+ };
3453
+ Repeater.prototype.$ready = function () {
3454
+ this.changeCount(this.count.$);
3455
+ };
3456
+ Repeater.prototype.$destroy = function () {
3457
+ var $ = this.$;
3458
+ _super.prototype.$destroy.call(this);
3459
+ this.count.off($.updateHandler);
3460
+ };
3461
+ return Repeater;
3462
+ }(RepeatNode));
3463
+
3464
+
3465
+ window.RepeaterPrivate = RepeaterPrivate;
3466
+ window.Repeater = Repeater;
3467
+
3468
+ // ./lib-es5/views/base-view.js
3469
+ /**
3470
+ * Private part of BaseView
3471
+ * @class BaseViewPrivate
3472
+ * @extends RepeatNodePrivate
3473
+ */
3474
+ var BaseViewPrivate = /** @class */ (function (_super) {
3475
+ __extends(BaseViewPrivate, _super);
3476
+ function BaseViewPrivate() {
3477
+ var _this = this; _super.call(this);
3478
+ _this.$seal();
3479
+ return _this;
3480
+ }
3481
+ return BaseViewPrivate;
3482
+ }(RepeatNodePrivate));
3483
+
3484
+ /**
3485
+ * Base class of default views
3486
+ * @class BaseView
3487
+ * @extends RepeatNode
3488
+ * @implements IModel
3489
+ */
3490
+ var BaseView = /** @class */ (function (_super) {
3491
+ __extends(BaseView, _super);
3492
+ function BaseView($1) {
3493
+ var _this = _super.call(this, $1 || new BaseViewPrivate) || this;
3494
+ var $ = _this.$;
3495
+ $.addHandler = function (id, item) {
3496
+ _this.createChild(id, item);
3497
+ };
3498
+ $.removeHandler = function (id, item) {
3499
+ _this.destroyChild(id, item);
3500
+ };
3501
+ _this.$seal();
3502
+ return _this;
3503
+ }
3504
+ /**
3505
+ * Handle ready event
3506
+ */
3507
+ BaseView.prototype.$ready = function () {
3508
+ var $ = this.$;
3509
+ this.model.listener.onAdd($.addHandler);
3510
+ this.model.listener.onRemove($.removeHandler);
3511
+ _super.prototype.$ready.call(this);
3512
+ };
3513
+ /**
3514
+ * Handles destroy event
3515
+ */
3516
+ BaseView.prototype.$destroy = function () {
3517
+ var $ = this.$;
3518
+ this.model.listener.offAdd($.addHandler);
3519
+ this.model.listener.offRemove($.removeHandler);
3520
+ _super.prototype.$destroy.call(this);
3521
+ };
3522
+ return BaseView;
3523
+ }(RepeatNode));
3524
+
3525
+
3526
+ window.BaseViewPrivate = BaseViewPrivate;
3527
+ window.BaseView = BaseView;
3528
+
3529
+ // ./lib-es5/views/array-view.js
3530
+ /**
3531
+ * Represents a view of an array model
3532
+ * @class ArrayView
3533
+ * @extends BaseView
3534
+ */
3535
+ var ArrayView = /** @class */ (function (_super) {
3536
+ __extends(ArrayView, _super);
3537
+ function ArrayView(model) {
3538
+ var _this = this; _super.call(this);
3539
+ _this.model = model;
3540
+ return _this;
3541
+ }
3542
+ ArrayView.prototype.createChild = function (id, item, before) {
3543
+ _super.prototype.createChild.call(this, item, item, before || this.$.nodes.get(id));
3544
+ };
3545
+ ArrayView.prototype.$ready = function () {
3546
+ var _this = this;
3547
+ this.model.forEach(function (item) {
3548
+ _this.createChild(item, item);
3549
+ });
3550
+ _super.prototype.$ready.call(this);
3551
+ };
3552
+ return ArrayView;
3553
+ }(BaseView));
3554
+
3555
+
3556
+ window.ArrayView = ArrayView;
3557
+
3558
+ // ./lib-es5/node/watch.js
3559
+ /**
3560
+ * Watch Node
3561
+ * @class Watch
3562
+ * @extends Fragment
3563
+ */
3564
+ var Watch = /** @class */ (function (_super) {
3565
+ __extends(Watch, _super);
3566
+ function Watch() {
3567
+ var _this = this; _super.call(this);
3568
+ _this.slot = new Slot;
3569
+ _this.model = _this.$ref(null);
3570
+ _this.$seal();
3571
+ return _this;
3572
+ }
3573
+ Watch.prototype.$createWatchers = function () {
3574
+ var _this = this;
3575
+ this.$watch(function (value) {
3576
+ _this.$children.forEach(function (child) {
3577
+ child.$destroy();
3578
+ });
3579
+ _this.$children.splice(0);
3580
+ _this.slot.release(_this, value);
3581
+ }, this.model);
3582
+ };
3583
+ Watch.prototype.$compose = function () {
3584
+ this.slot.release(this, this.model.$);
3585
+ };
3586
+ return Watch;
3587
+ }(Fragment));
3588
+
3589
+
3590
+ window.Watch = Watch;
3591
+
3592
+ // ./lib-es5/views/object-view.js
3593
+ /**
3594
+ * Create a children pack for each object field
3595
+ * @class ObjectView
3596
+ * @extends BaseView
3597
+ */
3598
+ var ObjectView = /** @class */ (function (_super) {
3599
+ __extends(ObjectView, _super);
3600
+ function ObjectView(model) {
3601
+ var _this = this; _super.call(this);
3602
+ _this.model = model;
3603
+ return _this;
3604
+ }
3605
+ ObjectView.prototype.$ready = function () {
3606
+ var obj = this.model;
3607
+ for (var key in obj) {
3608
+ this.createChild(key, obj[key]);
3609
+ }
3610
+ _super.prototype.$ready.call(this);
3611
+ };
3612
+ return ObjectView;
3613
+ }(BaseView));
3614
+
3615
+
3616
+ window.ObjectView = ObjectView;
3617
+
3618
+ // ./lib-es5/views/map-view.js
3619
+ /**
3620
+ * Create a children pack for each map value
3621
+ * @class MapView
3622
+ * @extends BaseView
3623
+ */
3624
+ var MapView = /** @class */ (function (_super) {
3625
+ __extends(MapView, _super);
3626
+ function MapView(model) {
3627
+ var _this = this; _super.call(this);
3628
+ _this.model = model;
3629
+ return _this;
3630
+ }
3631
+ MapView.prototype.$ready = function () {
3632
+ var _this = this;
3633
+ var map = this.model;
3634
+ map.forEach(function (value, key) {
3635
+ _this.createChild(key, value);
3636
+ });
3637
+ _super.prototype.$ready.call(this);
3638
+ };
3639
+ return MapView;
3640
+ }(BaseView));
3641
+
3642
+
3643
+ window.MapView = MapView;
3644
+
3645
+ // ./lib-es5/views/set-view.js
3646
+ /**
3647
+ * Create a children pack for each set value
3648
+ * @class SetView
3649
+ * @extends BaseView
3650
+ */
3651
+ var SetView = /** @class */ (function (_super) {
3652
+ __extends(SetView, _super);
3653
+ function SetView(model) {
3654
+ var _this = this; _super.call(this);
3655
+ _this.model = model;
3656
+ return _this;
3657
+ }
3658
+ SetView.prototype.$ready = function () {
3659
+ var _this = this;
3660
+ var $ = this.$;
3661
+ var set = this.model;
3662
+ set.forEach(function (item) {
3663
+ $.app.$run.callCallback(function () {
3664
+ _this.createChild(item, item);
3665
+ });
3666
+ });
3667
+ _super.prototype.$ready.call(this);
3668
+ };
3669
+ return SetView;
3670
+ }(BaseView));
3671
+
3672
+
3673
+ window.SetView = SetView;
3674
+
3675
+ })();