@tko/utils 4.0.0-beta1.0 → 4.0.0

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