@tko/bind 4.0.0-alpha8.4 → 4.0.0-beta1.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,2972 @@
1
+ // @tko/bind 🥊 4.0.0-beta1.3 CommonJS
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // index.ts
41
+ var bind_exports = {};
42
+ __export(bind_exports, {
43
+ AsyncBindingHandler: () => AsyncBindingHandler,
44
+ BindingHandler: () => BindingHandler,
45
+ DescendantBindingHandler: () => DescendantBindingHandler,
46
+ applyBindingAccessorsToNode: () => applyBindingAccessorsToNode,
47
+ applyBindings: () => applyBindings,
48
+ applyBindingsToDescendants: () => applyBindingsToDescendants,
49
+ applyBindingsToNode: () => applyBindingsToNode,
50
+ bindingContext: () => bindingContext,
51
+ bindingEvent: () => bindingEvent,
52
+ boundElementDomDataKey: () => boundElementDomDataKey2,
53
+ contextFor: () => contextFor,
54
+ contextSubscribeSymbol: () => contextSubscribeSymbol,
55
+ dataFor: () => dataFor,
56
+ getBindingHandler: () => getBindingHandler,
57
+ setDomNodeChildrenFromArrayMapping: () => setDomNodeChildrenFromArrayMapping,
58
+ storedBindingContextForNode: () => storedBindingContextForNode
59
+ });
60
+ module.exports = __toCommonJS(bind_exports);
61
+
62
+ // ../utils/dist/array.js
63
+ var { isArray } = Array;
64
+ function arrayForEach(array, action, thisArg) {
65
+ if (arguments.length > 2) {
66
+ action = action.bind(thisArg);
67
+ }
68
+ for (let i = 0, j = array.length; i < j; ++i) {
69
+ action(array[i], i, array);
70
+ }
71
+ }
72
+ function arrayIndexOf(array, item) {
73
+ return (isArray(array) ? array : [...array]).indexOf(item);
74
+ }
75
+ function arrayFirst(array, predicate, predicateOwner) {
76
+ return (isArray(array) ? array : [...array]).find(predicate, predicateOwner);
77
+ }
78
+ function arrayMap(array = [], mapping, thisArg) {
79
+ if (arguments.length > 2) {
80
+ mapping = mapping.bind(thisArg);
81
+ }
82
+ return array === null ? [] : Array.from(array, mapping);
83
+ }
84
+ function arrayRemoveItem(array, itemToRemove) {
85
+ var index = arrayIndexOf(array, itemToRemove);
86
+ if (index > 0) {
87
+ array.splice(index, 1);
88
+ } else if (index === 0) {
89
+ array.shift();
90
+ }
91
+ }
92
+ function arrayPushAll(array, valuesToPush) {
93
+ if (isArray(valuesToPush)) {
94
+ array.push.apply(array, valuesToPush);
95
+ } else {
96
+ for (var i = 0, j = valuesToPush.length; i < j; i++) {
97
+ array.push(valuesToPush[i]);
98
+ }
99
+ }
100
+ return array;
101
+ }
102
+ function findMovesInArrayComparison(left, right, limitFailedCompares) {
103
+ if (left.length && right.length) {
104
+ var failedCompares, l, r, leftItem, rightItem;
105
+ for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) {
106
+ for (r = 0; rightItem = right[r]; ++r) {
107
+ if (leftItem.value === rightItem.value) {
108
+ leftItem.moved = rightItem.index;
109
+ rightItem.moved = leftItem.index;
110
+ right.splice(r, 1);
111
+ failedCompares = r = 0;
112
+ break;
113
+ }
114
+ }
115
+ failedCompares += r;
116
+ }
117
+ }
118
+ }
119
+ var statusNotInOld = "added";
120
+ var statusNotInNew = "deleted";
121
+ function compareArrays(oldArray, newArray, options2) {
122
+ options2 = typeof options2 === "boolean" ? { dontLimitMoves: options2 } : options2 || {};
123
+ oldArray = oldArray || [];
124
+ newArray = newArray || [];
125
+ if (oldArray.length < newArray.length) {
126
+ return compareSmallArrayToBigArray(oldArray, newArray, statusNotInOld, statusNotInNew, options2);
127
+ } else {
128
+ return compareSmallArrayToBigArray(newArray, oldArray, statusNotInNew, statusNotInOld, options2);
129
+ }
130
+ }
131
+ function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, options2) {
132
+ var myMin = Math.min, myMax = Math.max, editDistanceMatrix = [], smlIndex, smlIndexMax = smlArray.length, bigIndex, bigIndexMax = bigArray.length, compareRange = bigIndexMax - smlIndexMax || 1, maxDistance = smlIndexMax + bigIndexMax + 1, thisRow, lastRow, bigIndexMaxForRow, bigIndexMinForRow;
133
+ for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
134
+ lastRow = thisRow;
135
+ editDistanceMatrix.push(thisRow = []);
136
+ bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
137
+ bigIndexMinForRow = myMax(0, smlIndex - 1);
138
+ for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
139
+ if (!bigIndex) {
140
+ thisRow[bigIndex] = smlIndex + 1;
141
+ } else if (!smlIndex) {
142
+ thisRow[bigIndex] = bigIndex + 1;
143
+ } else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1]) {
144
+ thisRow[bigIndex] = lastRow[bigIndex - 1];
145
+ } else {
146
+ var northDistance = lastRow[bigIndex] || maxDistance;
147
+ var westDistance = thisRow[bigIndex - 1] || maxDistance;
148
+ thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
149
+ }
150
+ }
151
+ }
152
+ var editScript = [], meMinusOne, notInSml = [], notInBig = [];
153
+ for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex; ) {
154
+ meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
155
+ if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {
156
+ notInSml.push(editScript[editScript.length] = {
157
+ "status": statusNotInSml,
158
+ "value": bigArray[--bigIndex],
159
+ "index": bigIndex
160
+ });
161
+ } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
162
+ notInBig.push(editScript[editScript.length] = {
163
+ "status": statusNotInBig,
164
+ "value": smlArray[--smlIndex],
165
+ "index": smlIndex
166
+ });
167
+ } else {
168
+ --bigIndex;
169
+ --smlIndex;
170
+ if (!options2.sparse) {
171
+ editScript.push({
172
+ "status": "retained",
173
+ "value": bigArray[bigIndex]
174
+ });
175
+ }
176
+ }
177
+ }
178
+ findMovesInArrayComparison(notInBig, notInSml, !options2.dontLimitMoves && smlIndexMax * 10);
179
+ return editScript.reverse();
180
+ }
181
+
182
+ // ../utils/dist/options.js
183
+ var options = {
184
+ deferUpdates: false,
185
+ useOnlyNativeEvents: false,
186
+ protoProperty: "__ko_proto__",
187
+ defaultBindingAttribute: "data-bind",
188
+ allowVirtualElements: true,
189
+ bindingGlobals: /* @__PURE__ */ Object.create(null),
190
+ bindingProviderInstance: null,
191
+ createChildContextWithAs: false,
192
+ jQuery: globalThis.jQuery,
193
+ Promise: globalThis.Promise,
194
+ taskScheduler: null,
195
+ debug: false,
196
+ global: globalThis,
197
+ document: globalThis.document,
198
+ filters: {},
199
+ includeDestroyed: false,
200
+ foreachHidesDestroyed: false,
201
+ onError: function(e) {
202
+ throw e;
203
+ },
204
+ set: function(name, value) {
205
+ options[name] = value;
206
+ },
207
+ getBindingHandler() {
208
+ },
209
+ cleanExternalData() {
210
+ }
211
+ };
212
+ Object.defineProperty(options, "$", {
213
+ get: function() {
214
+ return options.jQuery;
215
+ }
216
+ });
217
+ var options_default = options;
218
+
219
+ // ../utils/dist/error.js
220
+ function catchFunctionErrors(delegate) {
221
+ if (!options_default.onError) {
222
+ return delegate;
223
+ }
224
+ return (...args) => {
225
+ try {
226
+ return delegate(...args);
227
+ } catch (err) {
228
+ options_default.onError(err);
229
+ }
230
+ };
231
+ }
232
+ function deferError(error) {
233
+ safeSetTimeout(function() {
234
+ throw error;
235
+ }, 0);
236
+ }
237
+ function safeSetTimeout(handler, timeout) {
238
+ return setTimeout(catchFunctionErrors(handler), timeout);
239
+ }
240
+
241
+ // ../utils/dist/async.js
242
+ function throttle(callback, timeout) {
243
+ var timeoutInstance;
244
+ return function(...args) {
245
+ if (!timeoutInstance) {
246
+ timeoutInstance = safeSetTimeout(function() {
247
+ timeoutInstance = void 0;
248
+ callback(...args);
249
+ }, timeout);
250
+ }
251
+ };
252
+ }
253
+ function debounce(callback, timeout) {
254
+ var timeoutInstance;
255
+ return function(...args) {
256
+ clearTimeout(timeoutInstance);
257
+ timeoutInstance = safeSetTimeout(() => callback(...args), timeout);
258
+ };
259
+ }
260
+
261
+ // ../utils/dist/ie.js
262
+ var ieVersion = options_default.document && function() {
263
+ var version = 3, div = options_default.document.createElement("div"), iElems = div.getElementsByTagName("i");
264
+ while (div.innerHTML = "<!--[if gt IE " + ++version + "]><i></i><![endif]-->", iElems[0]) {
265
+ }
266
+ if (!version) {
267
+ const userAgent = window.navigator.userAgent;
268
+ return ua.match(/MSIE ([^ ]+)/) || ua.match(/rv:([^ )]+)/);
269
+ }
270
+ return version > 4 ? version : void 0;
271
+ }();
272
+
273
+ // ../utils/dist/object.js
274
+ function hasOwnProperty(obj, propName) {
275
+ return Object.prototype.hasOwnProperty.call(obj, propName);
276
+ }
277
+ function isObjectLike(obj) {
278
+ if (obj === null) {
279
+ return false;
280
+ }
281
+ return typeof obj === "object" || typeof obj === "function";
282
+ }
283
+ function extend(target, source) {
284
+ if (source) {
285
+ for (var prop in source) {
286
+ if (hasOwnProperty(source, prop)) {
287
+ target[prop] = source[prop];
288
+ }
289
+ }
290
+ }
291
+ return target;
292
+ }
293
+ function objectForEach(obj, action) {
294
+ for (var prop in obj) {
295
+ if (hasOwnProperty(obj, prop)) {
296
+ action(prop, obj[prop]);
297
+ }
298
+ }
299
+ }
300
+ function objectMap(source, mapping, thisArg) {
301
+ if (!source) {
302
+ return source;
303
+ }
304
+ if (arguments.length > 2) {
305
+ mapping = mapping.bind(thisArg);
306
+ }
307
+ var target = {};
308
+ for (var prop in source) {
309
+ if (hasOwnProperty(source, prop)) {
310
+ target[prop] = mapping(source[prop], prop, source);
311
+ }
312
+ }
313
+ return target;
314
+ }
315
+
316
+ // ../utils/dist/function.js
317
+ function testOverwrite() {
318
+ try {
319
+ Object.defineProperty(function x() {
320
+ }, "length", {});
321
+ return true;
322
+ } catch (e) {
323
+ return false;
324
+ }
325
+ }
326
+ var functionSupportsLengthOverwrite = testOverwrite();
327
+ function overwriteLengthPropertyIfSupported(fn, descriptor) {
328
+ if (functionSupportsLengthOverwrite) {
329
+ Object.defineProperty(fn, "length", descriptor);
330
+ }
331
+ }
332
+
333
+ // ../utils/dist/symbol.js
334
+ var useSymbols = typeof Symbol === "function";
335
+ function createSymbolOrString(identifier) {
336
+ return useSymbols ? Symbol(identifier) : identifier;
337
+ }
338
+
339
+ // ../utils/dist/jquery.js
340
+ var jQueryInstance = options_default.global && options_default.global.jQuery;
341
+
342
+ // ../utils/dist/dom/info.js
343
+ function domNodeIsContainedBy(node, containedByNode) {
344
+ if (node === containedByNode) {
345
+ return true;
346
+ }
347
+ if (node.nodeType === 11) {
348
+ return false;
349
+ }
350
+ if (containedByNode.contains) {
351
+ return containedByNode.contains(node.nodeType !== 1 ? node.parentNode : node);
352
+ }
353
+ if (containedByNode.compareDocumentPosition) {
354
+ return (containedByNode.compareDocumentPosition(node) & 16) == 16;
355
+ }
356
+ while (node && node != containedByNode) {
357
+ node = node.parentNode;
358
+ }
359
+ return !!node;
360
+ }
361
+ function domNodeIsAttachedToDocument(node) {
362
+ return domNodeIsContainedBy(node, node.ownerDocument.documentElement);
363
+ }
364
+ function anyDomNodeIsAttachedToDocument(nodes) {
365
+ return !!arrayFirst(nodes, domNodeIsAttachedToDocument);
366
+ }
367
+ function tagNameLower(element) {
368
+ return element && element.tagName && element.tagName.toLowerCase();
369
+ }
370
+
371
+ // ../utils/dist/dom/data.js
372
+ var data_exports = {};
373
+ __export(data_exports, {
374
+ clear: () => clear,
375
+ get: () => get,
376
+ getOrSet: () => getOrSet,
377
+ nextKey: () => nextKey,
378
+ set: () => set
379
+ });
380
+ var datastoreTime = new Date().getTime();
381
+ var dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`;
382
+ var dataStoreSymbol = Symbol("Knockout data");
383
+ var dataStore;
384
+ var uniqueId = 0;
385
+ var modern = {
386
+ getDataForNode(node, createIfNotFound) {
387
+ let dataForNode = node[dataStoreSymbol];
388
+ if (!dataForNode && createIfNotFound) {
389
+ dataForNode = node[dataStoreSymbol] = {};
390
+ }
391
+ return dataForNode;
392
+ },
393
+ clear(node) {
394
+ if (node[dataStoreSymbol]) {
395
+ delete node[dataStoreSymbol];
396
+ return true;
397
+ }
398
+ return false;
399
+ }
400
+ };
401
+ var IE = {
402
+ getDataforNode(node, createIfNotFound) {
403
+ let dataStoreKey = node[dataStoreKeyExpandoPropertyName];
404
+ const hasExistingDataStore = dataStoreKey && dataStoreKey !== "null" && dataStore[dataStoreKey];
405
+ if (!hasExistingDataStore) {
406
+ if (!createIfNotFound) {
407
+ return void 0;
408
+ }
409
+ dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++;
410
+ dataStore[dataStoreKey] = {};
411
+ }
412
+ return dataStore[dataStoreKey];
413
+ },
414
+ clear(node) {
415
+ const dataStoreKey = node[dataStoreKeyExpandoPropertyName];
416
+ if (dataStoreKey) {
417
+ delete dataStore[dataStoreKey];
418
+ node[dataStoreKeyExpandoPropertyName] = null;
419
+ return true;
420
+ }
421
+ return false;
422
+ }
423
+ };
424
+ var { getDataForNode, clear } = ieVersion ? IE : modern;
425
+ function nextKey() {
426
+ return uniqueId++ + dataStoreKeyExpandoPropertyName;
427
+ }
428
+ function get(node, key) {
429
+ const dataForNode = getDataForNode(node, false);
430
+ return dataForNode && dataForNode[key];
431
+ }
432
+ function set(node, key, value) {
433
+ var dataForNode = getDataForNode(node, value !== void 0);
434
+ dataForNode && (dataForNode[key] = value);
435
+ }
436
+ function getOrSet(node, key, value) {
437
+ const dataForNode = getDataForNode(node, true);
438
+ return dataForNode[key] || (dataForNode[key] = value);
439
+ }
440
+
441
+ // ../utils/dist/dom/disposal.js
442
+ var domDataKey = nextKey();
443
+ var cleanableNodeTypes = { 1: true, 8: true, 9: true };
444
+ var cleanableNodeTypesWithDescendants = { 1: true, 9: true };
445
+ function getDisposeCallbacksCollection(node, createIfNotFound) {
446
+ var allDisposeCallbacks = get(node, domDataKey);
447
+ if (allDisposeCallbacks === void 0 && createIfNotFound) {
448
+ allDisposeCallbacks = [];
449
+ set(node, domDataKey, allDisposeCallbacks);
450
+ }
451
+ return allDisposeCallbacks;
452
+ }
453
+ function destroyCallbacksCollection(node) {
454
+ set(node, domDataKey, void 0);
455
+ }
456
+ function cleanSingleNode(node) {
457
+ var callbacks = getDisposeCallbacksCollection(node, false);
458
+ if (callbacks) {
459
+ callbacks = callbacks.slice(0);
460
+ for (let i = 0; i < callbacks.length; i++) {
461
+ callbacks[i](node);
462
+ }
463
+ }
464
+ clear(node);
465
+ for (let i = 0, j = otherNodeCleanerFunctions.length; i < j; ++i) {
466
+ otherNodeCleanerFunctions[i](node);
467
+ }
468
+ if (options_default.cleanExternalData) {
469
+ options_default.cleanExternalData(node);
470
+ }
471
+ if (cleanableNodeTypesWithDescendants[node.nodeType]) {
472
+ cleanNodesInList(node.childNodes, true);
473
+ }
474
+ }
475
+ function cleanNodesInList(nodeList, onlyComments) {
476
+ const cleanedNodes = [];
477
+ let lastCleanedNode;
478
+ for (var i = 0; i < nodeList.length; i++) {
479
+ if (!onlyComments || nodeList[i].nodeType === 8) {
480
+ cleanSingleNode(cleanedNodes[cleanedNodes.length] = lastCleanedNode = nodeList[i]);
481
+ if (nodeList[i] !== lastCleanedNode) {
482
+ while (i-- && arrayIndexOf(cleanedNodes, nodeList[i]) === -1) {
483
+ }
484
+ }
485
+ }
486
+ }
487
+ }
488
+ function addDisposeCallback(node, callback) {
489
+ if (typeof callback !== "function") {
490
+ throw new Error("Callback must be a function");
491
+ }
492
+ getDisposeCallbacksCollection(node, true).push(callback);
493
+ }
494
+ function removeDisposeCallback(node, callback) {
495
+ var callbacksCollection = getDisposeCallbacksCollection(node, false);
496
+ if (callbacksCollection) {
497
+ arrayRemoveItem(callbacksCollection, callback);
498
+ if (callbacksCollection.length === 0) {
499
+ destroyCallbacksCollection(node);
500
+ }
501
+ }
502
+ }
503
+ function cleanNode(node) {
504
+ if (cleanableNodeTypes[node.nodeType]) {
505
+ cleanSingleNode(node);
506
+ if (cleanableNodeTypesWithDescendants[node.nodeType]) {
507
+ cleanNodesInList(node.getElementsByTagName("*"));
508
+ }
509
+ }
510
+ return node;
511
+ }
512
+ function removeNode(node) {
513
+ cleanNode(node);
514
+ if (node.parentNode) {
515
+ node.parentNode.removeChild(node);
516
+ }
517
+ }
518
+ var otherNodeCleanerFunctions = [];
519
+ function cleanjQueryData(node) {
520
+ var jQueryCleanNodeFn = jQueryInstance ? jQueryInstance.cleanData : null;
521
+ if (jQueryCleanNodeFn) {
522
+ jQueryCleanNodeFn([node]);
523
+ }
524
+ }
525
+ otherNodeCleanerFunctions.push(cleanjQueryData);
526
+
527
+ // ../utils/dist/dom/event.js
528
+ var knownEvents = {};
529
+ var knownEventTypesByEventName = {};
530
+ var keyEventTypeName = options_default.global.navigator && /Firefox\/2/i.test(options_default.global.navigator.userAgent) ? "KeyboardEvent" : "UIEvents";
531
+ knownEvents[keyEventTypeName] = ["keyup", "keydown", "keypress"];
532
+ knownEvents["MouseEvents"] = [
533
+ "click",
534
+ "dblclick",
535
+ "mousedown",
536
+ "mouseup",
537
+ "mousemove",
538
+ "mouseover",
539
+ "mouseout",
540
+ "mouseenter",
541
+ "mouseleave"
542
+ ];
543
+ objectForEach(knownEvents, function(eventType, knownEventsForType) {
544
+ if (knownEventsForType.length) {
545
+ for (var i = 0, j = knownEventsForType.length; i < j; i++) {
546
+ knownEventTypesByEventName[knownEventsForType[i]] = eventType;
547
+ }
548
+ }
549
+ });
550
+
551
+ // ../utils/dist/dom/manipulation.js
552
+ function setDomNodeChildren(domNode, childNodes2) {
553
+ emptyDomNode(domNode);
554
+ if (childNodes2) {
555
+ for (var i = 0, j = childNodes2.length; i < j; i++) {
556
+ domNode.appendChild(childNodes2[i]);
557
+ }
558
+ }
559
+ }
560
+ function replaceDomNodes(nodeToReplaceOrNodeArray, newNodesArray) {
561
+ var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;
562
+ if (nodesToReplaceArray.length > 0) {
563
+ var insertionPoint = nodesToReplaceArray[0];
564
+ var parent = insertionPoint.parentNode;
565
+ for (var i = 0, j = newNodesArray.length; i < j; i++) {
566
+ parent.insertBefore(newNodesArray[i], insertionPoint);
567
+ }
568
+ for (i = 0, j = nodesToReplaceArray.length; i < j; i++) {
569
+ removeNode(nodesToReplaceArray[i]);
570
+ }
571
+ }
572
+ }
573
+ function emptyDomNode(domNode) {
574
+ while (domNode.firstChild) {
575
+ removeNode(domNode.firstChild);
576
+ }
577
+ }
578
+
579
+ // ../utils/dist/dom/fixes.js
580
+ function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
581
+ if (continuousNodeArray.length) {
582
+ parentNode = parentNode.nodeType === 8 && parentNode.parentNode || parentNode;
583
+ while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) {
584
+ continuousNodeArray.splice(0, 1);
585
+ }
586
+ while (continuousNodeArray.length > 1 && continuousNodeArray[continuousNodeArray.length - 1].parentNode !== parentNode) {
587
+ continuousNodeArray.length--;
588
+ }
589
+ if (continuousNodeArray.length > 1) {
590
+ var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1];
591
+ continuousNodeArray.length = 0;
592
+ while (current !== last) {
593
+ continuousNodeArray.push(current);
594
+ current = current.nextSibling;
595
+ }
596
+ continuousNodeArray.push(last);
597
+ }
598
+ }
599
+ return continuousNodeArray;
600
+ }
601
+
602
+ // ../utils/dist/dom/virtualElements.js
603
+ var virtualElements_exports = {};
604
+ __export(virtualElements_exports, {
605
+ allowedBindings: () => allowedBindings,
606
+ childNodes: () => childNodes,
607
+ emptyNode: () => emptyNode,
608
+ endCommentRegex: () => endCommentRegex,
609
+ firstChild: () => firstChild,
610
+ getVirtualChildren: () => getVirtualChildren,
611
+ hasBindingValue: () => hasBindingValue,
612
+ insertAfter: () => insertAfter,
613
+ isEndComment: () => isEndComment,
614
+ isStartComment: () => isStartComment,
615
+ lastChild: () => lastChild,
616
+ nextSibling: () => nextSibling,
617
+ normaliseVirtualElementDomStructure: () => normaliseVirtualElementDomStructure,
618
+ prepend: () => prepend,
619
+ previousSibling: () => previousSibling,
620
+ setDomNodeChildren: () => setDomNodeChildren2,
621
+ startCommentRegex: () => startCommentRegex,
622
+ virtualNodeBindingValue: () => virtualNodeBindingValue
623
+ });
624
+ var commentNodesHaveTextProperty = options_default.document && options_default.document.createComment("test").text === "<!--test-->";
625
+ var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+([\s\S]+))?\s*-->$/ : /^\s*ko(?:\s+([\s\S]+))?\s*$/;
626
+ var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/;
627
+ var htmlTagsWithOptionallyClosingChildren = { "ul": true, "ol": true };
628
+ function isStartComment(node) {
629
+ return node.nodeType == 8 && startCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue);
630
+ }
631
+ function isEndComment(node) {
632
+ return node.nodeType == 8 && endCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue);
633
+ }
634
+ function isUnmatchedEndComment(node) {
635
+ return isEndComment(node) && !get(node, matchedEndCommentDataKey);
636
+ }
637
+ var matchedEndCommentDataKey = "__ko_matchedEndComment__";
638
+ function getVirtualChildren(startComment, allowUnbalanced) {
639
+ var currentNode = startComment;
640
+ var depth = 1;
641
+ var children = [];
642
+ while (currentNode = currentNode.nextSibling) {
643
+ if (isEndComment(currentNode)) {
644
+ set(currentNode, matchedEndCommentDataKey, true);
645
+ depth--;
646
+ if (depth === 0) {
647
+ return children;
648
+ }
649
+ }
650
+ children.push(currentNode);
651
+ if (isStartComment(currentNode)) {
652
+ depth++;
653
+ }
654
+ }
655
+ if (!allowUnbalanced) {
656
+ throw new Error("Cannot find closing comment tag to match: " + startComment.nodeValue);
657
+ }
658
+ return null;
659
+ }
660
+ function getMatchingEndComment(startComment, allowUnbalanced) {
661
+ var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced);
662
+ if (allVirtualChildren) {
663
+ if (allVirtualChildren.length > 0) {
664
+ return allVirtualChildren[allVirtualChildren.length - 1].nextSibling;
665
+ }
666
+ return startComment.nextSibling;
667
+ } else {
668
+ return null;
669
+ }
670
+ }
671
+ function getUnbalancedChildTags(node) {
672
+ var childNode = node.firstChild, captureRemaining = null;
673
+ if (childNode) {
674
+ do {
675
+ if (captureRemaining) {
676
+ captureRemaining.push(childNode);
677
+ } else if (isStartComment(childNode)) {
678
+ var matchingEndComment = getMatchingEndComment(childNode, true);
679
+ if (matchingEndComment) {
680
+ childNode = matchingEndComment;
681
+ } else {
682
+ captureRemaining = [childNode];
683
+ }
684
+ } else if (isEndComment(childNode)) {
685
+ captureRemaining = [childNode];
686
+ }
687
+ } while (childNode = childNode.nextSibling);
688
+ }
689
+ return captureRemaining;
690
+ }
691
+ var allowedBindings = {};
692
+ var hasBindingValue = isStartComment;
693
+ function childNodes(node) {
694
+ return isStartComment(node) ? getVirtualChildren(node) : node.childNodes;
695
+ }
696
+ function emptyNode(node) {
697
+ if (!isStartComment(node)) {
698
+ emptyDomNode(node);
699
+ } else {
700
+ var virtualChildren = childNodes(node);
701
+ for (var i = 0, j = virtualChildren.length; i < j; i++) {
702
+ removeNode(virtualChildren[i]);
703
+ }
704
+ }
705
+ }
706
+ function setDomNodeChildren2(node, childNodes2) {
707
+ if (!isStartComment(node)) {
708
+ setDomNodeChildren(node, childNodes2);
709
+ } else {
710
+ emptyNode(node);
711
+ const endCommentNode = node.nextSibling;
712
+ const parentNode = endCommentNode.parentNode;
713
+ for (var i = 0, j = childNodes2.length; i < j; ++i) {
714
+ parentNode.insertBefore(childNodes2[i], endCommentNode);
715
+ }
716
+ }
717
+ }
718
+ function prepend(containerNode, nodeToPrepend) {
719
+ if (!isStartComment(containerNode)) {
720
+ if (containerNode.firstChild) {
721
+ containerNode.insertBefore(nodeToPrepend, containerNode.firstChild);
722
+ } else {
723
+ containerNode.appendChild(nodeToPrepend);
724
+ }
725
+ } else {
726
+ containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling);
727
+ }
728
+ }
729
+ function insertAfter(containerNode, nodeToInsert, insertAfterNode) {
730
+ if (!insertAfterNode) {
731
+ prepend(containerNode, nodeToInsert);
732
+ } else if (!isStartComment(containerNode)) {
733
+ if (insertAfterNode.nextSibling) {
734
+ containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
735
+ } else {
736
+ containerNode.appendChild(nodeToInsert);
737
+ }
738
+ } else {
739
+ containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
740
+ }
741
+ }
742
+ function firstChild(node) {
743
+ if (!isStartComment(node)) {
744
+ if (node.firstChild && isEndComment(node.firstChild)) {
745
+ throw new Error("Found invalid end comment, as the first child of " + node.outerHTML);
746
+ }
747
+ return node.firstChild;
748
+ }
749
+ if (!node.nextSibling || isEndComment(node.nextSibling)) {
750
+ return null;
751
+ }
752
+ return node.nextSibling;
753
+ }
754
+ function lastChild(node) {
755
+ let nextChild = firstChild(node);
756
+ let lastChildNode;
757
+ do {
758
+ lastChildNode = nextChild;
759
+ } while (nextChild = nextSibling(nextChild));
760
+ return lastChildNode;
761
+ }
762
+ function nextSibling(node) {
763
+ if (isStartComment(node)) {
764
+ node = getMatchingEndComment(node);
765
+ }
766
+ if (node.nextSibling && isEndComment(node.nextSibling)) {
767
+ if (isUnmatchedEndComment(node.nextSibling)) {
768
+ throw Error("Found end comment without a matching opening comment, as next sibling of " + node.outerHTML);
769
+ }
770
+ return null;
771
+ } else {
772
+ return node.nextSibling;
773
+ }
774
+ }
775
+ function previousSibling(node) {
776
+ var depth = 0;
777
+ do {
778
+ if (node.nodeType === 8) {
779
+ if (isStartComment(node)) {
780
+ if (--depth === 0) {
781
+ return node;
782
+ }
783
+ } else if (isEndComment(node)) {
784
+ depth++;
785
+ }
786
+ } else {
787
+ if (depth === 0) {
788
+ return node;
789
+ }
790
+ }
791
+ } while (node = node.previousSibling);
792
+ }
793
+ function virtualNodeBindingValue(node) {
794
+ var regexMatch = (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex);
795
+ return regexMatch ? regexMatch[1] : null;
796
+ }
797
+ function normaliseVirtualElementDomStructure(elementVerified) {
798
+ if (!htmlTagsWithOptionallyClosingChildren[tagNameLower(elementVerified)]) {
799
+ return;
800
+ }
801
+ var childNode = elementVerified.firstChild;
802
+ if (childNode) {
803
+ do {
804
+ if (childNode.nodeType === 1) {
805
+ var unbalancedTags = getUnbalancedChildTags(childNode);
806
+ if (unbalancedTags) {
807
+ var nodeToInsertBefore = childNode.nextSibling;
808
+ for (var i = 0; i < unbalancedTags.length; i++) {
809
+ if (nodeToInsertBefore) {
810
+ elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore);
811
+ } else {
812
+ elementVerified.appendChild(unbalancedTags[i]);
813
+ }
814
+ }
815
+ }
816
+ }
817
+ } while (childNode = childNode.nextSibling);
818
+ }
819
+ }
820
+
821
+ // ../utils/dist/dom/html.js
822
+ var supportsTemplateTag = options_default.document && "content" in options_default.document.createElement("template");
823
+
824
+ // ../utils/dist/dom/selectExtensions.js
825
+ var hasDomDataExpandoProperty = Symbol("Knockout selectExtensions hasDomDataProperty");
826
+ var selectExtensions = {
827
+ optionValueDomDataKey: nextKey(),
828
+ readValue: function(element) {
829
+ switch (tagNameLower(element)) {
830
+ case "option":
831
+ if (element[hasDomDataExpandoProperty] === true) {
832
+ return get(element, selectExtensions.optionValueDomDataKey);
833
+ }
834
+ return element.value;
835
+ case "select":
836
+ return element.selectedIndex >= 0 ? selectExtensions.readValue(element.options[element.selectedIndex]) : void 0;
837
+ default:
838
+ return element.value;
839
+ }
840
+ },
841
+ writeValue: function(element, value, allowUnset) {
842
+ switch (tagNameLower(element)) {
843
+ case "option":
844
+ if (typeof value === "string") {
845
+ set(element, selectExtensions.optionValueDomDataKey, void 0);
846
+ if (hasDomDataExpandoProperty in element) {
847
+ delete element[hasDomDataExpandoProperty];
848
+ }
849
+ element.value = value;
850
+ } else {
851
+ set(element, selectExtensions.optionValueDomDataKey, value);
852
+ element[hasDomDataExpandoProperty] = true;
853
+ element.value = typeof value === "number" ? value : "";
854
+ }
855
+ break;
856
+ case "select":
857
+ if (value === "" || value === null) {
858
+ value = void 0;
859
+ }
860
+ var selection = -1;
861
+ for (let i = 0, n = element.options.length, optionValue; i < n; ++i) {
862
+ optionValue = selectExtensions.readValue(element.options[i]);
863
+ const strictEqual = optionValue === value;
864
+ const blankEqual = optionValue === "" && value === void 0;
865
+ const numericEqual = typeof value === "number" && Number(optionValue) === value;
866
+ if (strictEqual || blankEqual || numericEqual) {
867
+ selection = i;
868
+ break;
869
+ }
870
+ }
871
+ if (allowUnset || selection >= 0 || value === void 0 && element.size > 1) {
872
+ element.selectedIndex = selection;
873
+ }
874
+ break;
875
+ default:
876
+ if (value === null || value === void 0) {
877
+ value = "";
878
+ }
879
+ element.value = value;
880
+ break;
881
+ }
882
+ }
883
+ };
884
+
885
+ // ../utils/dist/tasks.js
886
+ var tasks_exports = {};
887
+ __export(tasks_exports, {
888
+ cancel: () => cancel,
889
+ resetForTesting: () => resetForTesting,
890
+ runEarly: () => processTasks,
891
+ schedule: () => schedule
892
+ });
893
+ var taskQueue = [];
894
+ var taskQueueLength = 0;
895
+ var nextHandle = 1;
896
+ var nextIndexToProcess = 0;
897
+ var w = options_default.global;
898
+ if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {
899
+ options_default.taskScheduler = function(callback) {
900
+ var div = w.document.createElement("div");
901
+ new w.MutationObserver(callback).observe(div, { attributes: true });
902
+ return function() {
903
+ div.classList.toggle("foo");
904
+ };
905
+ }(scheduledProcess);
906
+ } else if (w && w.document && "onreadystatechange" in w.document.createElement("script")) {
907
+ options_default.taskScheduler = function(callback) {
908
+ var script = document.createElement("script");
909
+ script.onreadystatechange = function() {
910
+ script.onreadystatechange = null;
911
+ document.documentElement.removeChild(script);
912
+ script = null;
913
+ callback();
914
+ };
915
+ document.documentElement.appendChild(script);
916
+ };
917
+ } else {
918
+ options_default.taskScheduler = function(callback) {
919
+ setTimeout(callback, 0);
920
+ };
921
+ }
922
+ function processTasks() {
923
+ if (taskQueueLength) {
924
+ var mark = taskQueueLength, countMarks = 0;
925
+ for (var task; nextIndexToProcess < taskQueueLength; ) {
926
+ if (task = taskQueue[nextIndexToProcess++]) {
927
+ if (nextIndexToProcess > mark) {
928
+ if (++countMarks >= 5e3) {
929
+ nextIndexToProcess = taskQueueLength;
930
+ deferError(Error("'Too much recursion' after processing " + countMarks + " task groups."));
931
+ break;
932
+ }
933
+ mark = taskQueueLength;
934
+ }
935
+ try {
936
+ task();
937
+ } catch (ex) {
938
+ deferError(ex);
939
+ }
940
+ }
941
+ }
942
+ }
943
+ }
944
+ function scheduledProcess() {
945
+ processTasks();
946
+ nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
947
+ }
948
+ function scheduleTaskProcessing() {
949
+ options_default.taskScheduler(scheduledProcess);
950
+ }
951
+ function schedule(func) {
952
+ if (!taskQueueLength) {
953
+ scheduleTaskProcessing();
954
+ }
955
+ taskQueue[taskQueueLength++] = func;
956
+ return nextHandle++;
957
+ }
958
+ function cancel(handle) {
959
+ var index = handle - (nextHandle - taskQueueLength);
960
+ if (index >= nextIndexToProcess && index < taskQueueLength) {
961
+ taskQueue[index] = null;
962
+ }
963
+ }
964
+ function resetForTesting() {
965
+ var length = taskQueueLength - nextIndexToProcess;
966
+ nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
967
+ return length;
968
+ }
969
+
970
+ // ../observable/dist/dependencyDetection.js
971
+ var dependencyDetection_exports = {};
972
+ __export(dependencyDetection_exports, {
973
+ begin: () => begin,
974
+ end: () => end,
975
+ getDependencies: () => getDependencies,
976
+ getDependenciesCount: () => getDependenciesCount,
977
+ ignore: () => ignore,
978
+ ignoreDependencies: () => ignore,
979
+ isInitial: () => isInitial,
980
+ registerDependency: () => registerDependency
981
+ });
982
+
983
+ // ../observable/dist/subscribableSymbol.js
984
+ var SUBSCRIBABLE_SYM = Symbol("Knockout Subscribable");
985
+ function isSubscribable(instance) {
986
+ return instance && instance[SUBSCRIBABLE_SYM] || false;
987
+ }
988
+
989
+ // ../observable/dist/dependencyDetection.js
990
+ var outerFrames = [];
991
+ var currentFrame;
992
+ var lastId = 0;
993
+ function getId() {
994
+ return ++lastId;
995
+ }
996
+ function begin(options2) {
997
+ outerFrames.push(currentFrame);
998
+ currentFrame = options2;
999
+ }
1000
+ function end() {
1001
+ currentFrame = outerFrames.pop();
1002
+ }
1003
+ function registerDependency(subscribable2) {
1004
+ if (currentFrame) {
1005
+ if (!isSubscribable(subscribable2)) {
1006
+ throw new Error("Only subscribable things can act as dependencies");
1007
+ }
1008
+ currentFrame.callback.call(currentFrame.callbackTarget, subscribable2, subscribable2._id || (subscribable2._id = getId()));
1009
+ }
1010
+ }
1011
+ function ignore(callback, callbackTarget, callbackArgs) {
1012
+ try {
1013
+ begin();
1014
+ return callback.apply(callbackTarget, callbackArgs || []);
1015
+ } finally {
1016
+ end();
1017
+ }
1018
+ }
1019
+ function getDependenciesCount() {
1020
+ if (currentFrame) {
1021
+ return currentFrame.computed.getDependenciesCount();
1022
+ }
1023
+ }
1024
+ function getDependencies() {
1025
+ if (currentFrame) {
1026
+ return currentFrame.computed.getDependencies();
1027
+ }
1028
+ }
1029
+ function isInitial() {
1030
+ if (currentFrame) {
1031
+ return currentFrame.isInitial;
1032
+ }
1033
+ }
1034
+
1035
+ // ../observable/dist/defer.js
1036
+ function deferUpdates(target) {
1037
+ if (target._deferUpdates) {
1038
+ return;
1039
+ }
1040
+ target._deferUpdates = true;
1041
+ target.limit(function(callback) {
1042
+ let handle;
1043
+ let ignoreUpdates = false;
1044
+ return function() {
1045
+ if (!ignoreUpdates) {
1046
+ tasks_exports.cancel(handle);
1047
+ handle = tasks_exports.schedule(callback);
1048
+ try {
1049
+ ignoreUpdates = true;
1050
+ target.notifySubscribers(void 0, "dirty");
1051
+ } finally {
1052
+ ignoreUpdates = false;
1053
+ }
1054
+ }
1055
+ };
1056
+ });
1057
+ }
1058
+
1059
+ // ../observable/dist/Subscription.js
1060
+ var Subscription = class {
1061
+ constructor(target, observer, disposeCallback) {
1062
+ this._target = target;
1063
+ this._callback = observer.next;
1064
+ this._disposeCallback = disposeCallback;
1065
+ this._isDisposed = false;
1066
+ this._domNodeDisposalCallback = null;
1067
+ }
1068
+ dispose() {
1069
+ if (this._domNodeDisposalCallback) {
1070
+ removeDisposeCallback(this._node, this._domNodeDisposalCallback);
1071
+ }
1072
+ this._isDisposed = true;
1073
+ this._disposeCallback();
1074
+ }
1075
+ disposeWhenNodeIsRemoved(node) {
1076
+ this._node = node;
1077
+ addDisposeCallback(node, this._domNodeDisposalCallback = this.dispose.bind(this));
1078
+ }
1079
+ unsubscribe() {
1080
+ this.dispose();
1081
+ }
1082
+ get closed() {
1083
+ return this._isDisposed;
1084
+ }
1085
+ };
1086
+
1087
+ // ../observable/dist/extenders.js
1088
+ var primitiveTypes = {
1089
+ "undefined": 1,
1090
+ "boolean": 1,
1091
+ "number": 1,
1092
+ "string": 1
1093
+ };
1094
+ function valuesArePrimitiveAndEqual(a, b) {
1095
+ var oldValueIsPrimitive = a === null || typeof a in primitiveTypes;
1096
+ return oldValueIsPrimitive ? a === b : false;
1097
+ }
1098
+ function applyExtenders(requestedExtenders) {
1099
+ var target = this;
1100
+ if (requestedExtenders) {
1101
+ objectForEach(requestedExtenders, function(key, value) {
1102
+ var extenderHandler = extenders[key];
1103
+ if (typeof extenderHandler === "function") {
1104
+ target = extenderHandler(target, value) || target;
1105
+ } else {
1106
+ options_default.onError(new Error("Extender not found: " + key));
1107
+ }
1108
+ });
1109
+ }
1110
+ return target;
1111
+ }
1112
+ function notify(target, notifyWhen) {
1113
+ target.equalityComparer = notifyWhen == "always" ? null : valuesArePrimitiveAndEqual;
1114
+ }
1115
+ function deferred(target, option) {
1116
+ if (option !== true) {
1117
+ throw new Error("The 'deferred' extender only accepts the value 'true', because it is not supported to turn deferral off once enabled.");
1118
+ }
1119
+ deferUpdates(target);
1120
+ }
1121
+ function rateLimit(target, options2) {
1122
+ var timeout, method, limitFunction;
1123
+ if (typeof options2 === "number") {
1124
+ timeout = options2;
1125
+ } else {
1126
+ timeout = options2.timeout;
1127
+ method = options2.method;
1128
+ }
1129
+ target._deferUpdates = false;
1130
+ limitFunction = method === "notifyWhenChangesStop" ? debounce : throttle;
1131
+ target.limit(function(callback) {
1132
+ return limitFunction(callback, timeout);
1133
+ });
1134
+ }
1135
+ var extenders = {
1136
+ notify,
1137
+ deferred,
1138
+ rateLimit
1139
+ };
1140
+
1141
+ // ../observable/dist/subscribable.js
1142
+ var LATEST_VALUE = Symbol("Knockout latest value");
1143
+ if (!Symbol.observable) {
1144
+ Symbol.observable = Symbol.for("@tko/Symbol.observable");
1145
+ }
1146
+ function subscribable() {
1147
+ Object.setPrototypeOf(this, ko_subscribable_fn);
1148
+ ko_subscribable_fn.init(this);
1149
+ }
1150
+ var defaultEvent = "change";
1151
+ var ko_subscribable_fn = {
1152
+ [SUBSCRIBABLE_SYM]: true,
1153
+ [Symbol.observable]() {
1154
+ return this;
1155
+ },
1156
+ init(instance) {
1157
+ instance._subscriptions = { change: [] };
1158
+ instance._versionNumber = 1;
1159
+ },
1160
+ subscribe(callback, callbackTarget, event) {
1161
+ const isTC39Callback = typeof callback === "object" && callback.next;
1162
+ event = event || defaultEvent;
1163
+ const observer = isTC39Callback ? callback : {
1164
+ next: callbackTarget ? callback.bind(callbackTarget) : callback
1165
+ };
1166
+ const subscriptionInstance = new Subscription(this, observer, () => {
1167
+ arrayRemoveItem(this._subscriptions[event], subscriptionInstance);
1168
+ if (this.afterSubscriptionRemove) {
1169
+ this.afterSubscriptionRemove(event);
1170
+ }
1171
+ });
1172
+ if (this.beforeSubscriptionAdd) {
1173
+ this.beforeSubscriptionAdd(event);
1174
+ }
1175
+ if (!this._subscriptions[event]) {
1176
+ this._subscriptions[event] = [];
1177
+ }
1178
+ this._subscriptions[event].push(subscriptionInstance);
1179
+ if (isTC39Callback && LATEST_VALUE in this) {
1180
+ observer.next(this[LATEST_VALUE]);
1181
+ }
1182
+ return subscriptionInstance;
1183
+ },
1184
+ notifySubscribers(valueToNotify, event) {
1185
+ event = event || defaultEvent;
1186
+ if (event === defaultEvent) {
1187
+ this.updateVersion();
1188
+ }
1189
+ if (this.hasSubscriptionsForEvent(event)) {
1190
+ const subs = event === defaultEvent && this._changeSubscriptions || [...this._subscriptions[event]];
1191
+ try {
1192
+ begin();
1193
+ for (let i = 0, subscriptionInstance; subscriptionInstance = subs[i]; ++i) {
1194
+ if (!subscriptionInstance._isDisposed) {
1195
+ subscriptionInstance._callback(valueToNotify);
1196
+ }
1197
+ }
1198
+ } finally {
1199
+ end();
1200
+ }
1201
+ }
1202
+ },
1203
+ getVersion() {
1204
+ return this._versionNumber;
1205
+ },
1206
+ hasChanged(versionToCheck) {
1207
+ return this.getVersion() !== versionToCheck;
1208
+ },
1209
+ updateVersion() {
1210
+ ++this._versionNumber;
1211
+ },
1212
+ hasSubscriptionsForEvent(event) {
1213
+ return this._subscriptions[event] && this._subscriptions[event].length;
1214
+ },
1215
+ getSubscriptionsCount(event) {
1216
+ if (event) {
1217
+ return this._subscriptions[event] && this._subscriptions[event].length || 0;
1218
+ } else {
1219
+ var total = 0;
1220
+ objectForEach(this._subscriptions, function(eventName, subscriptions) {
1221
+ if (eventName !== "dirty") {
1222
+ total += subscriptions.length;
1223
+ }
1224
+ });
1225
+ return total;
1226
+ }
1227
+ },
1228
+ isDifferent(oldValue, newValue) {
1229
+ return !this.equalityComparer || !this.equalityComparer(oldValue, newValue);
1230
+ },
1231
+ once(cb) {
1232
+ const subs = this.subscribe((nv) => {
1233
+ subs.dispose();
1234
+ cb(nv);
1235
+ });
1236
+ },
1237
+ when(test, returnValue) {
1238
+ const current = this.peek();
1239
+ const givenRv = arguments.length > 1;
1240
+ const testFn = typeof test === "function" ? test : (v) => v === test;
1241
+ if (testFn(current)) {
1242
+ return options_default.Promise.resolve(givenRv ? returnValue : current);
1243
+ }
1244
+ return new options_default.Promise((resolve, reject) => {
1245
+ const subs = this.subscribe((newValue) => {
1246
+ if (testFn(newValue)) {
1247
+ subs.dispose();
1248
+ resolve(givenRv ? returnValue : newValue);
1249
+ }
1250
+ });
1251
+ });
1252
+ },
1253
+ yet(test, ...args) {
1254
+ const testFn = typeof test === "function" ? test : (v) => v === test;
1255
+ const negated = (v) => !testFn(v);
1256
+ return this.when(negated, ...args);
1257
+ },
1258
+ next() {
1259
+ return new Promise((resolve) => this.once(resolve));
1260
+ },
1261
+ toString() {
1262
+ return "[object Object]";
1263
+ },
1264
+ extend: applyExtenders
1265
+ };
1266
+ Object.setPrototypeOf(ko_subscribable_fn, Function.prototype);
1267
+ subscribable.fn = ko_subscribable_fn;
1268
+
1269
+ // ../observable/dist/observable.js
1270
+ function observable(initialValue) {
1271
+ function Observable() {
1272
+ if (arguments.length > 0) {
1273
+ if (Observable.isDifferent(Observable[LATEST_VALUE], arguments[0])) {
1274
+ Observable.valueWillMutate();
1275
+ Observable[LATEST_VALUE] = arguments[0];
1276
+ Observable.valueHasMutated();
1277
+ }
1278
+ return this;
1279
+ } else {
1280
+ registerDependency(Observable);
1281
+ return Observable[LATEST_VALUE];
1282
+ }
1283
+ }
1284
+ overwriteLengthPropertyIfSupported(Observable, { value: void 0 });
1285
+ Observable[LATEST_VALUE] = initialValue;
1286
+ subscribable.fn.init(Observable);
1287
+ Object.setPrototypeOf(Observable, observable.fn);
1288
+ if (options_default.deferUpdates) {
1289
+ deferUpdates(Observable);
1290
+ }
1291
+ return Observable;
1292
+ }
1293
+ observable.fn = {
1294
+ equalityComparer: valuesArePrimitiveAndEqual,
1295
+ peek() {
1296
+ return this[LATEST_VALUE];
1297
+ },
1298
+ valueHasMutated() {
1299
+ this.notifySubscribers(this[LATEST_VALUE], "spectate");
1300
+ this.notifySubscribers(this[LATEST_VALUE]);
1301
+ },
1302
+ valueWillMutate() {
1303
+ this.notifySubscribers(this[LATEST_VALUE], "beforeChange");
1304
+ },
1305
+ modify(fn, peek22 = true) {
1306
+ return this(fn(peek22 ? this.peek() : this()));
1307
+ },
1308
+ isWriteable: true
1309
+ };
1310
+ function limitNotifySubscribers(value, event) {
1311
+ if (!event || event === defaultEvent) {
1312
+ this._limitChange(value);
1313
+ } else if (event === "beforeChange") {
1314
+ this._limitBeforeChange(value);
1315
+ } else {
1316
+ this._origNotifySubscribers(value, event);
1317
+ }
1318
+ }
1319
+ subscribable.fn.limit = function limit(limitFunction) {
1320
+ var self = this;
1321
+ var selfIsObservable = isObservable(self);
1322
+ var beforeChange = "beforeChange";
1323
+ var ignoreBeforeChange, notifyNextChange, previousValue, pendingValue, didUpdate;
1324
+ if (!self._origNotifySubscribers) {
1325
+ self._origNotifySubscribers = self.notifySubscribers;
1326
+ self.notifySubscribers = limitNotifySubscribers;
1327
+ }
1328
+ var finish = limitFunction(function() {
1329
+ self._notificationIsPending = false;
1330
+ if (selfIsObservable && pendingValue === self) {
1331
+ pendingValue = self._evalIfChanged ? self._evalIfChanged() : self();
1332
+ }
1333
+ const shouldNotify = notifyNextChange || didUpdate && self.isDifferent(previousValue, pendingValue);
1334
+ self._notifyNextChange = didUpdate = ignoreBeforeChange = false;
1335
+ if (shouldNotify) {
1336
+ self._origNotifySubscribers(previousValue = pendingValue);
1337
+ }
1338
+ });
1339
+ Object.assign(self, {
1340
+ _limitChange(value, isDirty) {
1341
+ if (!isDirty || !self._notificationIsPending) {
1342
+ didUpdate = !isDirty;
1343
+ }
1344
+ self._changeSubscriptions = [...self._subscriptions[defaultEvent]];
1345
+ self._notificationIsPending = ignoreBeforeChange = true;
1346
+ pendingValue = value;
1347
+ finish();
1348
+ },
1349
+ _limitBeforeChange(value) {
1350
+ if (!ignoreBeforeChange) {
1351
+ previousValue = value;
1352
+ self._origNotifySubscribers(value, beforeChange);
1353
+ }
1354
+ },
1355
+ _notifyNextChangeIfValueIsDifferent() {
1356
+ if (self.isDifferent(previousValue, self.peek(true))) {
1357
+ notifyNextChange = true;
1358
+ }
1359
+ },
1360
+ _recordUpdate() {
1361
+ didUpdate = true;
1362
+ }
1363
+ });
1364
+ };
1365
+ Object.setPrototypeOf(observable.fn, subscribable.fn);
1366
+ var protoProperty = observable.protoProperty = options_default.protoProperty;
1367
+ observable.fn[protoProperty] = observable;
1368
+ observable.observablePrototypes = /* @__PURE__ */ new Set([observable]);
1369
+ function isObservable(instance) {
1370
+ const proto = typeof instance === "function" && instance[protoProperty];
1371
+ if (proto && !observable.observablePrototypes.has(proto)) {
1372
+ throw Error("Invalid object that looks like an observable; possibly from another Knockout instance");
1373
+ }
1374
+ return !!proto;
1375
+ }
1376
+ function unwrap(value) {
1377
+ return isObservable(value) ? value() : value;
1378
+ }
1379
+ function isWriteableObservable(instance) {
1380
+ return isObservable(instance) && instance.isWriteable;
1381
+ }
1382
+
1383
+ // ../observable/dist/observableArray.changeTracking.js
1384
+ var arrayChangeEventName = "arrayChange";
1385
+ function trackArrayChanges(target, options2) {
1386
+ target.compareArrayOptions = {};
1387
+ if (options2 && typeof options2 === "object") {
1388
+ extend(target.compareArrayOptions, options2);
1389
+ }
1390
+ target.compareArrayOptions.sparse = true;
1391
+ if (target.cacheDiffForKnownOperation) {
1392
+ return;
1393
+ }
1394
+ let trackingChanges = false;
1395
+ let cachedDiff = null;
1396
+ let arrayChangeSubscription;
1397
+ let pendingNotifications = 0;
1398
+ let underlyingNotifySubscribersFunction;
1399
+ let underlyingBeforeSubscriptionAddFunction = target.beforeSubscriptionAdd;
1400
+ let underlyingAfterSubscriptionRemoveFunction = target.afterSubscriptionRemove;
1401
+ target.beforeSubscriptionAdd = function(event) {
1402
+ if (underlyingBeforeSubscriptionAddFunction) {
1403
+ underlyingBeforeSubscriptionAddFunction.call(target, event);
1404
+ }
1405
+ if (event === arrayChangeEventName) {
1406
+ trackChanges();
1407
+ }
1408
+ };
1409
+ target.afterSubscriptionRemove = function(event) {
1410
+ if (underlyingAfterSubscriptionRemoveFunction) {
1411
+ underlyingAfterSubscriptionRemoveFunction.call(target, event);
1412
+ }
1413
+ if (event === arrayChangeEventName && !target.hasSubscriptionsForEvent(arrayChangeEventName)) {
1414
+ if (underlyingNotifySubscribersFunction) {
1415
+ target.notifySubscribers = underlyingNotifySubscribersFunction;
1416
+ underlyingNotifySubscribersFunction = void 0;
1417
+ }
1418
+ if (arrayChangeSubscription) {
1419
+ arrayChangeSubscription.dispose();
1420
+ }
1421
+ arrayChangeSubscription = null;
1422
+ trackingChanges = false;
1423
+ }
1424
+ };
1425
+ function trackChanges() {
1426
+ if (trackingChanges) {
1427
+ return;
1428
+ }
1429
+ trackingChanges = true;
1430
+ underlyingNotifySubscribersFunction = target["notifySubscribers"];
1431
+ target.notifySubscribers = function(valueToNotify, event) {
1432
+ if (!event || event === defaultEvent) {
1433
+ ++pendingNotifications;
1434
+ }
1435
+ return underlyingNotifySubscribersFunction.apply(this, arguments);
1436
+ };
1437
+ var previousContents = [].concat(target.peek() === void 0 ? [] : target.peek());
1438
+ cachedDiff = null;
1439
+ arrayChangeSubscription = target.subscribe(function(currentContents) {
1440
+ let changes;
1441
+ currentContents = [].concat(currentContents || []);
1442
+ if (target.hasSubscriptionsForEvent(arrayChangeEventName)) {
1443
+ changes = getChanges(previousContents, currentContents);
1444
+ }
1445
+ previousContents = currentContents;
1446
+ cachedDiff = null;
1447
+ pendingNotifications = 0;
1448
+ if (changes && changes.length) {
1449
+ target.notifySubscribers(changes, arrayChangeEventName);
1450
+ }
1451
+ });
1452
+ }
1453
+ function getChanges(previousContents, currentContents) {
1454
+ if (!cachedDiff || pendingNotifications > 1) {
1455
+ cachedDiff = trackArrayChanges.compareArrays(previousContents, currentContents, target.compareArrayOptions);
1456
+ }
1457
+ return cachedDiff;
1458
+ }
1459
+ target.cacheDiffForKnownOperation = function(rawArray, operationName, args) {
1460
+ if (!trackingChanges || pendingNotifications) {
1461
+ return;
1462
+ }
1463
+ var diff = [], arrayLength = rawArray.length, argsLength = args.length, offset = 0;
1464
+ function pushDiff(status, value, index) {
1465
+ return diff[diff.length] = { "status": status, "value": value, "index": index };
1466
+ }
1467
+ switch (operationName) {
1468
+ case "push":
1469
+ offset = arrayLength;
1470
+ case "unshift":
1471
+ for (let index = 0; index < argsLength; index++) {
1472
+ pushDiff("added", args[index], offset + index);
1473
+ }
1474
+ break;
1475
+ case "pop":
1476
+ offset = arrayLength - 1;
1477
+ case "shift":
1478
+ if (arrayLength) {
1479
+ pushDiff("deleted", rawArray[offset], offset);
1480
+ }
1481
+ break;
1482
+ case "splice":
1483
+ var startIndex = Math.min(Math.max(0, args[0] < 0 ? arrayLength + args[0] : args[0]), arrayLength), endDeleteIndex = argsLength === 1 ? arrayLength : Math.min(startIndex + (args[1] || 0), arrayLength), endAddIndex = startIndex + argsLength - 2, endIndex = Math.max(endDeleteIndex, endAddIndex), additions = [], deletions = [];
1484
+ for (let index = startIndex, argsIndex = 2; index < endIndex; ++index, ++argsIndex) {
1485
+ if (index < endDeleteIndex) {
1486
+ deletions.push(pushDiff("deleted", rawArray[index], index));
1487
+ }
1488
+ if (index < endAddIndex) {
1489
+ additions.push(pushDiff("added", args[argsIndex], index));
1490
+ }
1491
+ }
1492
+ findMovesInArrayComparison(deletions, additions);
1493
+ break;
1494
+ default:
1495
+ return;
1496
+ }
1497
+ cachedDiff = diff;
1498
+ };
1499
+ }
1500
+ trackArrayChanges.compareArrays = compareArrays;
1501
+ extenders.trackArrayChanges = trackArrayChanges;
1502
+
1503
+ // ../observable/dist/observableArray.js
1504
+ function observableArray(initialValues) {
1505
+ initialValues = initialValues || [];
1506
+ if (typeof initialValues !== "object" || !("length" in initialValues)) {
1507
+ throw new Error("The argument passed when initializing an observable array must be an array, or null, or undefined.");
1508
+ }
1509
+ var result = observable(initialValues);
1510
+ Object.setPrototypeOf(result, observableArray.fn);
1511
+ trackArrayChanges(result);
1512
+ overwriteLengthPropertyIfSupported(result, { get: () => result().length });
1513
+ return result;
1514
+ }
1515
+ observableArray.fn = {
1516
+ remove(valueOrPredicate) {
1517
+ var underlyingArray = this.peek();
1518
+ var removedValues = [];
1519
+ var predicate = typeof valueOrPredicate === "function" && !isObservable(valueOrPredicate) ? valueOrPredicate : function(value2) {
1520
+ return value2 === valueOrPredicate;
1521
+ };
1522
+ for (var i = 0; i < underlyingArray.length; i++) {
1523
+ var value = underlyingArray[i];
1524
+ if (predicate(value)) {
1525
+ if (removedValues.length === 0) {
1526
+ this.valueWillMutate();
1527
+ }
1528
+ if (underlyingArray[i] !== value) {
1529
+ throw Error("Array modified during remove; cannot remove item");
1530
+ }
1531
+ removedValues.push(value);
1532
+ underlyingArray.splice(i, 1);
1533
+ i--;
1534
+ }
1535
+ }
1536
+ if (removedValues.length) {
1537
+ this.valueHasMutated();
1538
+ }
1539
+ return removedValues;
1540
+ },
1541
+ removeAll(arrayOfValues) {
1542
+ if (arrayOfValues === void 0) {
1543
+ var underlyingArray = this.peek();
1544
+ var allValues = underlyingArray.slice(0);
1545
+ this.valueWillMutate();
1546
+ underlyingArray.splice(0, underlyingArray.length);
1547
+ this.valueHasMutated();
1548
+ return allValues;
1549
+ }
1550
+ if (!arrayOfValues) {
1551
+ return [];
1552
+ }
1553
+ return this["remove"](function(value) {
1554
+ return arrayIndexOf(arrayOfValues, value) >= 0;
1555
+ });
1556
+ },
1557
+ destroy(valueOrPredicate) {
1558
+ var underlyingArray = this.peek();
1559
+ var predicate = typeof valueOrPredicate === "function" && !isObservable(valueOrPredicate) ? valueOrPredicate : function(value2) {
1560
+ return value2 === valueOrPredicate;
1561
+ };
1562
+ this.valueWillMutate();
1563
+ for (var i = underlyingArray.length - 1; i >= 0; i--) {
1564
+ var value = underlyingArray[i];
1565
+ if (predicate(value)) {
1566
+ value["_destroy"] = true;
1567
+ }
1568
+ }
1569
+ this.valueHasMutated();
1570
+ },
1571
+ destroyAll(arrayOfValues) {
1572
+ if (arrayOfValues === void 0) {
1573
+ return this.destroy(function() {
1574
+ return true;
1575
+ });
1576
+ }
1577
+ if (!arrayOfValues) {
1578
+ return [];
1579
+ }
1580
+ return this.destroy(function(value) {
1581
+ return arrayIndexOf(arrayOfValues, value) >= 0;
1582
+ });
1583
+ },
1584
+ indexOf(item) {
1585
+ return arrayIndexOf(this(), item);
1586
+ },
1587
+ replace(oldItem, newItem) {
1588
+ var index = this.indexOf(oldItem);
1589
+ if (index >= 0) {
1590
+ this.valueWillMutate();
1591
+ this.peek()[index] = newItem;
1592
+ this.valueHasMutated();
1593
+ }
1594
+ },
1595
+ sorted(compareFn) {
1596
+ return [...this()].sort(compareFn);
1597
+ },
1598
+ reversed() {
1599
+ return [...this()].reverse();
1600
+ },
1601
+ [Symbol.iterator]: function* () {
1602
+ yield* this();
1603
+ }
1604
+ };
1605
+ Object.setPrototypeOf(observableArray.fn, observable.fn);
1606
+ arrayForEach(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function(methodName) {
1607
+ observableArray.fn[methodName] = function() {
1608
+ var underlyingArray = this.peek();
1609
+ this.valueWillMutate();
1610
+ this.cacheDiffForKnownOperation(underlyingArray, methodName, arguments);
1611
+ var methodCallResult = underlyingArray[methodName].apply(underlyingArray, arguments);
1612
+ this.valueHasMutated();
1613
+ return methodCallResult === underlyingArray ? this : methodCallResult;
1614
+ };
1615
+ });
1616
+ arrayForEach(["slice"], function(methodName) {
1617
+ observableArray.fn[methodName] = function() {
1618
+ var underlyingArray = this();
1619
+ return underlyingArray[methodName].apply(underlyingArray, arguments);
1620
+ };
1621
+ });
1622
+ observableArray.trackArrayChanges = trackArrayChanges;
1623
+
1624
+ // ../computed/dist/computed.js
1625
+ var computedState = createSymbolOrString("_state");
1626
+ var DISPOSED_STATE = {
1627
+ dependencyTracking: null,
1628
+ dependenciesCount: 0,
1629
+ isDisposed: true,
1630
+ isStale: false,
1631
+ isDirty: false,
1632
+ isSleeping: false,
1633
+ disposeWhenNodeIsRemoved: null,
1634
+ readFunction: null,
1635
+ _options: null
1636
+ };
1637
+ function computed(evaluatorFunctionOrOptions, evaluatorFunctionTarget, options2) {
1638
+ if (typeof evaluatorFunctionOrOptions === "object") {
1639
+ options2 = evaluatorFunctionOrOptions;
1640
+ } else {
1641
+ options2 = options2 || {};
1642
+ if (evaluatorFunctionOrOptions) {
1643
+ options2.read = evaluatorFunctionOrOptions;
1644
+ }
1645
+ }
1646
+ if (typeof options2.read !== "function") {
1647
+ throw Error("Pass a function that returns the value of the computed");
1648
+ }
1649
+ var writeFunction = options2.write;
1650
+ var state = {
1651
+ latestValue: void 0,
1652
+ isStale: true,
1653
+ isDirty: true,
1654
+ isBeingEvaluated: false,
1655
+ suppressDisposalUntilDisposeWhenReturnsFalse: false,
1656
+ isDisposed: false,
1657
+ pure: false,
1658
+ isSleeping: false,
1659
+ readFunction: options2.read,
1660
+ evaluatorFunctionTarget: evaluatorFunctionTarget || options2.owner,
1661
+ disposeWhenNodeIsRemoved: options2.disposeWhenNodeIsRemoved || options2.disposeWhenNodeIsRemoved || null,
1662
+ disposeWhen: options2.disposeWhen || options2.disposeWhen,
1663
+ domNodeDisposalCallback: null,
1664
+ dependencyTracking: {},
1665
+ dependenciesCount: 0,
1666
+ evaluationTimeoutInstance: null
1667
+ };
1668
+ function computedObservable() {
1669
+ if (arguments.length > 0) {
1670
+ if (typeof writeFunction === "function") {
1671
+ writeFunction.apply(state.evaluatorFunctionTarget, arguments);
1672
+ } else {
1673
+ throw new Error("Cannot write a value to a computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.");
1674
+ }
1675
+ return this;
1676
+ } else {
1677
+ if (!state.isDisposed) {
1678
+ dependencyDetection_exports.registerDependency(computedObservable);
1679
+ }
1680
+ if (state.isDirty || state.isSleeping && computedObservable.haveDependenciesChanged()) {
1681
+ computedObservable.evaluateImmediate();
1682
+ }
1683
+ return state.latestValue;
1684
+ }
1685
+ }
1686
+ computedObservable[computedState] = state;
1687
+ computedObservable.isWriteable = typeof writeFunction === "function";
1688
+ subscribable.fn.init(computedObservable);
1689
+ Object.setPrototypeOf(computedObservable, computed.fn);
1690
+ if (options2.pure) {
1691
+ state.pure = true;
1692
+ state.isSleeping = true;
1693
+ extend(computedObservable, pureComputedOverrides);
1694
+ } else if (options2.deferEvaluation) {
1695
+ extend(computedObservable, deferEvaluationOverrides);
1696
+ }
1697
+ if (options_default.deferUpdates) {
1698
+ extenders.deferred(computedObservable, true);
1699
+ }
1700
+ if (options_default.debug) {
1701
+ computedObservable._options = options2;
1702
+ }
1703
+ if (state.disposeWhenNodeIsRemoved) {
1704
+ state.suppressDisposalUntilDisposeWhenReturnsFalse = true;
1705
+ if (!state.disposeWhenNodeIsRemoved.nodeType) {
1706
+ state.disposeWhenNodeIsRemoved = null;
1707
+ }
1708
+ }
1709
+ if (!state.isSleeping && !options2.deferEvaluation) {
1710
+ computedObservable.evaluateImmediate();
1711
+ }
1712
+ if (state.disposeWhenNodeIsRemoved && computedObservable.isActive()) {
1713
+ addDisposeCallback(state.disposeWhenNodeIsRemoved, state.domNodeDisposalCallback = function() {
1714
+ computedObservable.dispose();
1715
+ });
1716
+ }
1717
+ return computedObservable;
1718
+ }
1719
+ function computedDisposeDependencyCallback(id, entryToDispose) {
1720
+ if (entryToDispose !== null && entryToDispose.dispose) {
1721
+ entryToDispose.dispose();
1722
+ }
1723
+ }
1724
+ function computedBeginDependencyDetectionCallback(subscribable2, id) {
1725
+ var computedObservable = this.computedObservable, state = computedObservable[computedState];
1726
+ if (!state.isDisposed) {
1727
+ if (this.disposalCount && this.disposalCandidates[id]) {
1728
+ computedObservable.addDependencyTracking(id, subscribable2, this.disposalCandidates[id]);
1729
+ this.disposalCandidates[id] = null;
1730
+ --this.disposalCount;
1731
+ } else if (!state.dependencyTracking[id]) {
1732
+ computedObservable.addDependencyTracking(id, subscribable2, state.isSleeping ? { _target: subscribable2 } : computedObservable.subscribeToDependency(subscribable2));
1733
+ }
1734
+ if (subscribable2._notificationIsPending) {
1735
+ subscribable2._notifyNextChangeIfValueIsDifferent();
1736
+ }
1737
+ }
1738
+ }
1739
+ computed.fn = {
1740
+ equalityComparer: valuesArePrimitiveAndEqual,
1741
+ getDependenciesCount() {
1742
+ return this[computedState].dependenciesCount;
1743
+ },
1744
+ getDependencies() {
1745
+ const dependencyTracking = this[computedState].dependencyTracking;
1746
+ const dependentObservables = [];
1747
+ objectForEach(dependencyTracking, function(id, dependency) {
1748
+ dependentObservables[dependency._order] = dependency._target;
1749
+ });
1750
+ return dependentObservables;
1751
+ },
1752
+ addDependencyTracking(id, target, trackingObj) {
1753
+ if (this[computedState].pure && target === this) {
1754
+ throw Error("A 'pure' computed must not be called recursively");
1755
+ }
1756
+ this[computedState].dependencyTracking[id] = trackingObj;
1757
+ trackingObj._order = this[computedState].dependenciesCount++;
1758
+ trackingObj._version = target.getVersion();
1759
+ },
1760
+ haveDependenciesChanged() {
1761
+ var id, dependency, dependencyTracking = this[computedState].dependencyTracking;
1762
+ for (id in dependencyTracking) {
1763
+ if (hasOwnProperty(dependencyTracking, id)) {
1764
+ dependency = dependencyTracking[id];
1765
+ if (this._evalDelayed && dependency._target._notificationIsPending || dependency._target.hasChanged(dependency._version)) {
1766
+ return true;
1767
+ }
1768
+ }
1769
+ }
1770
+ },
1771
+ markDirty() {
1772
+ if (this._evalDelayed && !this[computedState].isBeingEvaluated) {
1773
+ this._evalDelayed(false);
1774
+ }
1775
+ },
1776
+ isActive() {
1777
+ const state = this[computedState];
1778
+ return state.isDirty || state.dependenciesCount > 0;
1779
+ },
1780
+ respondToChange() {
1781
+ if (!this._notificationIsPending) {
1782
+ this.evaluatePossiblyAsync();
1783
+ } else if (this[computedState].isDirty) {
1784
+ this[computedState].isStale = true;
1785
+ }
1786
+ },
1787
+ subscribeToDependency(target) {
1788
+ if (target._deferUpdates) {
1789
+ var dirtySub = target.subscribe(this.markDirty, this, "dirty"), changeSub = target.subscribe(this.respondToChange, this);
1790
+ return {
1791
+ _target: target,
1792
+ dispose() {
1793
+ dirtySub.dispose();
1794
+ changeSub.dispose();
1795
+ }
1796
+ };
1797
+ } else {
1798
+ return target.subscribe(this.evaluatePossiblyAsync, this);
1799
+ }
1800
+ },
1801
+ evaluatePossiblyAsync() {
1802
+ var computedObservable = this, throttleEvaluationTimeout = computedObservable.throttleEvaluation;
1803
+ if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
1804
+ clearTimeout(this[computedState].evaluationTimeoutInstance);
1805
+ this[computedState].evaluationTimeoutInstance = safeSetTimeout(function() {
1806
+ computedObservable.evaluateImmediate(true);
1807
+ }, throttleEvaluationTimeout);
1808
+ } else if (computedObservable._evalDelayed) {
1809
+ computedObservable._evalDelayed(true);
1810
+ } else {
1811
+ computedObservable.evaluateImmediate(true);
1812
+ }
1813
+ },
1814
+ evaluateImmediate(notifyChange) {
1815
+ var computedObservable = this, state = computedObservable[computedState], disposeWhen = state.disposeWhen, changed = false;
1816
+ if (state.isBeingEvaluated) {
1817
+ return;
1818
+ }
1819
+ if (state.isDisposed) {
1820
+ return;
1821
+ }
1822
+ if (state.disposeWhenNodeIsRemoved && !domNodeIsAttachedToDocument(state.disposeWhenNodeIsRemoved) || disposeWhen && disposeWhen()) {
1823
+ if (!state.suppressDisposalUntilDisposeWhenReturnsFalse) {
1824
+ computedObservable.dispose();
1825
+ return;
1826
+ }
1827
+ } else {
1828
+ state.suppressDisposalUntilDisposeWhenReturnsFalse = false;
1829
+ }
1830
+ state.isBeingEvaluated = true;
1831
+ try {
1832
+ changed = this.evaluateImmediate_CallReadWithDependencyDetection(notifyChange);
1833
+ } finally {
1834
+ state.isBeingEvaluated = false;
1835
+ }
1836
+ return changed;
1837
+ },
1838
+ evaluateImmediate_CallReadWithDependencyDetection(notifyChange) {
1839
+ var computedObservable = this, state = computedObservable[computedState], changed = false;
1840
+ var isInitial2 = state.pure ? void 0 : !state.dependenciesCount, dependencyDetectionContext = {
1841
+ computedObservable,
1842
+ disposalCandidates: state.dependencyTracking,
1843
+ disposalCount: state.dependenciesCount
1844
+ };
1845
+ dependencyDetection_exports.begin({
1846
+ callbackTarget: dependencyDetectionContext,
1847
+ callback: computedBeginDependencyDetectionCallback,
1848
+ computed: computedObservable,
1849
+ isInitial: isInitial2
1850
+ });
1851
+ state.dependencyTracking = {};
1852
+ state.dependenciesCount = 0;
1853
+ var newValue = this.evaluateImmediate_CallReadThenEndDependencyDetection(state, dependencyDetectionContext);
1854
+ if (!state.dependenciesCount) {
1855
+ computedObservable.dispose();
1856
+ changed = true;
1857
+ } else {
1858
+ changed = computedObservable.isDifferent(state.latestValue, newValue);
1859
+ }
1860
+ if (changed) {
1861
+ if (!state.isSleeping) {
1862
+ computedObservable.notifySubscribers(state.latestValue, "beforeChange");
1863
+ } else {
1864
+ computedObservable.updateVersion();
1865
+ }
1866
+ state.latestValue = newValue;
1867
+ if (options_default.debug) {
1868
+ computedObservable._latestValue = newValue;
1869
+ }
1870
+ computedObservable.notifySubscribers(state.latestValue, "spectate");
1871
+ if (!state.isSleeping && notifyChange) {
1872
+ computedObservable.notifySubscribers(state.latestValue);
1873
+ }
1874
+ if (computedObservable._recordUpdate) {
1875
+ computedObservable._recordUpdate();
1876
+ }
1877
+ }
1878
+ if (isInitial2) {
1879
+ computedObservable.notifySubscribers(state.latestValue, "awake");
1880
+ }
1881
+ return changed;
1882
+ },
1883
+ evaluateImmediate_CallReadThenEndDependencyDetection(state, dependencyDetectionContext) {
1884
+ try {
1885
+ var readFunction = state.readFunction;
1886
+ return state.evaluatorFunctionTarget ? readFunction.call(state.evaluatorFunctionTarget) : readFunction();
1887
+ } finally {
1888
+ dependencyDetection_exports.end();
1889
+ if (dependencyDetectionContext.disposalCount && !state.isSleeping) {
1890
+ objectForEach(dependencyDetectionContext.disposalCandidates, computedDisposeDependencyCallback);
1891
+ }
1892
+ state.isStale = state.isDirty = false;
1893
+ }
1894
+ },
1895
+ peek(forceEvaluate) {
1896
+ const state = this[computedState];
1897
+ if (state.isDirty && (forceEvaluate || !state.dependenciesCount) || state.isSleeping && this.haveDependenciesChanged()) {
1898
+ this.evaluateImmediate();
1899
+ }
1900
+ return state.latestValue;
1901
+ },
1902
+ get [LATEST_VALUE]() {
1903
+ return this.peek();
1904
+ },
1905
+ limit(limitFunction) {
1906
+ const state = this[computedState];
1907
+ subscribable.fn.limit.call(this, limitFunction);
1908
+ Object.assign(this, {
1909
+ _evalIfChanged() {
1910
+ if (!this[computedState].isSleeping) {
1911
+ if (this[computedState].isStale) {
1912
+ this.evaluateImmediate();
1913
+ } else {
1914
+ this[computedState].isDirty = false;
1915
+ }
1916
+ }
1917
+ return state.latestValue;
1918
+ },
1919
+ _evalDelayed(isChange) {
1920
+ this._limitBeforeChange(state.latestValue);
1921
+ state.isDirty = true;
1922
+ if (isChange) {
1923
+ state.isStale = true;
1924
+ }
1925
+ this._limitChange(this, !isChange);
1926
+ }
1927
+ });
1928
+ },
1929
+ dispose() {
1930
+ var state = this[computedState];
1931
+ if (!state.isSleeping && state.dependencyTracking) {
1932
+ objectForEach(state.dependencyTracking, function(id, dependency) {
1933
+ if (dependency.dispose) {
1934
+ dependency.dispose();
1935
+ }
1936
+ });
1937
+ }
1938
+ if (state.disposeWhenNodeIsRemoved && state.domNodeDisposalCallback) {
1939
+ removeDisposeCallback(state.disposeWhenNodeIsRemoved, state.domNodeDisposalCallback);
1940
+ }
1941
+ Object.assign(state, DISPOSED_STATE);
1942
+ }
1943
+ };
1944
+ var pureComputedOverrides = {
1945
+ beforeSubscriptionAdd(event) {
1946
+ var computedObservable = this, state = computedObservable[computedState];
1947
+ if (!state.isDisposed && state.isSleeping && event === "change") {
1948
+ state.isSleeping = false;
1949
+ if (state.isStale || computedObservable.haveDependenciesChanged()) {
1950
+ state.dependencyTracking = null;
1951
+ state.dependenciesCount = 0;
1952
+ if (computedObservable.evaluateImmediate()) {
1953
+ computedObservable.updateVersion();
1954
+ }
1955
+ } else {
1956
+ var dependenciesOrder = [];
1957
+ objectForEach(state.dependencyTracking, function(id, dependency) {
1958
+ dependenciesOrder[dependency._order] = id;
1959
+ });
1960
+ arrayForEach(dependenciesOrder, function(id, order) {
1961
+ var dependency = state.dependencyTracking[id], subscription = computedObservable.subscribeToDependency(dependency._target);
1962
+ subscription._order = order;
1963
+ subscription._version = dependency._version;
1964
+ state.dependencyTracking[id] = subscription;
1965
+ });
1966
+ if (computedObservable.haveDependenciesChanged()) {
1967
+ if (computedObservable.evaluateImmediate()) {
1968
+ computedObservable.updateVersion();
1969
+ }
1970
+ }
1971
+ }
1972
+ if (!state.isDisposed) {
1973
+ computedObservable.notifySubscribers(state.latestValue, "awake");
1974
+ }
1975
+ }
1976
+ },
1977
+ afterSubscriptionRemove(event) {
1978
+ var state = this[computedState];
1979
+ if (!state.isDisposed && event === "change" && !this.hasSubscriptionsForEvent("change")) {
1980
+ objectForEach(state.dependencyTracking, function(id, dependency) {
1981
+ if (dependency.dispose) {
1982
+ state.dependencyTracking[id] = {
1983
+ _target: dependency._target,
1984
+ _order: dependency._order,
1985
+ _version: dependency._version
1986
+ };
1987
+ dependency.dispose();
1988
+ }
1989
+ });
1990
+ state.isSleeping = true;
1991
+ this.notifySubscribers(void 0, "asleep");
1992
+ }
1993
+ },
1994
+ getVersion() {
1995
+ var state = this[computedState];
1996
+ if (state.isSleeping && (state.isStale || this.haveDependenciesChanged())) {
1997
+ this.evaluateImmediate();
1998
+ }
1999
+ return subscribable.fn.getVersion.call(this);
2000
+ }
2001
+ };
2002
+ var deferEvaluationOverrides = {
2003
+ beforeSubscriptionAdd(event) {
2004
+ if (event === "change" || event === "beforeChange") {
2005
+ this.peek();
2006
+ }
2007
+ }
2008
+ };
2009
+ Object.setPrototypeOf(computed.fn, subscribable.fn);
2010
+ var protoProp = observable.protoProperty;
2011
+ computed.fn[protoProp] = computed;
2012
+ observable.observablePrototypes.add(computed);
2013
+ function pureComputed(evaluatorFunctionOrOptions, evaluatorFunctionTarget) {
2014
+ if (typeof evaluatorFunctionOrOptions === "function") {
2015
+ return computed(evaluatorFunctionOrOptions, evaluatorFunctionTarget, { "pure": true });
2016
+ } else {
2017
+ evaluatorFunctionOrOptions = extend({}, evaluatorFunctionOrOptions);
2018
+ evaluatorFunctionOrOptions.pure = true;
2019
+ return computed(evaluatorFunctionOrOptions, evaluatorFunctionTarget);
2020
+ }
2021
+ }
2022
+
2023
+ // ../computed/dist/throttleExtender.js
2024
+ function throttleExtender(target, timeout) {
2025
+ target.throttleEvaluation = timeout;
2026
+ var writeTimeoutInstance = null;
2027
+ return computed({
2028
+ read: target,
2029
+ write: function(value) {
2030
+ clearTimeout(writeTimeoutInstance);
2031
+ writeTimeoutInstance = setTimeout(function() {
2032
+ target(value);
2033
+ }, timeout);
2034
+ }
2035
+ });
2036
+ }
2037
+ extenders.throttle = throttleExtender;
2038
+
2039
+ // ../computed/dist/proxy.js
2040
+ var PROXY_SYM = Symbol("Knockout Proxied Object");
2041
+ var MIRROR_SYM = Symbol("Knockout Proxied Observables");
2042
+ function makeComputed(proxy2, fn) {
2043
+ return computed({
2044
+ owner: proxy2,
2045
+ read: fn,
2046
+ write: fn,
2047
+ pure: "pure" in fn ? fn.pure : true,
2048
+ deferEvaluation: "deferEvaluation" in fn ? fn.deferEvaluation : true
2049
+ }).extend({ deferred: true });
2050
+ }
2051
+ function setOrCreate(mirror, prop, value, proxy2) {
2052
+ if (!mirror[prop]) {
2053
+ const ctr = Array.isArray(value) ? observableArray : typeof value === "function" ? makeComputed.bind(null, proxy2) : observable;
2054
+ mirror[prop] = ctr(value);
2055
+ } else {
2056
+ mirror[prop](value);
2057
+ }
2058
+ }
2059
+ function assignOrUpdate(mirror, object, proxy2) {
2060
+ for (const key of Object.keys(object)) {
2061
+ setOrCreate(mirror, key, object[key], proxy2);
2062
+ }
2063
+ return object;
2064
+ }
2065
+ function proxy(object) {
2066
+ const mirror = { [PROXY_SYM]: object };
2067
+ mirror[MIRROR_SYM] = mirror;
2068
+ const proxy2 = new Proxy(function() {
2069
+ }, {
2070
+ has(target, prop) {
2071
+ return prop in mirror;
2072
+ },
2073
+ get(target, prop) {
2074
+ return unwrap(mirror[prop]);
2075
+ },
2076
+ set(target, prop, value, receiver) {
2077
+ setOrCreate(mirror, prop, value, proxy2);
2078
+ object[prop] = value;
2079
+ return true;
2080
+ },
2081
+ deleteProperty(property) {
2082
+ delete mirror[property];
2083
+ return delete object[property];
2084
+ },
2085
+ apply(target, thisArg, [props]) {
2086
+ if (props) {
2087
+ assignOrUpdate(mirror, props, proxy2);
2088
+ return Object.assign(object, props);
2089
+ }
2090
+ return object;
2091
+ },
2092
+ getPrototypeOf() {
2093
+ return Object.getPrototypeOf(object);
2094
+ },
2095
+ setPrototypeOf(target, proto) {
2096
+ return Object.setPrototypeOf(object, proto);
2097
+ },
2098
+ defineProperty(target, prop, desc) {
2099
+ return Object.defineProperty(object, prop, desc);
2100
+ },
2101
+ preventExtensions() {
2102
+ return Object.preventExtensions(object);
2103
+ },
2104
+ isExtensible() {
2105
+ return Object.isExtensible(object);
2106
+ },
2107
+ ownKeys() {
2108
+ return [
2109
+ ...Object.getOwnPropertyNames(object),
2110
+ ...Object.getOwnPropertySymbols(object)
2111
+ ];
2112
+ }
2113
+ });
2114
+ assignOrUpdate(mirror, object, proxy2);
2115
+ return proxy2;
2116
+ }
2117
+ function getObservable(proxied, prop) {
2118
+ return proxied[MIRROR_SYM][prop];
2119
+ }
2120
+ function peek2(proxied, prop) {
2121
+ return getObservable(proxied, prop).peek();
2122
+ }
2123
+ function isProxied(proxied) {
2124
+ return PROXY_SYM in proxied;
2125
+ }
2126
+ Object.assign(proxy, { getObservable, peek: peek2, isProxied });
2127
+
2128
+ // src/bindingEvent.ts
2129
+ var contextAncestorBindingInfo = Symbol("_ancestorBindingInfo");
2130
+ var boundElementDomDataKey = data_exports.nextKey();
2131
+ var bindingEvent = {
2132
+ childrenComplete: "childrenComplete",
2133
+ descendantsComplete: "descendantsComplete",
2134
+ subscribe(node, event, callback, context) {
2135
+ const bindingInfo = data_exports.getOrSet(node, boundElementDomDataKey, {});
2136
+ if (!bindingInfo.eventSubscribable) {
2137
+ bindingInfo.eventSubscribable = new subscribable();
2138
+ }
2139
+ return bindingInfo.eventSubscribable.subscribe(callback, context, event);
2140
+ },
2141
+ notify(node, event) {
2142
+ const bindingInfo = data_exports.get(node, boundElementDomDataKey);
2143
+ if (bindingInfo) {
2144
+ if (bindingInfo.eventSubscribable) {
2145
+ bindingInfo.eventSubscribable.notifySubscribers(node, event);
2146
+ }
2147
+ }
2148
+ }
2149
+ };
2150
+
2151
+ // src/bindingContext.ts
2152
+ var boundElementDomDataKey2 = data_exports.nextKey();
2153
+ var contextSubscribeSymbol = Symbol("Knockout Context Subscription");
2154
+ var inheritParentIndicator = Symbol("Knockout Parent Indicator");
2155
+ function bindingContext(dataItemOrAccessor, parentContext, dataItemAlias, extendCallback, settings) {
2156
+ const self = this;
2157
+ const shouldInheritData = dataItemOrAccessor === inheritParentIndicator;
2158
+ const realDataItemOrAccessor = shouldInheritData ? void 0 : dataItemOrAccessor;
2159
+ const isFunc = typeof realDataItemOrAccessor === "function" && !isObservable(realDataItemOrAccessor);
2160
+ self.ko = options_default.knockoutInstance;
2161
+ let nodes;
2162
+ let subscribable2;
2163
+ function updateContext() {
2164
+ const dataItemOrObservable = isFunc ? realDataItemOrAccessor() : realDataItemOrAccessor;
2165
+ let dataItem = unwrap(dataItemOrObservable);
2166
+ if (parentContext) {
2167
+ if (parentContext[contextSubscribeSymbol]) {
2168
+ parentContext[contextSubscribeSymbol]();
2169
+ }
2170
+ extend(self, parentContext);
2171
+ if (contextAncestorBindingInfo in parentContext) {
2172
+ self[contextAncestorBindingInfo] = parentContext[contextAncestorBindingInfo];
2173
+ }
2174
+ } else {
2175
+ self.$parents = [];
2176
+ self.$root = dataItem;
2177
+ }
2178
+ self[contextSubscribeSymbol] = subscribable2;
2179
+ if (shouldInheritData) {
2180
+ dataItem = self.$data;
2181
+ } else {
2182
+ self.$rawData = dataItemOrObservable;
2183
+ self.$data = dataItem;
2184
+ }
2185
+ if (dataItemAlias) {
2186
+ self[dataItemAlias] = dataItem;
2187
+ }
2188
+ if (extendCallback) {
2189
+ extendCallback(self, parentContext, dataItem);
2190
+ }
2191
+ return self.$data;
2192
+ }
2193
+ if (settings && settings.exportDependencies) {
2194
+ updateContext();
2195
+ } else {
2196
+ subscribable2 = pureComputed(updateContext);
2197
+ subscribable2.peek();
2198
+ if (subscribable2.isActive()) {
2199
+ self[contextSubscribeSymbol] = subscribable2;
2200
+ subscribable2["equalityComparer"] = null;
2201
+ } else {
2202
+ self[contextSubscribeSymbol] = void 0;
2203
+ }
2204
+ }
2205
+ }
2206
+ Object.assign(bindingContext.prototype, {
2207
+ lookup(token, globals, node) {
2208
+ switch (token) {
2209
+ case "$element":
2210
+ return node;
2211
+ case "$context":
2212
+ return this;
2213
+ case "this":
2214
+ case "$data":
2215
+ return this.$data;
2216
+ }
2217
+ const $data = this.$data;
2218
+ if (isObjectLike($data) && token in $data) {
2219
+ return $data[token];
2220
+ }
2221
+ if (token in this) {
2222
+ return this[token];
2223
+ }
2224
+ if (token in globals) {
2225
+ return globals[token];
2226
+ }
2227
+ throw new Error(`The variable "${token}" was not found on $data, $context, or globals.`);
2228
+ },
2229
+ createChildContext(dataItemOrAccessor, dataItemAlias, extendCallback, settings) {
2230
+ return new bindingContext(dataItemOrAccessor, this, dataItemAlias, function(self, parentContext) {
2231
+ self.$parentContext = parentContext;
2232
+ self.$parent = parentContext.$data;
2233
+ self.$parents = (parentContext.$parents || []).slice(0);
2234
+ self.$parents.unshift(self.$parent);
2235
+ if (extendCallback) {
2236
+ extendCallback(self);
2237
+ }
2238
+ }, settings);
2239
+ },
2240
+ extend(properties) {
2241
+ return new bindingContext(inheritParentIndicator, this, null, function(self, parentContext) {
2242
+ extend(self, typeof properties === "function" ? properties.call(self) : properties);
2243
+ });
2244
+ },
2245
+ createStaticChildContext(dataItemOrAccessor, dataItemAlias) {
2246
+ return this.createChildContext(dataItemOrAccessor, dataItemAlias, null, { "exportDependencies": true });
2247
+ }
2248
+ });
2249
+ function storedBindingContextForNode(node) {
2250
+ const bindingInfo = data_exports.get(node, boundElementDomDataKey2);
2251
+ return bindingInfo && bindingInfo.context;
2252
+ }
2253
+ function contextFor(node) {
2254
+ if (node && (node.nodeType === 1 || node.nodeType === 8)) {
2255
+ return storedBindingContextForNode(node);
2256
+ }
2257
+ }
2258
+ function dataFor(node) {
2259
+ var context = contextFor(node);
2260
+ return context ? context.$data : void 0;
2261
+ }
2262
+
2263
+ // src/BindingResult.ts
2264
+ var BindingResult = class {
2265
+ constructor({ asyncBindingsApplied, rootNode, bindingContext: bindingContext2 }) {
2266
+ Object.assign(this, {
2267
+ rootNode,
2268
+ bindingContext: bindingContext2,
2269
+ isSync: asyncBindingsApplied.size === 0,
2270
+ isComplete: this.isSync
2271
+ });
2272
+ if (!this.isSync) {
2273
+ this.completionPromise = this.completeWhenBindingsFinish(asyncBindingsApplied);
2274
+ }
2275
+ }
2276
+ completeWhenBindingsFinish(asyncBindingsApplied) {
2277
+ return __async(this, null, function* () {
2278
+ yield Promise.all(asyncBindingsApplied);
2279
+ this.isComplete = true;
2280
+ return this;
2281
+ });
2282
+ }
2283
+ };
2284
+
2285
+ // ../lifecycle/dist/LifeCycle.js
2286
+ var SUBSCRIPTIONS = createSymbolOrString("LifeCycle Subscriptions List");
2287
+ var ANCHOR_NODE = createSymbolOrString("LifeCycle Anchor Node");
2288
+ var LifeCycle = class {
2289
+ static mixInto(Constructor) {
2290
+ const target = Constructor.prototype || Constructor;
2291
+ const mixin = LifeCycle.prototype;
2292
+ for (let prop of Object.getOwnPropertyNames(mixin)) {
2293
+ target[prop] = mixin[prop];
2294
+ }
2295
+ }
2296
+ subscribe(observable2, action, subscriptionType) {
2297
+ if (typeof action === "string") {
2298
+ action = this[action];
2299
+ }
2300
+ this.addDisposable(observable2.subscribe(action, this, subscriptionType));
2301
+ }
2302
+ computed(params) {
2303
+ if (typeof params === "string") {
2304
+ params = { read: this[params], write: this[params] };
2305
+ }
2306
+ if (typeof params === "object") {
2307
+ params = Object.assign({ owner: this }, params);
2308
+ } else if (typeof params === "function") {
2309
+ const proto = Object.getPrototypeOf(this);
2310
+ if (proto && proto[params.name] === params) {
2311
+ params = params.bind(this);
2312
+ }
2313
+ params = { read: params, write: params };
2314
+ } else {
2315
+ throw new Error("LifeCycle::computed not given a valid type.");
2316
+ }
2317
+ params.disposeWhenNodeIsRemoved = this[ANCHOR_NODE];
2318
+ return this.addDisposable(computed(params));
2319
+ }
2320
+ addEventListener(...args) {
2321
+ const node = args[0].nodeType ? args.shift() : this[ANCHOR_NODE];
2322
+ const [type, act, options2] = args;
2323
+ const handler = typeof act === "string" ? this[act].bind(this) : act;
2324
+ this.__addEventListener(node, type, handler, options2);
2325
+ }
2326
+ __addEventListener(node, eventType, handler, options2) {
2327
+ node.addEventListener(eventType, handler, options2);
2328
+ function dispose() {
2329
+ node.removeEventListener(eventType, handler);
2330
+ }
2331
+ addDisposeCallback(node, dispose);
2332
+ this.addDisposable({ dispose });
2333
+ }
2334
+ anchorTo(nodeOrLifeCycle) {
2335
+ if ("addDisposable" in nodeOrLifeCycle) {
2336
+ nodeOrLifeCycle.addDisposable(this);
2337
+ this[ANCHOR_NODE] = null;
2338
+ } else {
2339
+ this[ANCHOR_NODE] = nodeOrLifeCycle;
2340
+ addDisposeCallback(nodeOrLifeCycle, () => this[ANCHOR_NODE] === nodeOrLifeCycle && this.dispose());
2341
+ }
2342
+ }
2343
+ dispose() {
2344
+ const subscriptions = this[SUBSCRIPTIONS] || [];
2345
+ subscriptions.forEach((s) => s.dispose());
2346
+ this[SUBSCRIPTIONS] = [];
2347
+ this[ANCHOR_NODE] = null;
2348
+ }
2349
+ addDisposable(subscription) {
2350
+ const subscriptions = this[SUBSCRIPTIONS] || [];
2351
+ if (!this[SUBSCRIPTIONS]) {
2352
+ this[SUBSCRIPTIONS] = subscriptions;
2353
+ }
2354
+ if (typeof subscription.dispose !== "function") {
2355
+ throw new Error("Lifecycle::addDisposable argument missing `dispose`.");
2356
+ }
2357
+ subscriptions.push(subscription);
2358
+ return subscription;
2359
+ }
2360
+ };
2361
+
2362
+ // src/BindingHandler.ts
2363
+ var BindingHandler = class extends LifeCycle {
2364
+ constructor(params) {
2365
+ super();
2366
+ const { $element, valueAccessor, allBindings, $context } = params;
2367
+ Object.assign(this, {
2368
+ valueAccessor,
2369
+ allBindings,
2370
+ $element,
2371
+ $context,
2372
+ $data: $context.$data
2373
+ });
2374
+ this.anchorTo($element);
2375
+ }
2376
+ get value() {
2377
+ return this.valueAccessor();
2378
+ }
2379
+ set value(v) {
2380
+ const va = this.valueAccessor();
2381
+ if (isWriteableObservable(va)) {
2382
+ va(v);
2383
+ } else {
2384
+ this.valueAccessor(v);
2385
+ }
2386
+ }
2387
+ get controlsDescendants() {
2388
+ return false;
2389
+ }
2390
+ static get allowVirtualElements() {
2391
+ return false;
2392
+ }
2393
+ static get isBindingHandlerClass() {
2394
+ return true;
2395
+ }
2396
+ get bindingCompleted() {
2397
+ return true;
2398
+ }
2399
+ static registerAs(name, provider = options_default.bindingProviderInstance) {
2400
+ provider.bindingHandlers.set(name, this);
2401
+ }
2402
+ };
2403
+ var ResolveSymbol = Symbol("Async Binding Resolved");
2404
+ var AsyncBindingHandler = class extends BindingHandler {
2405
+ constructor(params) {
2406
+ super(params);
2407
+ this.bindingCompletion = new Promise((resolve) => {
2408
+ this[ResolveSymbol] = resolve;
2409
+ });
2410
+ this.completeBinding = (bindingResult) => this[ResolveSymbol](bindingResult);
2411
+ }
2412
+ get bindingCompleted() {
2413
+ return this.bindingCompletion;
2414
+ }
2415
+ };
2416
+
2417
+ // src/LegacyBindingHandler.ts
2418
+ var PossibleWeakMap = options_default.global.WeakMap || Map;
2419
+ var legacyBindingMap = new PossibleWeakMap();
2420
+ var LegacyBindingHandler = class extends BindingHandler {
2421
+ constructor(params) {
2422
+ super(params);
2423
+ const handler = this.handler;
2424
+ this.onError = params.onError;
2425
+ if (typeof handler.dispose === "function") {
2426
+ this.addDisposable(handler);
2427
+ }
2428
+ try {
2429
+ this.initReturn = handler.init && handler.init(...this.legacyArgs);
2430
+ } catch (e) {
2431
+ params.onError("init", e);
2432
+ }
2433
+ }
2434
+ onValueChange() {
2435
+ const handler = this.handler;
2436
+ if (typeof handler.update !== "function") {
2437
+ return;
2438
+ }
2439
+ try {
2440
+ handler.update(...this.legacyArgs);
2441
+ } catch (e) {
2442
+ this.onError("update", e);
2443
+ }
2444
+ }
2445
+ get legacyArgs() {
2446
+ return [
2447
+ this.$element,
2448
+ this.valueAccessor,
2449
+ this.allBindings,
2450
+ this.$data,
2451
+ this.$context
2452
+ ];
2453
+ }
2454
+ get controlsDescendants() {
2455
+ const objectToTest = this.initReturn || this.handler || {};
2456
+ return objectToTest.controlsDescendantBindings;
2457
+ }
2458
+ static getOrCreateFor(key, handler) {
2459
+ if (legacyBindingMap.has(handler)) {
2460
+ return legacyBindingMap.get(handler);
2461
+ }
2462
+ const newLegacyHandler = this.createFor(key, handler);
2463
+ legacyBindingMap.set(handler, newLegacyHandler);
2464
+ return newLegacyHandler;
2465
+ }
2466
+ static createFor(key, handler) {
2467
+ if (typeof handler === "function") {
2468
+ const [initFn, disposeFn] = [handler, handler.dispose];
2469
+ return class extends LegacyBindingHandler {
2470
+ get handler() {
2471
+ const init = initFn.bind(this);
2472
+ const dispose = disposeFn ? disposeFn.bind(this) : null;
2473
+ return { init, dispose };
2474
+ }
2475
+ static get after() {
2476
+ return handler.after;
2477
+ }
2478
+ static get allowVirtualElements() {
2479
+ return handler.allowVirtualElements || virtualElements_exports.allowedBindings[key];
2480
+ }
2481
+ };
2482
+ }
2483
+ if (typeof handler === "object") {
2484
+ return class extends LegacyBindingHandler {
2485
+ get handler() {
2486
+ return handler;
2487
+ }
2488
+ static get after() {
2489
+ return handler.after;
2490
+ }
2491
+ static get allowVirtualElements() {
2492
+ return handler.allowVirtualElements || virtualElements_exports.allowedBindings[key];
2493
+ }
2494
+ };
2495
+ }
2496
+ throw new Error("The given handler is not an appropriate type.");
2497
+ }
2498
+ };
2499
+
2500
+ // src/applyBindings.ts
2501
+ var bindingDoesNotRecurseIntoElementTypes = {
2502
+ "script": true,
2503
+ "textarea": true,
2504
+ "template": true
2505
+ };
2506
+ function getBindingProvider() {
2507
+ return options_default.bindingProviderInstance.instance || options_default.bindingProviderInstance;
2508
+ }
2509
+ function isProviderForNode(provider, node) {
2510
+ const nodeTypes = provider.FOR_NODE_TYPES || [1, 3, 8];
2511
+ return nodeTypes.includes(node.nodeType);
2512
+ }
2513
+ function asProperHandlerClass(handler, bindingKey) {
2514
+ if (!handler) {
2515
+ return;
2516
+ }
2517
+ return handler.isBindingHandlerClass ? handler : LegacyBindingHandler.getOrCreateFor(bindingKey, handler);
2518
+ }
2519
+ function getBindingHandlerFromComponent(bindingKey, $component) {
2520
+ if (!$component || typeof $component.getBindingHandler !== "function") {
2521
+ return;
2522
+ }
2523
+ return asProperHandlerClass($component.getBindingHandler(bindingKey));
2524
+ }
2525
+ function getBindingHandler(bindingKey) {
2526
+ const bindingDefinition = options_default.getBindingHandler(bindingKey) || getBindingProvider().bindingHandlers.get(bindingKey);
2527
+ return asProperHandlerClass(bindingDefinition, bindingKey);
2528
+ }
2529
+ function evaluateValueAccessor(valueAccessor) {
2530
+ return valueAccessor();
2531
+ }
2532
+ function applyBindingsToDescendantsInternal(bindingContext2, elementOrVirtualElement, asyncBindingsApplied) {
2533
+ let nextInQueue = virtualElements_exports.firstChild(elementOrVirtualElement);
2534
+ if (!nextInQueue) {
2535
+ return;
2536
+ }
2537
+ let currentChild;
2538
+ const provider = getBindingProvider();
2539
+ const preprocessNode = provider.preprocessNode;
2540
+ if (preprocessNode) {
2541
+ while (currentChild = nextInQueue) {
2542
+ nextInQueue = virtualElements_exports.nextSibling(currentChild);
2543
+ preprocessNode.call(provider, currentChild);
2544
+ }
2545
+ nextInQueue = virtualElements_exports.firstChild(elementOrVirtualElement);
2546
+ }
2547
+ while (currentChild = nextInQueue) {
2548
+ nextInQueue = virtualElements_exports.nextSibling(currentChild);
2549
+ applyBindingsToNodeAndDescendantsInternal(bindingContext2, currentChild, asyncBindingsApplied);
2550
+ }
2551
+ bindingEvent.notify(elementOrVirtualElement, bindingEvent.childrenComplete);
2552
+ }
2553
+ function hasBindings(node) {
2554
+ const provider = getBindingProvider();
2555
+ return isProviderForNode(provider, node) && provider.nodeHasBindings(node);
2556
+ }
2557
+ function nodeOrChildHasBindings(node) {
2558
+ return hasBindings(node) || [...node.childNodes].some((c) => nodeOrChildHasBindings(c));
2559
+ }
2560
+ function applyBindingsToNodeAndDescendantsInternal(bindingContext2, nodeVerified, asyncBindingsApplied) {
2561
+ var isElement = nodeVerified.nodeType === 1;
2562
+ if (isElement) {
2563
+ virtualElements_exports.normaliseVirtualElementDomStructure(nodeVerified);
2564
+ }
2565
+ let shouldApplyBindings = isElement || hasBindings(nodeVerified);
2566
+ const { shouldBindDescendants } = shouldApplyBindings ? applyBindingsToNodeInternal(nodeVerified, null, bindingContext2, asyncBindingsApplied) : { shouldBindDescendants: true };
2567
+ if (shouldBindDescendants && !bindingDoesNotRecurseIntoElementTypes[tagNameLower(nodeVerified)]) {
2568
+ applyBindingsToDescendantsInternal(bindingContext2, nodeVerified, asyncBindingsApplied);
2569
+ }
2570
+ }
2571
+ function* topologicalSortBindings(bindings, $component) {
2572
+ const results = [];
2573
+ const bindingsConsidered = {};
2574
+ const cyclicDependencyStack = [];
2575
+ objectForEach(bindings, function pushBinding(bindingKey) {
2576
+ if (!bindingsConsidered[bindingKey]) {
2577
+ const binding = getBindingHandlerFromComponent(bindingKey, $component) || getBindingHandler(bindingKey);
2578
+ if (!binding) {
2579
+ return;
2580
+ }
2581
+ if (binding.after) {
2582
+ cyclicDependencyStack.push(bindingKey);
2583
+ arrayForEach(binding.after, function(bindingDependencyKey) {
2584
+ if (!bindings[bindingDependencyKey]) {
2585
+ return;
2586
+ }
2587
+ if (arrayIndexOf(cyclicDependencyStack, bindingDependencyKey) !== -1) {
2588
+ throw Error("Cannot combine the following bindings, because they have a cyclic dependency: " + cyclicDependencyStack.join(", "));
2589
+ } else {
2590
+ pushBinding(bindingDependencyKey);
2591
+ }
2592
+ });
2593
+ cyclicDependencyStack.length--;
2594
+ }
2595
+ results.push([bindingKey, binding]);
2596
+ }
2597
+ bindingsConsidered[bindingKey] = true;
2598
+ });
2599
+ for (const result of results) {
2600
+ yield result;
2601
+ }
2602
+ }
2603
+ function applyBindingsToNodeInternal(node, sourceBindings, bindingContext2, asyncBindingsApplied) {
2604
+ const bindingInfo = data_exports.getOrSet(node, boundElementDomDataKey2, {});
2605
+ const alreadyBound = bindingInfo.alreadyBound;
2606
+ if (!sourceBindings) {
2607
+ if (alreadyBound) {
2608
+ if (!nodeOrChildHasBindings(node)) {
2609
+ return false;
2610
+ }
2611
+ onBindingError({
2612
+ during: "apply",
2613
+ errorCaptured: new Error("You cannot apply bindings multiple times to the same element."),
2614
+ element: node,
2615
+ bindingContext: bindingContext2
2616
+ });
2617
+ return false;
2618
+ }
2619
+ bindingInfo.alreadyBound = true;
2620
+ }
2621
+ if (!alreadyBound) {
2622
+ bindingInfo.context = bindingContext2;
2623
+ }
2624
+ var bindings;
2625
+ if (sourceBindings && typeof sourceBindings !== "function") {
2626
+ bindings = sourceBindings;
2627
+ } else {
2628
+ const provider = getBindingProvider();
2629
+ const getBindings = provider.getBindingAccessors;
2630
+ if (isProviderForNode(provider, node)) {
2631
+ var bindingsUpdater = computed(function() {
2632
+ bindings = sourceBindings ? sourceBindings(bindingContext2, node) : getBindings.call(provider, node, bindingContext2);
2633
+ if (bindings && bindingContext2[contextSubscribeSymbol]) {
2634
+ bindingContext2[contextSubscribeSymbol]();
2635
+ }
2636
+ return bindings;
2637
+ }, null, { disposeWhenNodeIsRemoved: node });
2638
+ if (!bindings || !bindingsUpdater.isActive()) {
2639
+ bindingsUpdater = null;
2640
+ }
2641
+ }
2642
+ }
2643
+ var bindingHandlerThatControlsDescendantBindings;
2644
+ if (bindings) {
2645
+ let allBindings = function() {
2646
+ return objectMap(bindingsUpdater ? bindingsUpdater() : bindings, evaluateValueAccessor);
2647
+ };
2648
+ const $component = bindingContext2.$component || {};
2649
+ const allBindingHandlers = {};
2650
+ data_exports.set(node, "bindingHandlers", allBindingHandlers);
2651
+ const getValueAccessor = bindingsUpdater ? (bindingKey) => function(optionalValue) {
2652
+ const valueAccessor = bindingsUpdater()[bindingKey];
2653
+ if (arguments.length === 0) {
2654
+ return evaluateValueAccessor(valueAccessor);
2655
+ } else {
2656
+ return valueAccessor(optionalValue);
2657
+ }
2658
+ } : (bindingKey) => bindings[bindingKey];
2659
+ allBindings.has = (key) => key in bindings;
2660
+ allBindings.get = (key) => bindings[key] && evaluateValueAccessor(getValueAccessor(key));
2661
+ if (bindingEvent.childrenComplete in bindings) {
2662
+ bindingEvent.subscribe(node, bindingEvent.childrenComplete, () => {
2663
+ const callback = evaluateValueAccessor(bindings[bindingEvent.childrenComplete]);
2664
+ if (!callback) {
2665
+ return;
2666
+ }
2667
+ const nodes = virtualElements_exports.childNodes(node);
2668
+ if (nodes.length) {
2669
+ callback(nodes, dataFor(nodes[0]));
2670
+ }
2671
+ });
2672
+ }
2673
+ const bindingsGenerated = topologicalSortBindings(bindings, $component);
2674
+ const nodeAsyncBindingPromises = /* @__PURE__ */ new Set();
2675
+ for (const [key, BindingHandlerClass] of bindingsGenerated) {
2676
+ let reportBindingError = function(during, errorCaptured) {
2677
+ onBindingError({
2678
+ during,
2679
+ errorCaptured,
2680
+ bindings,
2681
+ allBindings,
2682
+ bindingKey: key,
2683
+ bindingContext: bindingContext2,
2684
+ element: node,
2685
+ valueAccessor: getValueAccessor(key)
2686
+ });
2687
+ };
2688
+ if (node.nodeType === 8 && !BindingHandlerClass.allowVirtualElements) {
2689
+ throw new Error(`The binding '${key}' cannot be used with virtual elements`);
2690
+ }
2691
+ try {
2692
+ const bindingHandler = dependencyDetection_exports.ignore(() => new BindingHandlerClass({
2693
+ allBindings,
2694
+ $element: node,
2695
+ $context: bindingContext2,
2696
+ onError: reportBindingError,
2697
+ valueAccessor(...v) {
2698
+ return getValueAccessor(key)(...v);
2699
+ }
2700
+ }));
2701
+ if (bindingHandler.onValueChange) {
2702
+ dependencyDetection_exports.ignore(() => bindingHandler.computed("onValueChange"));
2703
+ }
2704
+ allBindingHandlers[key] = bindingHandler;
2705
+ if (bindingHandler.controlsDescendants) {
2706
+ if (bindingHandlerThatControlsDescendantBindings !== void 0) {
2707
+ throw new Error("Multiple bindings (" + bindingHandlerThatControlsDescendantBindings + " and " + key + ") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");
2708
+ }
2709
+ bindingHandlerThatControlsDescendantBindings = key;
2710
+ }
2711
+ if (bindingHandler.bindingCompleted instanceof Promise) {
2712
+ asyncBindingsApplied.add(bindingHandler.bindingCompleted);
2713
+ nodeAsyncBindingPromises.add(bindingHandler.bindingCompleted);
2714
+ }
2715
+ } catch (err) {
2716
+ reportBindingError("creation", err);
2717
+ }
2718
+ }
2719
+ triggerDescendantsComplete(node, bindings, nodeAsyncBindingPromises);
2720
+ }
2721
+ const shouldBindDescendants = bindingHandlerThatControlsDescendantBindings === void 0;
2722
+ return { shouldBindDescendants };
2723
+ }
2724
+ function triggerDescendantsComplete(node, bindings, nodeAsyncBindingPromises) {
2725
+ const hasBindingHandler = bindingEvent.descendantsComplete in bindings;
2726
+ const hasFirstChild = virtualElements_exports.firstChild(node);
2727
+ const accessor = hasBindingHandler && evaluateValueAccessor(bindings[bindingEvent.descendantsComplete]);
2728
+ const callback = () => {
2729
+ bindingEvent.notify(node, bindingEvent.descendantsComplete);
2730
+ if (accessor && hasFirstChild) {
2731
+ accessor(node);
2732
+ }
2733
+ };
2734
+ if (nodeAsyncBindingPromises.size) {
2735
+ Promise.all(nodeAsyncBindingPromises).then(callback);
2736
+ } else {
2737
+ callback();
2738
+ }
2739
+ }
2740
+ function getBindingContext(viewModelOrBindingContext, extendContextCallback) {
2741
+ return viewModelOrBindingContext && viewModelOrBindingContext instanceof bindingContext ? viewModelOrBindingContext : new bindingContext(viewModelOrBindingContext, void 0, void 0, extendContextCallback);
2742
+ }
2743
+ function applyBindingAccessorsToNode(node, bindings, viewModelOrBindingContext, asyncBindingsApplied) {
2744
+ if (node.nodeType === 1) {
2745
+ virtualElements_exports.normaliseVirtualElementDomStructure(node);
2746
+ }
2747
+ return applyBindingsToNodeInternal(node, bindings, getBindingContext(viewModelOrBindingContext), asyncBindingsApplied);
2748
+ }
2749
+ function applyBindingsToNode(node, bindings, viewModelOrBindingContext) {
2750
+ const asyncBindingsApplied = /* @__PURE__ */ new Set();
2751
+ const bindingContext2 = getBindingContext(viewModelOrBindingContext);
2752
+ const bindingAccessors = getBindingProvider().makeBindingAccessors(bindings, bindingContext2, node);
2753
+ applyBindingAccessorsToNode(node, bindingAccessors, bindingContext2, asyncBindingsApplied);
2754
+ return new BindingResult({ asyncBindingsApplied, rootNode: node, bindingContext: bindingContext2 });
2755
+ }
2756
+ function applyBindingsToDescendants(viewModelOrBindingContext, rootNode) {
2757
+ const asyncBindingsApplied = /* @__PURE__ */ new Set();
2758
+ if (rootNode.nodeType === 1 || rootNode.nodeType === 8) {
2759
+ const bindingContext2 = getBindingContext(viewModelOrBindingContext);
2760
+ applyBindingsToDescendantsInternal(bindingContext2, rootNode, asyncBindingsApplied);
2761
+ return new BindingResult({ asyncBindingsApplied, rootNode, bindingContext: bindingContext2 });
2762
+ }
2763
+ return new BindingResult({ asyncBindingsApplied, rootNode });
2764
+ }
2765
+ function applyBindings(viewModelOrBindingContext, rootNode, extendContextCallback) {
2766
+ const asyncBindingsApplied = /* @__PURE__ */ new Set();
2767
+ if (!options_default.jQuery === void 0 && options_default.jQuery) {
2768
+ options_default.jQuery = options_default.jQuery;
2769
+ }
2770
+ if (!rootNode) {
2771
+ rootNode = window.document.body;
2772
+ if (!rootNode) {
2773
+ throw Error("ko.applyBindings: could not find window.document.body; has the document been loaded?");
2774
+ }
2775
+ } else if (rootNode.nodeType !== 1 && rootNode.nodeType !== 8) {
2776
+ throw Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node");
2777
+ }
2778
+ const rootContext = getBindingContext(viewModelOrBindingContext, extendContextCallback);
2779
+ applyBindingsToNodeAndDescendantsInternal(rootContext, rootNode, asyncBindingsApplied);
2780
+ return Promise.all(asyncBindingsApplied);
2781
+ }
2782
+ function onBindingError(spec) {
2783
+ var error, bindingText;
2784
+ if (spec.bindingKey) {
2785
+ error = spec.errorCaptured;
2786
+ spec.message = 'Unable to process binding "' + spec.bindingKey + '" in binding "' + spec.bindingKey + '"\nMessage: ' + (error.message ? error.message : error);
2787
+ } else {
2788
+ error = spec.errorCaptured;
2789
+ }
2790
+ try {
2791
+ extend(error, spec);
2792
+ } catch (e) {
2793
+ spec.stack = error.stack;
2794
+ error = new Error(error.message ? error.message : error);
2795
+ extend(error, spec);
2796
+ }
2797
+ options_default.onError(error);
2798
+ }
2799
+
2800
+ // src/arrayToDomNodeChildren.ts
2801
+ function mapNodeAndRefreshWhenChanged(containerNode, mapping, valueToMap, callbackAfterAddingNodes, index) {
2802
+ var mappedNodes = [];
2803
+ var dependentObservable = computed(function() {
2804
+ var newMappedNodes = mapping(valueToMap, index, fixUpContinuousNodeArray(mappedNodes, containerNode)) || [];
2805
+ if (mappedNodes.length > 0) {
2806
+ replaceDomNodes(mappedNodes, newMappedNodes);
2807
+ if (callbackAfterAddingNodes) {
2808
+ dependencyDetection_exports.ignore(callbackAfterAddingNodes, null, [valueToMap, newMappedNodes, index]);
2809
+ }
2810
+ }
2811
+ mappedNodes.length = 0;
2812
+ arrayPushAll(mappedNodes, newMappedNodes);
2813
+ }, null, { disposeWhenNodeIsRemoved: containerNode, disposeWhen: function() {
2814
+ return !anyDomNodeIsAttachedToDocument(mappedNodes);
2815
+ } });
2816
+ return { mappedNodes, dependentObservable: dependentObservable.isActive() ? dependentObservable : void 0 };
2817
+ }
2818
+ var lastMappingResultDomDataKey = data_exports.nextKey();
2819
+ var deletedItemDummyValue = data_exports.nextKey();
2820
+ function setDomNodeChildrenFromArrayMapping(domNode, array, mapping, options2, callbackAfterAddingNodes, editScript) {
2821
+ array = array || [];
2822
+ if (typeof array.length === "undefined") {
2823
+ array = [array];
2824
+ }
2825
+ options2 = options2 || {};
2826
+ let lastMappingResult = data_exports.get(domNode, lastMappingResultDomDataKey);
2827
+ let isFirstExecution = !lastMappingResult;
2828
+ var newMappingResult = [];
2829
+ var lastMappingResultIndex = 0;
2830
+ var newMappingResultIndex = 0;
2831
+ var nodesToDelete = [];
2832
+ var itemsToProcess = [];
2833
+ var itemsForBeforeRemoveCallbacks = [];
2834
+ var itemsForMoveCallbacks = [];
2835
+ var itemsForAfterAddCallbacks = [];
2836
+ var mapData;
2837
+ let countWaitingForRemove = 0;
2838
+ function itemAdded(value) {
2839
+ mapData = { arrayEntry: value, indexObservable: observable(newMappingResultIndex++) };
2840
+ newMappingResult.push(mapData);
2841
+ itemsToProcess.push(mapData);
2842
+ if (!isFirstExecution) {
2843
+ itemsForAfterAddCallbacks.push(mapData);
2844
+ }
2845
+ }
2846
+ function itemMovedOrRetained(oldPosition) {
2847
+ mapData = lastMappingResult[oldPosition];
2848
+ if (newMappingResultIndex !== oldPosition) {
2849
+ itemsForMoveCallbacks.push(mapData);
2850
+ }
2851
+ mapData.indexObservable(newMappingResultIndex++);
2852
+ fixUpContinuousNodeArray(mapData.mappedNodes, domNode);
2853
+ newMappingResult.push(mapData);
2854
+ itemsToProcess.push(mapData);
2855
+ }
2856
+ function callCallback(callback, items) {
2857
+ if (callback) {
2858
+ for (var i2 = 0, n = items.length; i2 < n; i2++) {
2859
+ arrayForEach(items[i2].mappedNodes, function(node2) {
2860
+ callback(node2, i2, items[i2].arrayEntry);
2861
+ });
2862
+ }
2863
+ }
2864
+ }
2865
+ if (isFirstExecution) {
2866
+ arrayForEach(array, itemAdded);
2867
+ } else {
2868
+ if (!editScript || lastMappingResult && lastMappingResult["_countWaitingForRemove"]) {
2869
+ var lastArray = isFirstExecution ? [] : arrayMap(lastMappingResult, function(x) {
2870
+ return x.arrayEntry;
2871
+ });
2872
+ var compareOptions = {
2873
+ "dontLimitMoves": options2["dontLimitMoves"],
2874
+ "sparse": true
2875
+ };
2876
+ editScript = compareArrays(lastArray, array, compareOptions);
2877
+ }
2878
+ for (var i = 0, editScriptItem, movedIndex, itemIndex; editScriptItem = editScript[i]; i++) {
2879
+ movedIndex = editScriptItem["moved"];
2880
+ itemIndex = editScriptItem["index"];
2881
+ switch (editScriptItem["status"]) {
2882
+ case "deleted":
2883
+ while (lastMappingResultIndex < itemIndex) {
2884
+ itemMovedOrRetained(lastMappingResultIndex++);
2885
+ }
2886
+ if (movedIndex === void 0) {
2887
+ mapData = lastMappingResult[lastMappingResultIndex];
2888
+ if (mapData.dependentObservable) {
2889
+ mapData.dependentObservable.dispose();
2890
+ mapData.dependentObservable = void 0;
2891
+ }
2892
+ if (fixUpContinuousNodeArray(mapData.mappedNodes, domNode).length) {
2893
+ if (options2["beforeRemove"]) {
2894
+ newMappingResult.push(mapData);
2895
+ itemsToProcess.push(mapData);
2896
+ countWaitingForRemove++;
2897
+ if (mapData.arrayEntry === deletedItemDummyValue) {
2898
+ mapData = null;
2899
+ } else {
2900
+ itemsForBeforeRemoveCallbacks.push(mapData);
2901
+ }
2902
+ }
2903
+ if (mapData) {
2904
+ nodesToDelete.push.apply(nodesToDelete, mapData.mappedNodes);
2905
+ }
2906
+ }
2907
+ }
2908
+ lastMappingResultIndex++;
2909
+ break;
2910
+ case "added":
2911
+ while (newMappingResultIndex < itemIndex) {
2912
+ itemMovedOrRetained(lastMappingResultIndex++);
2913
+ }
2914
+ if (movedIndex !== void 0) {
2915
+ itemMovedOrRetained(movedIndex);
2916
+ } else {
2917
+ itemAdded(editScriptItem["value"]);
2918
+ }
2919
+ break;
2920
+ }
2921
+ }
2922
+ while (newMappingResultIndex < array.length) {
2923
+ itemMovedOrRetained(lastMappingResultIndex++);
2924
+ }
2925
+ newMappingResult["_countWaitingForRemove"] = countWaitingForRemove;
2926
+ }
2927
+ data_exports.set(domNode, lastMappingResultDomDataKey, newMappingResult);
2928
+ callCallback(options2["beforeMove"], itemsForMoveCallbacks);
2929
+ arrayForEach(nodesToDelete, options2["beforeRemove"] ? cleanNode : removeNode);
2930
+ i = 0;
2931
+ for (var nextNode = virtualElements_exports.firstChild(domNode), lastNode, node; mapData = itemsToProcess[i]; i++) {
2932
+ if (!mapData.mappedNodes) {
2933
+ extend(mapData, mapNodeAndRefreshWhenChanged(domNode, mapping, mapData.arrayEntry, callbackAfterAddingNodes, mapData.indexObservable));
2934
+ }
2935
+ for (var j = 0; node = mapData.mappedNodes[j]; nextNode = node.nextSibling, lastNode = node, j++) {
2936
+ if (node !== nextNode) {
2937
+ virtualElements_exports.insertAfter(domNode, node, lastNode);
2938
+ }
2939
+ }
2940
+ if (!mapData.initialized && callbackAfterAddingNodes) {
2941
+ callbackAfterAddingNodes(mapData.arrayEntry, mapData.mappedNodes, mapData.indexObservable);
2942
+ mapData.initialized = true;
2943
+ }
2944
+ }
2945
+ callCallback(options2["beforeRemove"], itemsForBeforeRemoveCallbacks);
2946
+ for (i = 0; i < itemsForBeforeRemoveCallbacks.length; ++i) {
2947
+ itemsForBeforeRemoveCallbacks[i].arrayEntry = deletedItemDummyValue;
2948
+ }
2949
+ callCallback(options2["afterMove"], itemsForMoveCallbacks);
2950
+ callCallback(options2["afterAdd"], itemsForAfterAddCallbacks);
2951
+ }
2952
+
2953
+ // src/DescendantBindingHandler.ts
2954
+ var DescendantBindingHandler = class extends AsyncBindingHandler {
2955
+ get controlsDescendants() {
2956
+ return true;
2957
+ }
2958
+ applyBindingsToDescendants(childContext, callback) {
2959
+ return __async(this, null, function* () {
2960
+ const bindingResult = applyBindingsToDescendants(childContext, this.$element);
2961
+ if (bindingResult.isSync) {
2962
+ this.bindingCompletion = bindingResult;
2963
+ } else {
2964
+ yield bindingResult.completionPromise;
2965
+ }
2966
+ if (callback) {
2967
+ callback(bindingResult);
2968
+ }
2969
+ this.completeBinding(bindingResult);
2970
+ });
2971
+ }
2972
+ };