@tko/utils 4.0.0-alpha7.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.
Files changed (59) hide show
  1. package/LICENSE +22 -0
  2. package/dist/array.js +156 -0
  3. package/dist/array.js.map +7 -0
  4. package/dist/async.js +20 -0
  5. package/dist/async.js.map +7 -0
  6. package/dist/bind-shim.js +18 -0
  7. package/dist/bind-shim.js.map +7 -0
  8. package/dist/css.js +27 -0
  9. package/dist/css.js.map +7 -0
  10. package/dist/dom/data.js +63 -0
  11. package/dist/dom/data.js.map +7 -0
  12. package/dist/dom/disposal.js +98 -0
  13. package/dist/dom/disposal.js.map +7 -0
  14. package/dist/dom/event.js +87 -0
  15. package/dist/dom/event.js.map +7 -0
  16. package/dist/dom/fixes.js +45 -0
  17. package/dist/dom/fixes.js.map +7 -0
  18. package/dist/dom/html.js +115 -0
  19. package/dist/dom/html.js.map +7 -0
  20. package/dist/dom/info.js +43 -0
  21. package/dist/dom/info.js.map +7 -0
  22. package/dist/dom/manipulation.js +55 -0
  23. package/dist/dom/manipulation.js.map +7 -0
  24. package/dist/dom/selectExtensions.js +62 -0
  25. package/dist/dom/selectExtensions.js.map +7 -0
  26. package/dist/dom/virtualElements.js +202 -0
  27. package/dist/dom/virtualElements.js.map +7 -0
  28. package/dist/error.js +22 -0
  29. package/dist/error.js.map +7 -0
  30. package/dist/function.js +16 -0
  31. package/dist/function.js.map +7 -0
  32. package/dist/ie.js +15 -0
  33. package/dist/ie.js.map +7 -0
  34. package/dist/index.cjs +1448 -0
  35. package/dist/index.cjs.map +7 -0
  36. package/dist/index.js +24 -0
  37. package/dist/index.js.map +7 -0
  38. package/dist/index.mjs +24 -0
  39. package/dist/index.mjs.map +7 -0
  40. package/dist/jquery.js +6 -0
  41. package/dist/jquery.js.map +7 -0
  42. package/dist/memoization.js +64 -0
  43. package/dist/memoization.js.map +7 -0
  44. package/dist/object.js +76 -0
  45. package/dist/object.js.map +7 -0
  46. package/dist/options.js +36 -0
  47. package/dist/options.js.map +7 -0
  48. package/dist/string.js +23 -0
  49. package/dist/string.js.map +7 -0
  50. package/dist/symbol.js +5 -0
  51. package/dist/symbol.js.map +7 -0
  52. package/dist/tasks.js +76 -0
  53. package/dist/tasks.js.map +7 -0
  54. package/helpers/jasmine-13-helper.ts +207 -0
  55. package/package.json +18 -26
  56. package/dist/utils.es6.js +0 -1628
  57. package/dist/utils.es6.js.map +0 -1
  58. package/dist/utils.js +0 -1645
  59. package/dist/utils.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,1448 @@
1
+ // @tko/utils 🥊 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
+
20
+ // index.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ addCleaner: () => addCleaner,
24
+ addDisposeCallback: () => addDisposeCallback,
25
+ addOrRemoveItem: () => addOrRemoveItem,
26
+ anyDomNodeIsAttachedToDocument: () => anyDomNodeIsAttachedToDocument,
27
+ arrayFilter: () => arrayFilter,
28
+ arrayFirst: () => arrayFirst,
29
+ arrayForEach: () => arrayForEach,
30
+ arrayGetDistinctValues: () => arrayGetDistinctValues,
31
+ arrayIndexOf: () => arrayIndexOf,
32
+ arrayMap: () => arrayMap,
33
+ arrayPushAll: () => arrayPushAll,
34
+ arrayRemoveItem: () => arrayRemoveItem,
35
+ catchFunctionErrors: () => catchFunctionErrors,
36
+ cleanNode: () => cleanNode,
37
+ cleanjQueryData: () => cleanjQueryData,
38
+ cloneNodes: () => cloneNodes,
39
+ clonePlainObjectDeep: () => clonePlainObjectDeep,
40
+ compareArrays: () => compareArrays,
41
+ createSymbolOrString: () => createSymbolOrString,
42
+ debounce: () => debounce,
43
+ deferError: () => deferError,
44
+ domData: () => data_exports,
45
+ domNodeIsAttachedToDocument: () => domNodeIsAttachedToDocument,
46
+ domNodeIsContainedBy: () => domNodeIsContainedBy,
47
+ emptyDomNode: () => emptyDomNode,
48
+ ensureSelectElementIsRenderedCorrectly: () => ensureSelectElementIsRenderedCorrectly,
49
+ extend: () => extend,
50
+ findMovesInArrayComparison: () => findMovesInArrayComparison,
51
+ fixUpContinuousNodeArray: () => fixUpContinuousNodeArray,
52
+ forceRefresh: () => forceRefresh,
53
+ functionSupportsLengthOverwrite: () => functionSupportsLengthOverwrite,
54
+ getObjectOwnProperty: () => getObjectOwnProperty,
55
+ hasOwnProperty: () => hasOwnProperty,
56
+ ieVersion: () => ieVersion,
57
+ isDocumentFragment: () => isDocumentFragment,
58
+ isDomElement: () => isDomElement,
59
+ isIe6: () => isIe6,
60
+ isIe7: () => isIe7,
61
+ isObjectLike: () => isObjectLike,
62
+ isThenable: () => isThenable,
63
+ jQuerySetInstance: () => jQuerySetInstance,
64
+ makeArray: () => makeArray,
65
+ memoization: () => memoization_exports,
66
+ moveCleanedNodesToContainerElement: () => moveCleanedNodesToContainerElement,
67
+ objectForEach: () => objectForEach,
68
+ objectMap: () => objectMap,
69
+ options: () => options_default,
70
+ otherNodeCleanerFunctions: () => otherNodeCleanerFunctions,
71
+ overwriteLengthPropertyIfSupported: () => overwriteLengthPropertyIfSupported,
72
+ parseHtmlForTemplateNodes: () => parseHtmlForTemplateNodes,
73
+ parseHtmlFragment: () => parseHtmlFragment,
74
+ parseJson: () => parseJson,
75
+ range: () => range,
76
+ registerEventHandler: () => registerEventHandler,
77
+ removeCleaner: () => removeCleaner,
78
+ removeDisposeCallback: () => removeDisposeCallback,
79
+ removeNode: () => removeNode,
80
+ replaceDomNodes: () => replaceDomNodes,
81
+ safeSetTimeout: () => safeSetTimeout,
82
+ safeStringify: () => safeStringify,
83
+ selectExtensions: () => selectExtensions,
84
+ setDomNodeChildren: () => setDomNodeChildren,
85
+ setElementName: () => setElementName,
86
+ setHtml: () => setHtml,
87
+ setOptionNodeSelectionState: () => setOptionNodeSelectionState,
88
+ setTextContent: () => setTextContent,
89
+ stringStartsWith: () => stringStartsWith,
90
+ stringTrim: () => stringTrim,
91
+ tagNameLower: () => tagNameLower,
92
+ tasks: () => tasks_exports,
93
+ throttle: () => throttle,
94
+ toggleDomNodeCssClass: () => toggleDomNodeCssClass,
95
+ triggerEvent: () => triggerEvent,
96
+ useSymbols: () => useSymbols,
97
+ virtualElements: () => virtualElements_exports
98
+ });
99
+ module.exports = __toCommonJS(utils_exports);
100
+
101
+ // src/array.ts
102
+ var { isArray } = Array;
103
+ function arrayForEach(array, action, thisArg) {
104
+ if (arguments.length > 2) {
105
+ action = action.bind(thisArg);
106
+ }
107
+ for (let i = 0, j = array.length; i < j; ++i) {
108
+ action(array[i], i, array);
109
+ }
110
+ }
111
+ function arrayIndexOf(array, item) {
112
+ return (isArray(array) ? array : [...array]).indexOf(item);
113
+ }
114
+ function arrayFirst(array, predicate, predicateOwner) {
115
+ return (isArray(array) ? array : [...array]).find(predicate, predicateOwner);
116
+ }
117
+ function arrayMap(array = [], mapping, thisArg) {
118
+ if (arguments.length > 2) {
119
+ mapping = mapping.bind(thisArg);
120
+ }
121
+ return array === null ? [] : Array.from(array, mapping);
122
+ }
123
+ function arrayRemoveItem(array, itemToRemove) {
124
+ var index = arrayIndexOf(array, itemToRemove);
125
+ if (index > 0) {
126
+ array.splice(index, 1);
127
+ } else if (index === 0) {
128
+ array.shift();
129
+ }
130
+ }
131
+ function arrayGetDistinctValues(array = []) {
132
+ const seen = /* @__PURE__ */ new Set();
133
+ if (array === null) {
134
+ return [];
135
+ }
136
+ return (isArray(array) ? array : [...array]).filter((item) => seen.has(item) ? false : seen.add(item));
137
+ }
138
+ function arrayFilter(array, predicate, thisArg) {
139
+ if (arguments.length > 2) {
140
+ predicate = predicate.bind(thisArg);
141
+ }
142
+ return array === null ? [] : (isArray(array) ? array : [...array]).filter(predicate);
143
+ }
144
+ function arrayPushAll(array, valuesToPush) {
145
+ if (isArray(valuesToPush)) {
146
+ array.push.apply(array, valuesToPush);
147
+ } else {
148
+ for (var i = 0, j = valuesToPush.length; i < j; i++) {
149
+ array.push(valuesToPush[i]);
150
+ }
151
+ }
152
+ return array;
153
+ }
154
+ function addOrRemoveItem(array, value, included) {
155
+ var existingEntryIndex = arrayIndexOf(typeof array.peek === "function" ? array.peek() : array, value);
156
+ if (existingEntryIndex < 0) {
157
+ if (included) {
158
+ array.push(value);
159
+ }
160
+ } else {
161
+ if (!included) {
162
+ array.splice(existingEntryIndex, 1);
163
+ }
164
+ }
165
+ }
166
+ function makeArray(arrayLikeObject) {
167
+ return Array.from(arrayLikeObject);
168
+ }
169
+ function range(min, max) {
170
+ min = typeof min === "function" ? min() : min;
171
+ max = typeof max === "function" ? max() : max;
172
+ var result = [];
173
+ for (var i = min; i <= max; i++) {
174
+ result.push(i);
175
+ }
176
+ return result;
177
+ }
178
+ function findMovesInArrayComparison(left, right, limitFailedCompares) {
179
+ if (left.length && right.length) {
180
+ var failedCompares, l, r, leftItem, rightItem;
181
+ for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) {
182
+ for (r = 0; rightItem = right[r]; ++r) {
183
+ if (leftItem.value === rightItem.value) {
184
+ leftItem.moved = rightItem.index;
185
+ rightItem.moved = leftItem.index;
186
+ right.splice(r, 1);
187
+ failedCompares = r = 0;
188
+ break;
189
+ }
190
+ }
191
+ failedCompares += r;
192
+ }
193
+ }
194
+ }
195
+ var statusNotInOld = "added";
196
+ var statusNotInNew = "deleted";
197
+ function compareArrays(oldArray, newArray, options2) {
198
+ options2 = typeof options2 === "boolean" ? { dontLimitMoves: options2 } : options2 || {};
199
+ oldArray = oldArray || [];
200
+ newArray = newArray || [];
201
+ if (oldArray.length < newArray.length) {
202
+ return compareSmallArrayToBigArray(oldArray, newArray, statusNotInOld, statusNotInNew, options2);
203
+ } else {
204
+ return compareSmallArrayToBigArray(newArray, oldArray, statusNotInNew, statusNotInOld, options2);
205
+ }
206
+ }
207
+ function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, options2) {
208
+ 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;
209
+ for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
210
+ lastRow = thisRow;
211
+ editDistanceMatrix.push(thisRow = []);
212
+ bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
213
+ bigIndexMinForRow = myMax(0, smlIndex - 1);
214
+ for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
215
+ if (!bigIndex) {
216
+ thisRow[bigIndex] = smlIndex + 1;
217
+ } else if (!smlIndex) {
218
+ thisRow[bigIndex] = bigIndex + 1;
219
+ } else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1]) {
220
+ thisRow[bigIndex] = lastRow[bigIndex - 1];
221
+ } else {
222
+ var northDistance = lastRow[bigIndex] || maxDistance;
223
+ var westDistance = thisRow[bigIndex - 1] || maxDistance;
224
+ thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
225
+ }
226
+ }
227
+ }
228
+ var editScript = [], meMinusOne, notInSml = [], notInBig = [];
229
+ for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex; ) {
230
+ meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
231
+ if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {
232
+ notInSml.push(editScript[editScript.length] = {
233
+ "status": statusNotInSml,
234
+ "value": bigArray[--bigIndex],
235
+ "index": bigIndex
236
+ });
237
+ } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
238
+ notInBig.push(editScript[editScript.length] = {
239
+ "status": statusNotInBig,
240
+ "value": smlArray[--smlIndex],
241
+ "index": smlIndex
242
+ });
243
+ } else {
244
+ --bigIndex;
245
+ --smlIndex;
246
+ if (!options2.sparse) {
247
+ editScript.push({
248
+ "status": "retained",
249
+ "value": bigArray[bigIndex]
250
+ });
251
+ }
252
+ }
253
+ }
254
+ findMovesInArrayComparison(notInBig, notInSml, !options2.dontLimitMoves && smlIndexMax * 10);
255
+ return editScript.reverse();
256
+ }
257
+
258
+ // src/options.ts
259
+ var options = {
260
+ deferUpdates: false,
261
+ useOnlyNativeEvents: false,
262
+ protoProperty: "__ko_proto__",
263
+ defaultBindingAttribute: "data-bind",
264
+ allowVirtualElements: true,
265
+ bindingGlobals: /* @__PURE__ */ Object.create(null),
266
+ bindingProviderInstance: null,
267
+ createChildContextWithAs: false,
268
+ jQuery: globalThis.jQuery,
269
+ Promise: globalThis.Promise,
270
+ taskScheduler: null,
271
+ debug: false,
272
+ global: globalThis,
273
+ document: globalThis.document,
274
+ filters: {},
275
+ includeDestroyed: false,
276
+ foreachHidesDestroyed: false,
277
+ onError: function(e) {
278
+ throw e;
279
+ },
280
+ set: function(name, value) {
281
+ options[name] = value;
282
+ },
283
+ getBindingHandler() {
284
+ },
285
+ cleanExternalData() {
286
+ }
287
+ };
288
+ Object.defineProperty(options, "$", {
289
+ get: function() {
290
+ return options.jQuery;
291
+ }
292
+ });
293
+ var options_default = options;
294
+
295
+ // src/error.ts
296
+ function catchFunctionErrors(delegate) {
297
+ if (!options_default.onError) {
298
+ return delegate;
299
+ }
300
+ return (...args) => {
301
+ try {
302
+ return delegate(...args);
303
+ } catch (err) {
304
+ options_default.onError(err);
305
+ }
306
+ };
307
+ }
308
+ function deferError(error) {
309
+ safeSetTimeout(function() {
310
+ throw error;
311
+ }, 0);
312
+ }
313
+ function safeSetTimeout(handler, timeout) {
314
+ return setTimeout(catchFunctionErrors(handler), timeout);
315
+ }
316
+
317
+ // src/async.ts
318
+ function throttle(callback, timeout) {
319
+ var timeoutInstance;
320
+ return function(...args) {
321
+ if (!timeoutInstance) {
322
+ timeoutInstance = safeSetTimeout(function() {
323
+ timeoutInstance = void 0;
324
+ callback(...args);
325
+ }, timeout);
326
+ }
327
+ };
328
+ }
329
+ function debounce(callback, timeout) {
330
+ var timeoutInstance;
331
+ return function(...args) {
332
+ clearTimeout(timeoutInstance);
333
+ timeoutInstance = safeSetTimeout(() => callback(...args), timeout);
334
+ };
335
+ }
336
+
337
+ // src/ie.ts
338
+ var ieVersion = options_default.document && function() {
339
+ var version = 3, div = options_default.document.createElement("div"), iElems = div.getElementsByTagName("i");
340
+ while (div.innerHTML = "<!--[if gt IE " + ++version + "]><i></i><![endif]-->", iElems[0]) {
341
+ }
342
+ if (!version) {
343
+ const userAgent = window.navigator.userAgent;
344
+ return ua.match(/MSIE ([^ ]+)/) || ua.match(/rv:([^ )]+)/);
345
+ }
346
+ return version > 4 ? version : void 0;
347
+ }();
348
+ var isIe6 = ieVersion === 6;
349
+ var isIe7 = ieVersion === 7;
350
+
351
+ // src/object.ts
352
+ function hasOwnProperty(obj, propName) {
353
+ return Object.prototype.hasOwnProperty.call(obj, propName);
354
+ }
355
+ function isObjectLike(obj) {
356
+ if (obj === null) {
357
+ return false;
358
+ }
359
+ return typeof obj === "object" || typeof obj === "function";
360
+ }
361
+ function extend(target, source) {
362
+ if (source) {
363
+ for (var prop in source) {
364
+ if (hasOwnProperty(source, prop)) {
365
+ target[prop] = source[prop];
366
+ }
367
+ }
368
+ }
369
+ return target;
370
+ }
371
+ function objectForEach(obj, action) {
372
+ for (var prop in obj) {
373
+ if (hasOwnProperty(obj, prop)) {
374
+ action(prop, obj[prop]);
375
+ }
376
+ }
377
+ }
378
+ function objectMap(source, mapping, thisArg) {
379
+ if (!source) {
380
+ return source;
381
+ }
382
+ if (arguments.length > 2) {
383
+ mapping = mapping.bind(thisArg);
384
+ }
385
+ var target = {};
386
+ for (var prop in source) {
387
+ if (hasOwnProperty(source, prop)) {
388
+ target[prop] = mapping(source[prop], prop, source);
389
+ }
390
+ }
391
+ return target;
392
+ }
393
+ function getObjectOwnProperty(obj, propName) {
394
+ return hasOwnProperty(obj, propName) ? obj[propName] : void 0;
395
+ }
396
+ function clonePlainObjectDeep(obj, seen) {
397
+ if (!seen) {
398
+ seen = [];
399
+ }
400
+ if (!obj || typeof obj !== "object" || obj.constructor !== Object || seen.indexOf(obj) !== -1) {
401
+ return obj;
402
+ }
403
+ seen.push(obj);
404
+ var result = {};
405
+ for (var prop in obj) {
406
+ if (hasOwnProperty(obj, prop)) {
407
+ result[prop] = clonePlainObjectDeep(obj[prop], seen);
408
+ }
409
+ }
410
+ return result;
411
+ }
412
+ function safeStringify(value) {
413
+ const seen = /* @__PURE__ */ new Set();
414
+ return JSON.stringify(value, (k, v) => {
415
+ if (seen.has(v)) {
416
+ return "...";
417
+ }
418
+ if (typeof v === "object") {
419
+ seen.add(v);
420
+ }
421
+ return v;
422
+ });
423
+ }
424
+ function isThenable(object2) {
425
+ return isObjectLike(object2) && typeof object2.then === "function";
426
+ }
427
+
428
+ // src/function.ts
429
+ function testOverwrite() {
430
+ try {
431
+ Object.defineProperty(function x() {
432
+ }, "length", {});
433
+ return true;
434
+ } catch (e) {
435
+ return false;
436
+ }
437
+ }
438
+ var functionSupportsLengthOverwrite = testOverwrite();
439
+ function overwriteLengthPropertyIfSupported(fn, descriptor) {
440
+ if (functionSupportsLengthOverwrite) {
441
+ Object.defineProperty(fn, "length", descriptor);
442
+ }
443
+ }
444
+
445
+ // src/string.ts
446
+ function stringTrim(string) {
447
+ return string === null || string === void 0 ? "" : string.trim ? string.trim() : string.toString().replace(/^[\s\xa0]+|[\s\xa0]+$/g, "");
448
+ }
449
+ function stringStartsWith(string, startsWith) {
450
+ string = string || "";
451
+ if (startsWith.length > string.length) {
452
+ return false;
453
+ }
454
+ return string.substring(0, startsWith.length) === startsWith;
455
+ }
456
+ function parseJson(jsonString) {
457
+ if (typeof jsonString === "string") {
458
+ jsonString = stringTrim(jsonString);
459
+ if (jsonString) {
460
+ if (JSON && JSON.parse) {
461
+ return JSON.parse(jsonString);
462
+ }
463
+ return new Function("return " + jsonString)();
464
+ }
465
+ }
466
+ return null;
467
+ }
468
+
469
+ // src/symbol.ts
470
+ var useSymbols = typeof Symbol === "function";
471
+ function createSymbolOrString(identifier) {
472
+ return useSymbols ? Symbol(identifier) : identifier;
473
+ }
474
+
475
+ // src/css.ts
476
+ var cssClassNameRegex = /\S+/g;
477
+ function toggleDomNodeCssClass(node, classNames, shouldHaveClass) {
478
+ var addOrRemoveFn;
479
+ if (!classNames) {
480
+ return;
481
+ }
482
+ if (typeof node.classList === "object") {
483
+ addOrRemoveFn = node.classList[shouldHaveClass ? "add" : "remove"];
484
+ arrayForEach(classNames.match(cssClassNameRegex), function(className) {
485
+ addOrRemoveFn.call(node.classList, className);
486
+ });
487
+ } else if (typeof node.className["baseVal"] === "string") {
488
+ toggleObjectClassPropertyString(node.className, "baseVal", classNames, shouldHaveClass);
489
+ } else {
490
+ toggleObjectClassPropertyString(node, "className", classNames, shouldHaveClass);
491
+ }
492
+ }
493
+ function toggleObjectClassPropertyString(obj, prop, classNames, shouldHaveClass) {
494
+ var currentClassNames = obj[prop].match(cssClassNameRegex) || [];
495
+ arrayForEach(classNames.match(cssClassNameRegex), function(className) {
496
+ addOrRemoveItem(currentClassNames, className, shouldHaveClass);
497
+ });
498
+ obj[prop] = currentClassNames.join(" ");
499
+ }
500
+
501
+ // src/jquery.ts
502
+ var jQueryInstance = options_default.global && options_default.global.jQuery;
503
+ function jQuerySetInstance(jquery) {
504
+ options_default.jQuery = jQueryInstance = jquery;
505
+ }
506
+
507
+ // src/dom/info.ts
508
+ function domNodeIsContainedBy(node, containedByNode) {
509
+ if (node === containedByNode) {
510
+ return true;
511
+ }
512
+ if (node.nodeType === 11) {
513
+ return false;
514
+ }
515
+ if (containedByNode.contains) {
516
+ return containedByNode.contains(node.nodeType !== 1 ? node.parentNode : node);
517
+ }
518
+ if (containedByNode.compareDocumentPosition) {
519
+ return (containedByNode.compareDocumentPosition(node) & 16) == 16;
520
+ }
521
+ while (node && node != containedByNode) {
522
+ node = node.parentNode;
523
+ }
524
+ return !!node;
525
+ }
526
+ function domNodeIsAttachedToDocument(node) {
527
+ return domNodeIsContainedBy(node, node.ownerDocument.documentElement);
528
+ }
529
+ function anyDomNodeIsAttachedToDocument(nodes) {
530
+ return !!arrayFirst(nodes, domNodeIsAttachedToDocument);
531
+ }
532
+ function tagNameLower(element) {
533
+ return element && element.tagName && element.tagName.toLowerCase();
534
+ }
535
+ function isDomElement(obj) {
536
+ if (window.HTMLElement) {
537
+ return obj instanceof HTMLElement;
538
+ } else {
539
+ return obj && obj.tagName && obj.nodeType === 1;
540
+ }
541
+ }
542
+ function isDocumentFragment(obj) {
543
+ if (window.DocumentFragment) {
544
+ return obj instanceof DocumentFragment;
545
+ } else {
546
+ return obj && obj.nodeType === 11;
547
+ }
548
+ }
549
+
550
+ // src/dom/data.ts
551
+ var data_exports = {};
552
+ __export(data_exports, {
553
+ clear: () => clear,
554
+ get: () => get,
555
+ getOrSet: () => getOrSet,
556
+ nextKey: () => nextKey,
557
+ set: () => set
558
+ });
559
+ var datastoreTime = new Date().getTime();
560
+ var dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`;
561
+ var dataStoreSymbol = Symbol("Knockout data");
562
+ var dataStore;
563
+ var uniqueId = 0;
564
+ var modern = {
565
+ getDataForNode(node, createIfNotFound) {
566
+ let dataForNode = node[dataStoreSymbol];
567
+ if (!dataForNode && createIfNotFound) {
568
+ dataForNode = node[dataStoreSymbol] = {};
569
+ }
570
+ return dataForNode;
571
+ },
572
+ clear(node) {
573
+ if (node[dataStoreSymbol]) {
574
+ delete node[dataStoreSymbol];
575
+ return true;
576
+ }
577
+ return false;
578
+ }
579
+ };
580
+ var IE = {
581
+ getDataforNode(node, createIfNotFound) {
582
+ let dataStoreKey = node[dataStoreKeyExpandoPropertyName];
583
+ const hasExistingDataStore = dataStoreKey && dataStoreKey !== "null" && dataStore[dataStoreKey];
584
+ if (!hasExistingDataStore) {
585
+ if (!createIfNotFound) {
586
+ return void 0;
587
+ }
588
+ dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++;
589
+ dataStore[dataStoreKey] = {};
590
+ }
591
+ return dataStore[dataStoreKey];
592
+ },
593
+ clear(node) {
594
+ const dataStoreKey = node[dataStoreKeyExpandoPropertyName];
595
+ if (dataStoreKey) {
596
+ delete dataStore[dataStoreKey];
597
+ node[dataStoreKeyExpandoPropertyName] = null;
598
+ return true;
599
+ }
600
+ return false;
601
+ }
602
+ };
603
+ var { getDataForNode, clear } = ieVersion ? IE : modern;
604
+ function nextKey() {
605
+ return uniqueId++ + dataStoreKeyExpandoPropertyName;
606
+ }
607
+ function get(node, key) {
608
+ const dataForNode = getDataForNode(node, false);
609
+ return dataForNode && dataForNode[key];
610
+ }
611
+ function set(node, key, value) {
612
+ var dataForNode = getDataForNode(node, value !== void 0);
613
+ dataForNode && (dataForNode[key] = value);
614
+ }
615
+ function getOrSet(node, key, value) {
616
+ const dataForNode = getDataForNode(node, true);
617
+ return dataForNode[key] || (dataForNode[key] = value);
618
+ }
619
+
620
+ // src/dom/disposal.ts
621
+ var domDataKey = nextKey();
622
+ var cleanableNodeTypes = { 1: true, 8: true, 9: true };
623
+ var cleanableNodeTypesWithDescendants = { 1: true, 9: true };
624
+ function getDisposeCallbacksCollection(node, createIfNotFound) {
625
+ var allDisposeCallbacks = get(node, domDataKey);
626
+ if (allDisposeCallbacks === void 0 && createIfNotFound) {
627
+ allDisposeCallbacks = [];
628
+ set(node, domDataKey, allDisposeCallbacks);
629
+ }
630
+ return allDisposeCallbacks;
631
+ }
632
+ function destroyCallbacksCollection(node) {
633
+ set(node, domDataKey, void 0);
634
+ }
635
+ function cleanSingleNode(node) {
636
+ var callbacks = getDisposeCallbacksCollection(node, false);
637
+ if (callbacks) {
638
+ callbacks = callbacks.slice(0);
639
+ for (let i = 0; i < callbacks.length; i++) {
640
+ callbacks[i](node);
641
+ }
642
+ }
643
+ clear(node);
644
+ for (let i = 0, j = otherNodeCleanerFunctions.length; i < j; ++i) {
645
+ otherNodeCleanerFunctions[i](node);
646
+ }
647
+ if (options_default.cleanExternalData) {
648
+ options_default.cleanExternalData(node);
649
+ }
650
+ if (cleanableNodeTypesWithDescendants[node.nodeType]) {
651
+ cleanNodesInList(node.childNodes, true);
652
+ }
653
+ }
654
+ function cleanNodesInList(nodeList, onlyComments) {
655
+ const cleanedNodes = [];
656
+ let lastCleanedNode;
657
+ for (var i = 0; i < nodeList.length; i++) {
658
+ if (!onlyComments || nodeList[i].nodeType === 8) {
659
+ cleanSingleNode(cleanedNodes[cleanedNodes.length] = lastCleanedNode = nodeList[i]);
660
+ if (nodeList[i] !== lastCleanedNode) {
661
+ while (i-- && arrayIndexOf(cleanedNodes, nodeList[i]) === -1) {
662
+ }
663
+ }
664
+ }
665
+ }
666
+ }
667
+ function addDisposeCallback(node, callback) {
668
+ if (typeof callback !== "function") {
669
+ throw new Error("Callback must be a function");
670
+ }
671
+ getDisposeCallbacksCollection(node, true).push(callback);
672
+ }
673
+ function removeDisposeCallback(node, callback) {
674
+ var callbacksCollection = getDisposeCallbacksCollection(node, false);
675
+ if (callbacksCollection) {
676
+ arrayRemoveItem(callbacksCollection, callback);
677
+ if (callbacksCollection.length === 0) {
678
+ destroyCallbacksCollection(node);
679
+ }
680
+ }
681
+ }
682
+ function cleanNode(node) {
683
+ if (cleanableNodeTypes[node.nodeType]) {
684
+ cleanSingleNode(node);
685
+ if (cleanableNodeTypesWithDescendants[node.nodeType]) {
686
+ cleanNodesInList(node.getElementsByTagName("*"));
687
+ }
688
+ }
689
+ return node;
690
+ }
691
+ function removeNode(node) {
692
+ cleanNode(node);
693
+ if (node.parentNode) {
694
+ node.parentNode.removeChild(node);
695
+ }
696
+ }
697
+ var otherNodeCleanerFunctions = [];
698
+ function addCleaner(fn) {
699
+ otherNodeCleanerFunctions.push(fn);
700
+ }
701
+ function removeCleaner(fn) {
702
+ const fnIndex = otherNodeCleanerFunctions.indexOf(fn);
703
+ if (fnIndex >= 0) {
704
+ otherNodeCleanerFunctions.splice(fnIndex, 1);
705
+ }
706
+ }
707
+ function cleanjQueryData(node) {
708
+ var jQueryCleanNodeFn = jQueryInstance ? jQueryInstance.cleanData : null;
709
+ if (jQueryCleanNodeFn) {
710
+ jQueryCleanNodeFn([node]);
711
+ }
712
+ }
713
+ otherNodeCleanerFunctions.push(cleanjQueryData);
714
+
715
+ // src/dom/event.ts
716
+ var knownEvents = {};
717
+ var knownEventTypesByEventName = {};
718
+ var keyEventTypeName = options_default.global.navigator && /Firefox\/2/i.test(options_default.global.navigator.userAgent) ? "KeyboardEvent" : "UIEvents";
719
+ knownEvents[keyEventTypeName] = ["keyup", "keydown", "keypress"];
720
+ knownEvents["MouseEvents"] = [
721
+ "click",
722
+ "dblclick",
723
+ "mousedown",
724
+ "mouseup",
725
+ "mousemove",
726
+ "mouseover",
727
+ "mouseout",
728
+ "mouseenter",
729
+ "mouseleave"
730
+ ];
731
+ objectForEach(knownEvents, function(eventType, knownEventsForType) {
732
+ if (knownEventsForType.length) {
733
+ for (var i = 0, j = knownEventsForType.length; i < j; i++) {
734
+ knownEventTypesByEventName[knownEventsForType[i]] = eventType;
735
+ }
736
+ }
737
+ });
738
+ function isClickOnCheckableElement(element, eventType) {
739
+ if (tagNameLower(element) !== "input" || !element.type)
740
+ return false;
741
+ if (eventType.toLowerCase() != "click")
742
+ return false;
743
+ var inputType = element.type;
744
+ return inputType == "checkbox" || inputType == "radio";
745
+ }
746
+ var eventsThatMustBeRegisteredUsingAttachEvent = { "propertychange": true };
747
+ var jQueryEventAttachName;
748
+ function registerEventHandler(element, eventType, handler, eventOptions = false) {
749
+ const wrappedHandler = catchFunctionErrors(handler);
750
+ const mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];
751
+ const mustUseNative = Boolean(eventOptions);
752
+ if (!options_default.useOnlyNativeEvents && !mustUseAttachEvent && !mustUseNative && jQueryInstance) {
753
+ if (!jQueryEventAttachName) {
754
+ jQueryEventAttachName = typeof jQueryInstance(element).on === "function" ? "on" : "bind";
755
+ }
756
+ jQueryInstance(element)[jQueryEventAttachName](eventType, wrappedHandler);
757
+ } else if (!mustUseAttachEvent && typeof element.addEventListener === "function") {
758
+ element.addEventListener(eventType, wrappedHandler, eventOptions);
759
+ } else if (typeof element.attachEvent !== "undefined") {
760
+ const attachEventHandler = function(event) {
761
+ wrappedHandler.call(element, event);
762
+ };
763
+ const attachEventName = "on" + eventType;
764
+ element.attachEvent(attachEventName, attachEventHandler);
765
+ addDisposeCallback(element, function() {
766
+ element.detachEvent(attachEventName, attachEventHandler);
767
+ });
768
+ } else {
769
+ throw new Error("Browser doesn't support addEventListener or attachEvent");
770
+ }
771
+ }
772
+ function triggerEvent(element, eventType) {
773
+ if (!(element && element.nodeType)) {
774
+ throw new Error("element must be a DOM node when calling triggerEvent");
775
+ }
776
+ var useClickWorkaround = isClickOnCheckableElement(element, eventType);
777
+ if (!options_default.useOnlyNativeEvents && jQueryInstance && !useClickWorkaround) {
778
+ jQueryInstance(element).trigger(eventType);
779
+ } else if (typeof document.createEvent === "function") {
780
+ if (typeof element.dispatchEvent === "function") {
781
+ var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";
782
+ var event = document.createEvent(eventCategory);
783
+ event.initEvent(eventType, true, true, options_default.global, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
784
+ element.dispatchEvent(event);
785
+ } else {
786
+ throw new Error("The supplied element doesn't support dispatchEvent");
787
+ }
788
+ } else if (useClickWorkaround && element.click) {
789
+ element.click();
790
+ } else if (typeof element.fireEvent !== "undefined") {
791
+ element.fireEvent("on" + eventType);
792
+ } else {
793
+ throw new Error("Browser doesn't support triggering events");
794
+ }
795
+ }
796
+
797
+ // src/dom/manipulation.ts
798
+ function moveCleanedNodesToContainerElement(nodes) {
799
+ var nodesArray = makeArray(nodes);
800
+ var templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document;
801
+ var container = templateDocument.createElement("div");
802
+ for (var i = 0, j = nodesArray.length; i < j; i++) {
803
+ container.appendChild(cleanNode(nodesArray[i]));
804
+ }
805
+ return container;
806
+ }
807
+ function cloneNodes(nodesArray, shouldCleanNodes) {
808
+ for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) {
809
+ var clonedNode = nodesArray[i].cloneNode(true);
810
+ newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode);
811
+ }
812
+ return newNodesArray;
813
+ }
814
+ function setDomNodeChildren(domNode, childNodes2) {
815
+ emptyDomNode(domNode);
816
+ if (childNodes2) {
817
+ for (var i = 0, j = childNodes2.length; i < j; i++) {
818
+ domNode.appendChild(childNodes2[i]);
819
+ }
820
+ }
821
+ }
822
+ function replaceDomNodes(nodeToReplaceOrNodeArray, newNodesArray) {
823
+ var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;
824
+ if (nodesToReplaceArray.length > 0) {
825
+ var insertionPoint = nodesToReplaceArray[0];
826
+ var parent = insertionPoint.parentNode;
827
+ for (var i = 0, j = newNodesArray.length; i < j; i++) {
828
+ parent.insertBefore(newNodesArray[i], insertionPoint);
829
+ }
830
+ for (i = 0, j = nodesToReplaceArray.length; i < j; i++) {
831
+ removeNode(nodesToReplaceArray[i]);
832
+ }
833
+ }
834
+ }
835
+ function setElementName(element, name) {
836
+ element.name = name;
837
+ if (ieVersion <= 7) {
838
+ try {
839
+ element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false);
840
+ } catch (e) {
841
+ }
842
+ }
843
+ }
844
+ function emptyDomNode(domNode) {
845
+ while (domNode.firstChild) {
846
+ removeNode(domNode.firstChild);
847
+ }
848
+ }
849
+
850
+ // src/dom/fixes.ts
851
+ function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
852
+ if (continuousNodeArray.length) {
853
+ parentNode = parentNode.nodeType === 8 && parentNode.parentNode || parentNode;
854
+ while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) {
855
+ continuousNodeArray.splice(0, 1);
856
+ }
857
+ while (continuousNodeArray.length > 1 && continuousNodeArray[continuousNodeArray.length - 1].parentNode !== parentNode) {
858
+ continuousNodeArray.length--;
859
+ }
860
+ if (continuousNodeArray.length > 1) {
861
+ var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1];
862
+ continuousNodeArray.length = 0;
863
+ while (current !== last) {
864
+ continuousNodeArray.push(current);
865
+ current = current.nextSibling;
866
+ }
867
+ continuousNodeArray.push(last);
868
+ }
869
+ }
870
+ return continuousNodeArray;
871
+ }
872
+ function setOptionNodeSelectionState(optionNode, isSelected) {
873
+ if (ieVersion < 7) {
874
+ optionNode.setAttribute("selected", isSelected);
875
+ } else {
876
+ optionNode.selected = isSelected;
877
+ }
878
+ }
879
+ function forceRefresh(node) {
880
+ if (ieVersion >= 9) {
881
+ var elem = node.nodeType == 1 ? node : node.parentNode;
882
+ if (elem.style) {
883
+ elem.style.zoom = elem.style.zoom;
884
+ }
885
+ }
886
+ }
887
+ function ensureSelectElementIsRenderedCorrectly(selectElement) {
888
+ if (ieVersion) {
889
+ var originalWidth = selectElement.style.width;
890
+ selectElement.style.width = 0;
891
+ selectElement.style.width = originalWidth;
892
+ }
893
+ }
894
+
895
+ // src/dom/virtualElements.ts
896
+ var virtualElements_exports = {};
897
+ __export(virtualElements_exports, {
898
+ allowedBindings: () => allowedBindings,
899
+ childNodes: () => childNodes,
900
+ emptyNode: () => emptyNode,
901
+ endCommentRegex: () => endCommentRegex,
902
+ firstChild: () => firstChild,
903
+ getVirtualChildren: () => getVirtualChildren,
904
+ hasBindingValue: () => hasBindingValue,
905
+ insertAfter: () => insertAfter,
906
+ isEndComment: () => isEndComment,
907
+ isStartComment: () => isStartComment,
908
+ lastChild: () => lastChild,
909
+ nextSibling: () => nextSibling,
910
+ normaliseVirtualElementDomStructure: () => normaliseVirtualElementDomStructure,
911
+ prepend: () => prepend,
912
+ previousSibling: () => previousSibling,
913
+ setDomNodeChildren: () => setDomNodeChildren2,
914
+ startCommentRegex: () => startCommentRegex,
915
+ virtualNodeBindingValue: () => virtualNodeBindingValue
916
+ });
917
+ var commentNodesHaveTextProperty = options_default.document && options_default.document.createComment("test").text === "<!--test-->";
918
+ var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+([\s\S]+))?\s*-->$/ : /^\s*ko(?:\s+([\s\S]+))?\s*$/;
919
+ var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/;
920
+ var htmlTagsWithOptionallyClosingChildren = { "ul": true, "ol": true };
921
+ function isStartComment(node) {
922
+ return node.nodeType == 8 && startCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue);
923
+ }
924
+ function isEndComment(node) {
925
+ return node.nodeType == 8 && endCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue);
926
+ }
927
+ function isUnmatchedEndComment(node) {
928
+ return isEndComment(node) && !get(node, matchedEndCommentDataKey);
929
+ }
930
+ var matchedEndCommentDataKey = "__ko_matchedEndComment__";
931
+ function getVirtualChildren(startComment, allowUnbalanced) {
932
+ var currentNode = startComment;
933
+ var depth = 1;
934
+ var children = [];
935
+ while (currentNode = currentNode.nextSibling) {
936
+ if (isEndComment(currentNode)) {
937
+ set(currentNode, matchedEndCommentDataKey, true);
938
+ depth--;
939
+ if (depth === 0) {
940
+ return children;
941
+ }
942
+ }
943
+ children.push(currentNode);
944
+ if (isStartComment(currentNode)) {
945
+ depth++;
946
+ }
947
+ }
948
+ if (!allowUnbalanced) {
949
+ throw new Error("Cannot find closing comment tag to match: " + startComment.nodeValue);
950
+ }
951
+ return null;
952
+ }
953
+ function getMatchingEndComment(startComment, allowUnbalanced) {
954
+ var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced);
955
+ if (allVirtualChildren) {
956
+ if (allVirtualChildren.length > 0) {
957
+ return allVirtualChildren[allVirtualChildren.length - 1].nextSibling;
958
+ }
959
+ return startComment.nextSibling;
960
+ } else {
961
+ return null;
962
+ }
963
+ }
964
+ function getUnbalancedChildTags(node) {
965
+ var childNode = node.firstChild, captureRemaining = null;
966
+ if (childNode) {
967
+ do {
968
+ if (captureRemaining) {
969
+ captureRemaining.push(childNode);
970
+ } else if (isStartComment(childNode)) {
971
+ var matchingEndComment = getMatchingEndComment(childNode, true);
972
+ if (matchingEndComment) {
973
+ childNode = matchingEndComment;
974
+ } else {
975
+ captureRemaining = [childNode];
976
+ }
977
+ } else if (isEndComment(childNode)) {
978
+ captureRemaining = [childNode];
979
+ }
980
+ } while (childNode = childNode.nextSibling);
981
+ }
982
+ return captureRemaining;
983
+ }
984
+ var allowedBindings = {};
985
+ var hasBindingValue = isStartComment;
986
+ function childNodes(node) {
987
+ return isStartComment(node) ? getVirtualChildren(node) : node.childNodes;
988
+ }
989
+ function emptyNode(node) {
990
+ if (!isStartComment(node)) {
991
+ emptyDomNode(node);
992
+ } else {
993
+ var virtualChildren = childNodes(node);
994
+ for (var i = 0, j = virtualChildren.length; i < j; i++) {
995
+ removeNode(virtualChildren[i]);
996
+ }
997
+ }
998
+ }
999
+ function setDomNodeChildren2(node, childNodes2) {
1000
+ if (!isStartComment(node)) {
1001
+ setDomNodeChildren(node, childNodes2);
1002
+ } else {
1003
+ emptyNode(node);
1004
+ const endCommentNode = node.nextSibling;
1005
+ const parentNode = endCommentNode.parentNode;
1006
+ for (var i = 0, j = childNodes2.length; i < j; ++i) {
1007
+ parentNode.insertBefore(childNodes2[i], endCommentNode);
1008
+ }
1009
+ }
1010
+ }
1011
+ function prepend(containerNode, nodeToPrepend) {
1012
+ if (!isStartComment(containerNode)) {
1013
+ if (containerNode.firstChild) {
1014
+ containerNode.insertBefore(nodeToPrepend, containerNode.firstChild);
1015
+ } else {
1016
+ containerNode.appendChild(nodeToPrepend);
1017
+ }
1018
+ } else {
1019
+ containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling);
1020
+ }
1021
+ }
1022
+ function insertAfter(containerNode, nodeToInsert, insertAfterNode) {
1023
+ if (!insertAfterNode) {
1024
+ prepend(containerNode, nodeToInsert);
1025
+ } else if (!isStartComment(containerNode)) {
1026
+ if (insertAfterNode.nextSibling) {
1027
+ containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
1028
+ } else {
1029
+ containerNode.appendChild(nodeToInsert);
1030
+ }
1031
+ } else {
1032
+ containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
1033
+ }
1034
+ }
1035
+ function firstChild(node) {
1036
+ if (!isStartComment(node)) {
1037
+ if (node.firstChild && isEndComment(node.firstChild)) {
1038
+ throw new Error("Found invalid end comment, as the first child of " + node.outerHTML);
1039
+ }
1040
+ return node.firstChild;
1041
+ }
1042
+ if (!node.nextSibling || isEndComment(node.nextSibling)) {
1043
+ return null;
1044
+ }
1045
+ return node.nextSibling;
1046
+ }
1047
+ function lastChild(node) {
1048
+ let nextChild = firstChild(node);
1049
+ let lastChildNode;
1050
+ do {
1051
+ lastChildNode = nextChild;
1052
+ } while (nextChild = nextSibling(nextChild));
1053
+ return lastChildNode;
1054
+ }
1055
+ function nextSibling(node) {
1056
+ if (isStartComment(node)) {
1057
+ node = getMatchingEndComment(node);
1058
+ }
1059
+ if (node.nextSibling && isEndComment(node.nextSibling)) {
1060
+ if (isUnmatchedEndComment(node.nextSibling)) {
1061
+ throw Error("Found end comment without a matching opening comment, as next sibling of " + node.outerHTML);
1062
+ }
1063
+ return null;
1064
+ } else {
1065
+ return node.nextSibling;
1066
+ }
1067
+ }
1068
+ function previousSibling(node) {
1069
+ var depth = 0;
1070
+ do {
1071
+ if (node.nodeType === 8) {
1072
+ if (isStartComment(node)) {
1073
+ if (--depth === 0) {
1074
+ return node;
1075
+ }
1076
+ } else if (isEndComment(node)) {
1077
+ depth++;
1078
+ }
1079
+ } else {
1080
+ if (depth === 0) {
1081
+ return node;
1082
+ }
1083
+ }
1084
+ } while (node = node.previousSibling);
1085
+ }
1086
+ function virtualNodeBindingValue(node) {
1087
+ var regexMatch = (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex);
1088
+ return regexMatch ? regexMatch[1] : null;
1089
+ }
1090
+ function normaliseVirtualElementDomStructure(elementVerified) {
1091
+ if (!htmlTagsWithOptionallyClosingChildren[tagNameLower(elementVerified)]) {
1092
+ return;
1093
+ }
1094
+ var childNode = elementVerified.firstChild;
1095
+ if (childNode) {
1096
+ do {
1097
+ if (childNode.nodeType === 1) {
1098
+ var unbalancedTags = getUnbalancedChildTags(childNode);
1099
+ if (unbalancedTags) {
1100
+ var nodeToInsertBefore = childNode.nextSibling;
1101
+ for (var i = 0; i < unbalancedTags.length; i++) {
1102
+ if (nodeToInsertBefore) {
1103
+ elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore);
1104
+ } else {
1105
+ elementVerified.appendChild(unbalancedTags[i]);
1106
+ }
1107
+ }
1108
+ }
1109
+ }
1110
+ } while (childNode = childNode.nextSibling);
1111
+ }
1112
+ }
1113
+
1114
+ // src/dom/html.ts
1115
+ var none = [0, "", ""];
1116
+ var table = [1, "<table>", "</table>"];
1117
+ var tbody = [2, "<table><tbody>", "</tbody></table>"];
1118
+ var colgroup = [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"];
1119
+ var tr = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1120
+ var select = [1, "<select multiple='multiple'>", "</select>"];
1121
+ var fieldset = [1, "<fieldset>", "</fieldset>"];
1122
+ var map = [1, "<map>", "</map>"];
1123
+ var object = [1, "<object>", "</object>"];
1124
+ var lookup = {
1125
+ "area": map,
1126
+ "col": colgroup,
1127
+ "colgroup": table,
1128
+ "caption": table,
1129
+ "legend": fieldset,
1130
+ "thead": table,
1131
+ "tbody": table,
1132
+ "tfoot": table,
1133
+ "tr": tbody,
1134
+ "td": tr,
1135
+ "th": tr,
1136
+ "option": select,
1137
+ "optgroup": select,
1138
+ "param": object
1139
+ };
1140
+ var supportsTemplateTag = options_default.document && "content" in options_default.document.createElement("template");
1141
+ function getWrap(tags) {
1142
+ const m = tags.match(/^(?:<!--.*?-->\s*?)*?<([a-z]+)[\s>]/);
1143
+ return m && lookup[m[1]] || none;
1144
+ }
1145
+ function simpleHtmlParse(html, documentContext) {
1146
+ documentContext || (documentContext = document);
1147
+ var windowContext = documentContext["parentWindow"] || documentContext["defaultView"] || window;
1148
+ var tags = stringTrim(html).toLowerCase(), div = documentContext.createElement("div"), wrap = getWrap(tags), depth = wrap[0];
1149
+ var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
1150
+ if (typeof windowContext["innerShiv"] === "function") {
1151
+ div.appendChild(windowContext["innerShiv"](markup));
1152
+ } else {
1153
+ div.innerHTML = markup;
1154
+ }
1155
+ while (depth--) {
1156
+ div = div.lastChild;
1157
+ }
1158
+ return makeArray(div.lastChild.childNodes);
1159
+ }
1160
+ function templateHtmlParse(html, documentContext) {
1161
+ if (!documentContext) {
1162
+ documentContext = document;
1163
+ }
1164
+ var template = documentContext.createElement("template");
1165
+ template.innerHTML = html;
1166
+ return makeArray(template.content.childNodes);
1167
+ }
1168
+ function jQueryHtmlParse(html, documentContext) {
1169
+ if (jQueryInstance.parseHTML) {
1170
+ return jQueryInstance.parseHTML(html, documentContext) || [];
1171
+ } else {
1172
+ var elems = jQueryInstance.clean([html], documentContext);
1173
+ if (elems && elems[0]) {
1174
+ var elem = elems[0];
1175
+ while (elem.parentNode && elem.parentNode.nodeType !== 11) {
1176
+ elem = elem.parentNode;
1177
+ }
1178
+ if (elem.parentNode) {
1179
+ elem.parentNode.removeChild(elem);
1180
+ }
1181
+ }
1182
+ return elems;
1183
+ }
1184
+ }
1185
+ function parseHtmlFragment(html, documentContext) {
1186
+ return supportsTemplateTag ? templateHtmlParse(html, documentContext) : jQueryInstance ? jQueryHtmlParse(html, documentContext) : simpleHtmlParse(html, documentContext);
1187
+ }
1188
+ function parseHtmlForTemplateNodes(html, documentContext) {
1189
+ const nodes = parseHtmlFragment(html, documentContext);
1190
+ return nodes.length && nodes[0].parentElement || moveCleanedNodesToContainerElement(nodes);
1191
+ }
1192
+ function setHtml(node, html) {
1193
+ emptyDomNode(node);
1194
+ if (typeof html === "function") {
1195
+ html = html();
1196
+ }
1197
+ if (html !== null && html !== void 0) {
1198
+ if (typeof html !== "string") {
1199
+ html = html.toString();
1200
+ }
1201
+ if (jQueryInstance && !supportsTemplateTag) {
1202
+ jQueryInstance(node).html(html);
1203
+ } else {
1204
+ var parsedNodes = parseHtmlFragment(html, node.ownerDocument);
1205
+ if (node.nodeType === 8) {
1206
+ if (html === null) {
1207
+ emptyNode(node);
1208
+ } else {
1209
+ setDomNodeChildren2(node, parsedNodes);
1210
+ }
1211
+ } else {
1212
+ for (var i = 0; i < parsedNodes.length; i++) {
1213
+ node.appendChild(parsedNodes[i]);
1214
+ }
1215
+ }
1216
+ }
1217
+ }
1218
+ }
1219
+ function setTextContent(element, textContent) {
1220
+ var value = typeof textContent === "function" ? textContent() : textContent;
1221
+ if (value === null || value === void 0) {
1222
+ value = "";
1223
+ }
1224
+ var innerTextNode = firstChild(element);
1225
+ if (!innerTextNode || innerTextNode.nodeType != 3 || nextSibling(innerTextNode)) {
1226
+ setDomNodeChildren2(element, [element.ownerDocument.createTextNode(value)]);
1227
+ } else {
1228
+ innerTextNode.data = value;
1229
+ }
1230
+ forceRefresh(element);
1231
+ }
1232
+
1233
+ // src/dom/selectExtensions.ts
1234
+ var hasDomDataExpandoProperty = Symbol("Knockout selectExtensions hasDomDataProperty");
1235
+ var selectExtensions = {
1236
+ optionValueDomDataKey: nextKey(),
1237
+ readValue: function(element) {
1238
+ switch (tagNameLower(element)) {
1239
+ case "option":
1240
+ if (element[hasDomDataExpandoProperty] === true) {
1241
+ return get(element, selectExtensions.optionValueDomDataKey);
1242
+ }
1243
+ return element.value;
1244
+ case "select":
1245
+ return element.selectedIndex >= 0 ? selectExtensions.readValue(element.options[element.selectedIndex]) : void 0;
1246
+ default:
1247
+ return element.value;
1248
+ }
1249
+ },
1250
+ writeValue: function(element, value, allowUnset) {
1251
+ switch (tagNameLower(element)) {
1252
+ case "option":
1253
+ if (typeof value === "string") {
1254
+ set(element, selectExtensions.optionValueDomDataKey, void 0);
1255
+ if (hasDomDataExpandoProperty in element) {
1256
+ delete element[hasDomDataExpandoProperty];
1257
+ }
1258
+ element.value = value;
1259
+ } else {
1260
+ set(element, selectExtensions.optionValueDomDataKey, value);
1261
+ element[hasDomDataExpandoProperty] = true;
1262
+ element.value = typeof value === "number" ? value : "";
1263
+ }
1264
+ break;
1265
+ case "select":
1266
+ if (value === "" || value === null) {
1267
+ value = void 0;
1268
+ }
1269
+ var selection = -1;
1270
+ for (let i = 0, n = element.options.length, optionValue; i < n; ++i) {
1271
+ optionValue = selectExtensions.readValue(element.options[i]);
1272
+ const strictEqual = optionValue === value;
1273
+ const blankEqual = optionValue === "" && value === void 0;
1274
+ const numericEqual = typeof value === "number" && Number(optionValue) === value;
1275
+ if (strictEqual || blankEqual || numericEqual) {
1276
+ selection = i;
1277
+ break;
1278
+ }
1279
+ }
1280
+ if (allowUnset || selection >= 0 || value === void 0 && element.size > 1) {
1281
+ element.selectedIndex = selection;
1282
+ }
1283
+ break;
1284
+ default:
1285
+ if (value === null || value === void 0) {
1286
+ value = "";
1287
+ }
1288
+ element.value = value;
1289
+ break;
1290
+ }
1291
+ }
1292
+ };
1293
+
1294
+ // src/memoization.ts
1295
+ var memoization_exports = {};
1296
+ __export(memoization_exports, {
1297
+ memoize: () => memoize,
1298
+ parseMemoText: () => parseMemoText,
1299
+ unmemoize: () => unmemoize,
1300
+ unmemoizeDomNodeAndDescendants: () => unmemoizeDomNodeAndDescendants
1301
+ });
1302
+ var memos = {};
1303
+ function randomMax8HexChars() {
1304
+ return ((1 + Math.random()) * 4294967296 | 0).toString(16).substring(1);
1305
+ }
1306
+ function generateRandomId() {
1307
+ return randomMax8HexChars() + randomMax8HexChars();
1308
+ }
1309
+ function findMemoNodes(rootNode, appendToArray) {
1310
+ if (!rootNode) {
1311
+ return;
1312
+ }
1313
+ if (rootNode.nodeType == 8) {
1314
+ var memoId = parseMemoText(rootNode.nodeValue);
1315
+ if (memoId != null) {
1316
+ appendToArray.push({ domNode: rootNode, memoId });
1317
+ }
1318
+ } else if (rootNode.nodeType == 1) {
1319
+ for (var i = 0, childNodes2 = rootNode.childNodes, j = childNodes2.length; i < j; i++) {
1320
+ findMemoNodes(childNodes2[i], appendToArray);
1321
+ }
1322
+ }
1323
+ }
1324
+ function memoize(callback) {
1325
+ if (typeof callback !== "function") {
1326
+ throw new Error("You can only pass a function to memoization.memoize()");
1327
+ }
1328
+ var memoId = generateRandomId();
1329
+ memos[memoId] = callback;
1330
+ return "<!--[ko_memo:" + memoId + "]-->";
1331
+ }
1332
+ function unmemoize(memoId, callbackParams) {
1333
+ var callback = memos[memoId];
1334
+ if (callback === void 0) {
1335
+ throw new Error("Couldn't find any memo with ID " + memoId + ". Perhaps it's already been unmemoized.");
1336
+ }
1337
+ try {
1338
+ callback.apply(null, callbackParams || []);
1339
+ return true;
1340
+ } finally {
1341
+ delete memos[memoId];
1342
+ }
1343
+ }
1344
+ function unmemoizeDomNodeAndDescendants(domNode, extraCallbackParamsArray) {
1345
+ var memos2 = [];
1346
+ findMemoNodes(domNode, memos2);
1347
+ for (var i = 0, j = memos2.length; i < j; i++) {
1348
+ var node = memos2[i].domNode;
1349
+ var combinedParams = [node];
1350
+ if (extraCallbackParamsArray) {
1351
+ arrayPushAll(combinedParams, extraCallbackParamsArray);
1352
+ }
1353
+ unmemoize(memos2[i].memoId, combinedParams);
1354
+ node.nodeValue = "";
1355
+ if (node.parentNode) {
1356
+ node.parentNode.removeChild(node);
1357
+ }
1358
+ }
1359
+ }
1360
+ function parseMemoText(memoText) {
1361
+ var match = memoText.match(/^\[ko_memo\:(.*?)\]$/);
1362
+ return match ? match[1] : null;
1363
+ }
1364
+
1365
+ // src/tasks.ts
1366
+ var tasks_exports = {};
1367
+ __export(tasks_exports, {
1368
+ cancel: () => cancel,
1369
+ resetForTesting: () => resetForTesting,
1370
+ runEarly: () => processTasks,
1371
+ schedule: () => schedule
1372
+ });
1373
+ var taskQueue = [];
1374
+ var taskQueueLength = 0;
1375
+ var nextHandle = 1;
1376
+ var nextIndexToProcess = 0;
1377
+ var w = options_default.global;
1378
+ if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {
1379
+ options_default.taskScheduler = function(callback) {
1380
+ var div = w.document.createElement("div");
1381
+ new w.MutationObserver(callback).observe(div, { attributes: true });
1382
+ return function() {
1383
+ div.classList.toggle("foo");
1384
+ };
1385
+ }(scheduledProcess);
1386
+ } else if (w && w.document && "onreadystatechange" in w.document.createElement("script")) {
1387
+ options_default.taskScheduler = function(callback) {
1388
+ var script = document.createElement("script");
1389
+ script.onreadystatechange = function() {
1390
+ script.onreadystatechange = null;
1391
+ document.documentElement.removeChild(script);
1392
+ script = null;
1393
+ callback();
1394
+ };
1395
+ document.documentElement.appendChild(script);
1396
+ };
1397
+ } else {
1398
+ options_default.taskScheduler = function(callback) {
1399
+ setTimeout(callback, 0);
1400
+ };
1401
+ }
1402
+ function processTasks() {
1403
+ if (taskQueueLength) {
1404
+ var mark = taskQueueLength, countMarks = 0;
1405
+ for (var task; nextIndexToProcess < taskQueueLength; ) {
1406
+ if (task = taskQueue[nextIndexToProcess++]) {
1407
+ if (nextIndexToProcess > mark) {
1408
+ if (++countMarks >= 5e3) {
1409
+ nextIndexToProcess = taskQueueLength;
1410
+ deferError(Error("'Too much recursion' after processing " + countMarks + " task groups."));
1411
+ break;
1412
+ }
1413
+ mark = taskQueueLength;
1414
+ }
1415
+ try {
1416
+ task();
1417
+ } catch (ex) {
1418
+ deferError(ex);
1419
+ }
1420
+ }
1421
+ }
1422
+ }
1423
+ }
1424
+ function scheduledProcess() {
1425
+ processTasks();
1426
+ nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
1427
+ }
1428
+ function scheduleTaskProcessing() {
1429
+ options_default.taskScheduler(scheduledProcess);
1430
+ }
1431
+ function schedule(func) {
1432
+ if (!taskQueueLength) {
1433
+ scheduleTaskProcessing();
1434
+ }
1435
+ taskQueue[taskQueueLength++] = func;
1436
+ return nextHandle++;
1437
+ }
1438
+ function cancel(handle) {
1439
+ var index = handle - (nextHandle - taskQueueLength);
1440
+ if (index >= nextIndexToProcess && index < taskQueueLength) {
1441
+ taskQueue[index] = null;
1442
+ }
1443
+ }
1444
+ function resetForTesting() {
1445
+ var length = taskQueueLength - nextIndexToProcess;
1446
+ nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
1447
+ return length;
1448
+ }