@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/array.js CHANGED
@@ -1,8 +1,9 @@
1
- // @tko/utils 🥊 4.0.0-beta1.0 ESM
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
2
3
  const { isArray } = Array;
3
- export function arrayForEach(array, action, thisArg) {
4
+ export function arrayForEach(array, action, actionOwner) {
4
5
  if (arguments.length > 2) {
5
- action = action.bind(thisArg);
6
+ action = action.bind(actionOwner);
6
7
  }
7
8
  for (let i = 0, j = array.length; i < j; ++i) {
8
9
  action(array[i], i, array);
@@ -14,30 +15,30 @@ export function arrayIndexOf(array, item) {
14
15
  export function arrayFirst(array, predicate, predicateOwner) {
15
16
  return (isArray(array) ? array : [...array]).find(predicate, predicateOwner);
16
17
  }
17
- export function arrayMap(array = [], mapping, thisArg) {
18
+ export function arrayMap(array, mapping, thisArg) {
18
19
  if (arguments.length > 2) {
19
20
  mapping = mapping.bind(thisArg);
20
21
  }
21
22
  return array === null ? [] : Array.from(array, mapping);
22
23
  }
23
24
  export function arrayRemoveItem(array, itemToRemove) {
24
- var index = arrayIndexOf(array, itemToRemove);
25
+ const index = arrayIndexOf(array, itemToRemove);
25
26
  if (index > 0) {
26
27
  array.splice(index, 1);
27
28
  } else if (index === 0) {
28
29
  array.shift();
29
30
  }
30
31
  }
31
- export function arrayGetDistinctValues(array = []) {
32
+ export function arrayGetDistinctValues(array) {
32
33
  const seen = /* @__PURE__ */ new Set();
33
34
  if (array === null) {
34
35
  return [];
35
36
  }
36
37
  return (isArray(array) ? array : [...array]).filter((item) => seen.has(item) ? false : seen.add(item));
37
38
  }
38
- export function arrayFilter(array, predicate, thisArg) {
39
+ export function arrayFilter(array, predicate, predicateOwner) {
39
40
  if (arguments.length > 2) {
40
- predicate = predicate.bind(thisArg);
41
+ predicate = predicate.bind(predicateOwner);
41
42
  }
42
43
  return array === null ? [] : (isArray(array) ? array : [...array]).filter(predicate);
43
44
  }
@@ -45,14 +46,14 @@ export function arrayPushAll(array, valuesToPush) {
45
46
  if (isArray(valuesToPush)) {
46
47
  array.push.apply(array, valuesToPush);
47
48
  } else {
48
- for (var i = 0, j = valuesToPush.length; i < j; i++) {
49
+ for (let i = 0, j = valuesToPush.length; i < j; i++) {
49
50
  array.push(valuesToPush[i]);
50
51
  }
51
52
  }
52
53
  return array;
53
54
  }
54
55
  export function addOrRemoveItem(array, value, included) {
55
- var existingEntryIndex = arrayIndexOf(typeof array.peek === "function" ? array.peek() : array, value);
56
+ const existingEntryIndex = arrayIndexOf(typeof array.peek === "function" ? array.peek() : array, value);
56
57
  if (existingEntryIndex < 0) {
57
58
  if (included) {
58
59
  array.push(value);
@@ -67,17 +68,17 @@ export function makeArray(arrayLikeObject) {
67
68
  return Array.from(arrayLikeObject);
68
69
  }
69
70
  export function range(min, max) {
70
- min = typeof min === "function" ? min() : min;
71
- max = typeof max === "function" ? max() : max;
72
- var result = [];
73
- for (var i = min; i <= max; i++) {
71
+ const minimum = typeof min === "function" ? min() : min;
72
+ const maximum = typeof max === "function" ? max() : max;
73
+ const result = [];
74
+ for (let i = minimum; i <= maximum; i++) {
74
75
  result.push(i);
75
76
  }
76
77
  return result;
77
78
  }
78
79
  export function findMovesInArrayComparison(left, right, limitFailedCompares) {
79
80
  if (left.length && right.length) {
80
- var failedCompares, l, r, leftItem, rightItem;
81
+ let failedCompares, l, r, leftItem, rightItem;
81
82
  for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) {
82
83
  for (r = 0; rightItem = right[r]; ++r) {
83
84
  if (leftItem.value === rightItem.value) {
@@ -105,10 +106,10 @@ export function compareArrays(oldArray, newArray, options) {
105
106
  }
106
107
  }
107
108
  function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, options) {
108
- 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;
109
+ 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;
109
110
  for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
110
111
  lastRow = thisRow;
111
- editDistanceMatrix.push(thisRow = []);
112
+ editDistanceMatrix.push(thisRow = new Array());
112
113
  bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
113
114
  bigIndexMinForRow = myMax(0, smlIndex - 1);
114
115
  for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
@@ -119,35 +120,38 @@ function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusN
119
120
  } else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1]) {
120
121
  thisRow[bigIndex] = lastRow[bigIndex - 1];
121
122
  } else {
122
- var northDistance = lastRow[bigIndex] || maxDistance;
123
- var westDistance = thisRow[bigIndex - 1] || maxDistance;
123
+ const northDistance = lastRow[bigIndex] || maxDistance;
124
+ const westDistance = thisRow[bigIndex - 1] || maxDistance;
124
125
  thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
125
126
  }
126
127
  }
127
128
  }
128
- var editScript = [], meMinusOne, notInSml = [], notInBig = [];
129
+ let editScript = new Array(), meMinusOne, notInSml = new Array(), notInBig = new Array();
129
130
  for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex; ) {
130
131
  meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
131
132
  if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {
132
- notInSml.push(editScript[editScript.length] = {
133
- "status": statusNotInSml,
134
- "value": bigArray[--bigIndex],
135
- "index": bigIndex
136
- });
133
+ notInSml.push(
134
+ editScript[editScript.length] = {
135
+ // added
136
+ status: statusNotInSml,
137
+ value: bigArray[--bigIndex],
138
+ index: bigIndex
139
+ }
140
+ );
137
141
  } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
138
- notInBig.push(editScript[editScript.length] = {
139
- "status": statusNotInBig,
140
- "value": smlArray[--smlIndex],
141
- "index": smlIndex
142
- });
142
+ notInBig.push(
143
+ editScript[editScript.length] = {
144
+ // deleted
145
+ status: statusNotInBig,
146
+ value: smlArray[--smlIndex],
147
+ index: smlIndex
148
+ }
149
+ );
143
150
  } else {
144
151
  --bigIndex;
145
152
  --smlIndex;
146
- if (!options.sparse) {
147
- editScript.push({
148
- "status": "retained",
149
- "value": bigArray[bigIndex]
150
- });
153
+ if (!options?.sparse) {
154
+ editScript.push({ status: "retained", value: bigArray[bigIndex] });
151
155
  }
152
156
  }
153
157
  }
package/dist/array.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/array.ts"],
4
- "sourcesContent": ["//\n// Array utilities\n//\n// Note that the array functions may be called with\n// Array-like things, such as NodeList.\n\nconst {isArray} = Array\n\nexport function arrayForEach (array, action, thisArg) {\n if (arguments.length > 2) { action = action.bind(thisArg) }\n for (let i = 0, j = array.length; i < j; ++i) {\n action(array[i], i, array)\n }\n}\n\nexport function arrayIndexOf (array, item) {\n return (isArray(array) ? array : [...array]).indexOf(item)\n}\n\nexport function arrayFirst (array, predicate, predicateOwner) {\n return (isArray(array) ? array : [...array])\n .find(predicate, predicateOwner)\n}\n\nexport function arrayMap (array = [], mapping, thisArg) {\n if (arguments.length > 2) { mapping = mapping.bind(thisArg) }\n return array === null ? [] : Array.from(array, mapping)\n}\n\nexport function arrayRemoveItem (array, itemToRemove) {\n var index = arrayIndexOf(array, itemToRemove)\n if (index > 0) {\n array.splice(index, 1)\n } else if (index === 0) {\n array.shift()\n }\n}\n\nexport function arrayGetDistinctValues (array = []) {\n const seen = new Set()\n if (array === null) { return [] }\n return (isArray(array) ? array : [...array])\n .filter(item => seen.has(item) ? false : seen.add(item))\n}\n\nexport function arrayFilter (array, predicate, thisArg) {\n if (arguments.length > 2) { predicate = predicate.bind(thisArg) }\n return array === null ? [] : (isArray(array) ? array : [...array]).filter(predicate)\n}\n\nexport function arrayPushAll (array, valuesToPush) {\n if (isArray(valuesToPush)) {\n array.push.apply(array, valuesToPush)\n } else {\n for (var i = 0, j = valuesToPush.length; i < j; i++) { array.push(valuesToPush[i]) }\n }\n return array\n}\n\nexport function addOrRemoveItem (array, value, included) {\n var existingEntryIndex = arrayIndexOf(typeof array.peek === 'function' ? array.peek() : array, value)\n if (existingEntryIndex < 0) {\n if (included) { array.push(value) }\n } else {\n if (!included) { array.splice(existingEntryIndex, 1) }\n }\n}\n\nexport function makeArray (arrayLikeObject) {\n return Array.from(arrayLikeObject)\n}\n\nexport function range (min, max) {\n min = typeof min === 'function' ? min() : min\n max = typeof max === 'function' ? max() : max\n var result = []\n for (var i = min; i <= max; i++) { result.push(i) }\n return result\n}\n\n// Go through the items that have been added and deleted and try to find matches between them.\nexport function findMovesInArrayComparison (left, right, limitFailedCompares) {\n if (left.length && right.length) {\n var failedCompares, l, r, leftItem, rightItem\n for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) {\n for (r = 0; rightItem = right[r]; ++r) {\n if (leftItem.value === rightItem.value) {\n leftItem.moved = rightItem.index\n rightItem.moved = leftItem.index\n right.splice(r, 1) // This item is marked as moved; so remove it from right list\n failedCompares = r = 0 // Reset failed compares count because we're checking for consecutive failures\n break\n }\n }\n failedCompares += r\n }\n }\n}\n\nconst statusNotInOld = 'added'\nconst statusNotInNew = 'deleted'\n\n // Simple calculation based on Levenshtein distance.\nexport function compareArrays (oldArray, newArray, options) {\n // For backward compatibility, if the third arg is actually a bool, interpret\n // it as the old parameter 'dontLimitMoves'. Newer code should use { dontLimitMoves: true }.\n options = (typeof options === 'boolean') ? { dontLimitMoves: options } : (options || {})\n oldArray = oldArray || []\n newArray = newArray || []\n\n if (oldArray.length < newArray.length) { return compareSmallArrayToBigArray(oldArray, newArray, statusNotInOld, statusNotInNew, options) } else { return compareSmallArrayToBigArray(newArray, oldArray, statusNotInNew, statusNotInOld, options) }\n}\n\nfunction compareSmallArrayToBigArray (smlArray, bigArray, statusNotInSml, statusNotInBig, options) {\n var myMin = Math.min,\n myMax = Math.max,\n editDistanceMatrix = [],\n smlIndex, smlIndexMax = smlArray.length,\n bigIndex, bigIndexMax = bigArray.length,\n compareRange = (bigIndexMax - smlIndexMax) || 1,\n maxDistance = smlIndexMax + bigIndexMax + 1,\n thisRow, lastRow,\n bigIndexMaxForRow, bigIndexMinForRow\n\n for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {\n lastRow = thisRow\n editDistanceMatrix.push(thisRow = [])\n bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange)\n bigIndexMinForRow = myMax(0, smlIndex - 1)\n for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {\n if (!bigIndex) {\n thisRow[bigIndex] = smlIndex + 1\n } else if (!smlIndex) {\n // Top row - transform empty array into new array via additions\n thisRow[bigIndex] = bigIndex + 1\n } else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1]) {\n thisRow[bigIndex] = lastRow[bigIndex - 1]\n } else { // copy value (no edit)\n var northDistance = lastRow[bigIndex] || maxDistance // not in big (deletion)\n var westDistance = thisRow[bigIndex - 1] || maxDistance // not in small (addition)\n thisRow[bigIndex] = myMin(northDistance, westDistance) + 1\n }\n }\n }\n\n var editScript = [], meMinusOne, notInSml = [], notInBig = []\n for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex;) {\n meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1\n if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {\n notInSml.push(editScript[editScript.length] = { // added\n 'status': statusNotInSml,\n 'value': bigArray[--bigIndex],\n 'index': bigIndex })\n } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {\n notInBig.push(editScript[editScript.length] = { // deleted\n 'status': statusNotInBig,\n 'value': smlArray[--smlIndex],\n 'index': smlIndex })\n } else {\n --bigIndex\n --smlIndex\n if (!options.sparse) {\n editScript.push({\n 'status': 'retained',\n 'value': bigArray[bigIndex] })\n }\n }\n }\n\n // Set a limit on the number of consecutive non-matching comparisons; having it a multiple of\n // smlIndexMax keeps the time complexity of this algorithm linear.\n findMovesInArrayComparison(notInBig, notInSml, !options.dontLimitMoves && smlIndexMax * 10)\n\n return editScript.reverse()\n}\n"],
5
- "mappings": ";AAMA,MAAM,EAAC,YAAW;AAEX,6BAAuB,OAAO,QAAQ,SAAS;AACpD,MAAI,UAAU,SAAS,GAAG;AAAE,aAAS,OAAO,KAAK,OAAO;AAAA,EAAE;AAC1D,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,EAAE,GAAG;AAC5C,WAAO,MAAM,IAAI,GAAG,KAAK;AAAA,EAC3B;AACF;AAEO,6BAAuB,OAAO,MAAM;AACzC,SAAQ,SAAQ,KAAK,IAAI,QAAQ,CAAC,GAAG,KAAK,GAAG,QAAQ,IAAI;AAC3D;AAEO,2BAAqB,OAAO,WAAW,gBAAgB;AAC5D,SAAQ,SAAQ,KAAK,IAAI,QAAQ,CAAC,GAAG,KAAK,GACvC,KAAK,WAAW,cAAc;AACnC;AAEO,yBAAmB,QAAQ,CAAC,GAAG,SAAS,SAAS;AACtD,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AW,UAAU;AAAA,QAC5C,UAAU;AAAA,QACV,SAAS,SAAS,EAAE;AAAA,QACpB,SAAS;AAAA,MAAS,CAAC;AAAA,IACvB,OAAO;AACL,QAAE;AACF,QAAE;AACF,UAAI,CAAC,QAAQ,QAAQ;AACnB,mBAAW,KAAK;AAAA,UACd,UAAU;AAAA,UACV,SAAS,SAAS;AAAA,QAAU,CAAC;AAAA,MACjC;AAAA,IACF;AAAA,EACF;AAIA,6BAA2B,UAAU,UAAU,CAAC,QAAQ,kBAAkB,cAAc,EAAE;AAE1F,SAAO,WAAW,QAAQ;AAC5B;",
4
+ "sourcesContent": ["//\n// Array utilities\n//\n// Note that the array functions may be called with\n// Array-like things, such as NodeList.\n\nconst { isArray } = Array\n\nexport function arrayForEach<T = any>(\n array: T[],\n action: (item: T, index?: number, array?: T[]) => void,\n actionOwner?: any\n): void {\n if (arguments.length > 2) {\n action = action.bind(actionOwner)\n }\n for (let i = 0, j = array.length; i < j; ++i) {\n action(array[i], i, array)\n }\n}\n\nexport function arrayIndexOf<T = any>(array: Array<T>, item: T): number {\n return (isArray(array) ? array : [...array]).indexOf(item)\n}\n\nexport function arrayFirst<T = any>(\n array: T[],\n predicate: (item: T, index?: number) => boolean,\n predicateOwner?: any\n): T | undefined {\n return (isArray(array) ? array : [...array]).find(predicate, predicateOwner)\n}\n\nexport function arrayMap<T = any, U = any>(array: ArrayLike<T>, mapping: (item: T, index?: number) => U, thisArg?) {\n if (arguments.length > 2) {\n mapping = mapping.bind(thisArg)\n }\n return array === null ? [] : Array.from(array, mapping)\n}\n\nexport function arrayRemoveItem<T = any>(array: Array<T>, itemToRemove: T): void {\n const index = arrayIndexOf(array, itemToRemove)\n if (index > 0) {\n array.splice(index, 1)\n } else if (index === 0) {\n array.shift()\n }\n}\n\nexport function arrayGetDistinctValues<T = any>(array: T[]): T[] {\n const seen = new Set()\n if (array === null) {\n return []\n }\n return (isArray(array) ? array : [...array]).filter(item => (seen.has(item) ? false : seen.add(item)))\n}\n\nexport function arrayFilter<T = any>(\n array: T[],\n predicate: (item: T, index?: number) => boolean,\n predicateOwner?: any\n): T[] {\n if (arguments.length > 2) {\n predicate = predicate.bind(predicateOwner)\n }\n return array === null ? [] : (isArray(array) ? array : [...array]).filter(predicate)\n}\n\nexport function arrayPushAll<T = any>(array: Array<T>, valuesToPush: ArrayLike<T>): T[] {\n if (isArray(valuesToPush)) {\n array.push.apply(array, valuesToPush)\n } else {\n for (let i = 0, j = valuesToPush.length; i < j; i++) {\n array.push(valuesToPush[i])\n }\n }\n return array\n}\n\nexport function addOrRemoveItem(array, value, included: boolean) {\n const existingEntryIndex = arrayIndexOf(typeof array.peek === 'function' ? array.peek() : array, value)\n if (existingEntryIndex < 0) {\n if (included) {\n array.push(value)\n }\n } else {\n if (!included) {\n array.splice(existingEntryIndex, 1)\n }\n }\n}\n\nexport function makeArray<T = any>(arrayLikeObject: ArrayLike<T>): T[] {\n return Array.from(arrayLikeObject)\n}\n\n//TODO May be MaybeSubscribable<number> -> I actually don't want the dependency\nexport function range(min: () => number | number, max: () => number | number): number[] {\n const minimum = typeof min === 'function' ? (min as () => number)() : (min as number)\n const maximum = typeof max === 'function' ? (max as () => number)() : (max as number)\n const result: number[] = []\n for (let i = minimum as number; i <= maximum; i++) {\n result.push(i)\n }\n return result\n}\n\n// Go through the items that have been added and deleted and try to find matches between them.\nexport function findMovesInArrayComparison(left, right, limitFailedCompares?: number | boolean) {\n if (left.length && right.length) {\n let failedCompares, l, r, leftItem, rightItem\n for (\n failedCompares = l = 0;\n (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]);\n ++l\n ) {\n for (r = 0; (rightItem = right[r]); ++r) {\n if (leftItem.value === rightItem.value) {\n leftItem.moved = rightItem.index\n rightItem.moved = leftItem.index\n right.splice(r, 1) // This item is marked as moved; so remove it from right list\n failedCompares = r = 0 // Reset failed compares count because we're checking for consecutive failures\n break\n }\n }\n failedCompares += r\n }\n }\n}\n\nconst statusNotInOld = 'added'\nconst statusNotInNew = 'deleted'\n\nexport interface ArrayChange<T = any> {\n status: 'added' | 'deleted' | 'retained'\n value: T\n index: number\n moved?: number\n}\n\nexport type ArrayChanges<T = any> = ArrayChange<T>[]\n\nexport interface CompareArraysOptions {\n dontLimitMoves?: boolean\n sparse?: boolean\n}\n\n// Simple calculation based on Levenshtein distance.\nexport function compareArrays<T = any>(\n oldArray: T[],\n newArray: T[],\n options?: CompareArraysOptions | boolean\n): ArrayChanges<T> {\n // For backward compatibility, if the third arg is actually a bool, interpret\n // it as the old parameter 'dontLimitMoves'. Newer code should use { dontLimitMoves: true }.\n options = typeof options === 'boolean' ? { dontLimitMoves: options } : options || {}\n oldArray = oldArray || []\n newArray = newArray || []\n\n if (oldArray.length < newArray.length) {\n return compareSmallArrayToBigArray(oldArray, newArray, statusNotInOld, statusNotInNew, options)\n } else {\n return compareSmallArrayToBigArray(newArray, oldArray, statusNotInNew, statusNotInOld, options)\n }\n}\n\nfunction compareSmallArrayToBigArray<T = any>(\n smlArray: T[],\n bigArray: T[],\n statusNotInSml: 'added' | 'deleted',\n statusNotInBig: 'added' | 'deleted',\n options: CompareArraysOptions\n): ArrayChanges<T> {\n let myMin = Math.min,\n myMax = Math.max,\n editDistanceMatrix = new Array(),\n smlIndex,\n smlIndexMax = smlArray.length,\n bigIndex,\n bigIndexMax = bigArray.length,\n compareRange = bigIndexMax - smlIndexMax || 1,\n maxDistance = smlIndexMax + bigIndexMax + 1,\n thisRow,\n lastRow,\n bigIndexMaxForRow,\n bigIndexMinForRow\n\n for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {\n lastRow = thisRow\n editDistanceMatrix.push((thisRow = new Array()))\n bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange)\n bigIndexMinForRow = myMax(0, smlIndex - 1)\n for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {\n if (!bigIndex) {\n thisRow[bigIndex] = smlIndex + 1\n } else if (!smlIndex) {\n // Top row - transform empty array into new array via additions\n thisRow[bigIndex] = bigIndex + 1\n } else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1]) {\n thisRow[bigIndex] = lastRow[bigIndex - 1]\n } else {\n // copy value (no edit)\n const northDistance = lastRow[bigIndex] || maxDistance // not in big (deletion)\n const westDistance = thisRow[bigIndex - 1] || maxDistance // not in small (addition)\n thisRow[bigIndex] = myMin(northDistance, westDistance) + 1\n }\n }\n }\n\n let editScript = new Array(),\n meMinusOne,\n notInSml = new Array(),\n notInBig = new Array()\n for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex; ) {\n meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1\n if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {\n notInSml.push(\n (editScript[editScript.length] = {\n // added\n status: statusNotInSml,\n value: bigArray[--bigIndex],\n index: bigIndex\n })\n )\n } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {\n notInBig.push(\n (editScript[editScript.length] = {\n // deleted\n status: statusNotInBig,\n value: smlArray[--smlIndex],\n index: smlIndex\n })\n )\n } else {\n --bigIndex\n --smlIndex\n if (!options?.sparse) {\n editScript.push({ status: 'retained', value: bigArray[bigIndex] })\n }\n }\n }\n\n // Set a limit on the number of consecutive non-matching comparisons; having it a multiple of\n // smlIndexMax keeps the time complexity of this algorithm linear.\n findMovesInArrayComparison(notInBig, notInSml, !options.dontLimitMoves && smlIndexMax * 10)\n\n return editScript.reverse()\n}\n"],
5
+ "mappings": ";;AAMA,MAAM,EAAE,QAAQ,IAAI;AAEb,gBAAS,aACd,OACA,QACA,aACM;AACN,MAAI,UAAU,SAAS,GAAG;AACxB,aAAS,OAAO,KAAK,WAAW;AAAA,EAClC;AACA,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,EAAE,GAAG;AAC5C,WAAO,MAAM,CAAC,GAAG,GAAG,KAAK;AAAA,EAC3B;AACF;AAEO,gBA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;AAEA,MAAI,aAAa,IAAI,MAAM,GACzB,YACA,WAAW,IAAI,MAAM,GACrB,WAAW,IAAI,MAAM;AACvB,OAAK,WAAW,aAAa,WAAW,aAAa,YAAY,YAAY;AAC3E,iBAAa,mBAAmB,QAAQ,EAAE,QAAQ,IAAI;AACtD,QAAI,YAAY,eAAe,mBAAmB,QAAQ,EAAE,WAAW,CAAC,GAAG;AACzE,eAAS;AAAA,QACN,WAAW,WAAW,MAAM,IAAI;AAAA;AAAA,UAE/B,QAAQ;AAAA,UACR,OAAO,SAAS,EAAE,QAAQ;AAAA,UAC1B,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF,WAAW,YAAY,eAAe,mBAAmB,WAAW,CAAC,EAAE,QAAQ,GAAG;AAChF,eAAS;AAAA,QACN,WAAW,WAAW,MAAM,IAAI;AAAA;AAAA,UAE/B,QAAQ;AAAA,UACR,OAAO,SAAS,EAAE,QAAQ;AAAA,UAC1B,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF,OAAO;AACL,QAAE;AACF,QAAE;AACF,UAAI,CAAC,SAAS,QAAQ;AACpB,mBAAW,KAAK,EAAE,QAAQ,YAAY,OAAO,SAAS,QAAQ,EAAE,CAAC;AAAA,MACnE;AAAA,IACF;AAAA,EACF;AAIA,6BAA2B,UAAU,UAAU,CAAC,QAAQ,kBAAkB,cAAc,EAAE;AAE1F,SAAO,WAAW,QAAQ;AAC5B;",
6
6
  "names": []
7
7
  }
package/dist/async.js CHANGED
@@ -1,7 +1,8 @@
1
- // @tko/utils 🥊 4.0.0-beta1.0 ESM
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
2
3
  import { safeSetTimeout } from "./error";
3
4
  export function throttle(callback, timeout) {
4
- var timeoutInstance;
5
+ let timeoutInstance;
5
6
  return function(...args) {
6
7
  if (!timeoutInstance) {
7
8
  timeoutInstance = safeSetTimeout(function() {
@@ -12,7 +13,7 @@ export function throttle(callback, timeout) {
12
13
  };
13
14
  }
14
15
  export function debounce(callback, timeout) {
15
- var timeoutInstance;
16
+ let timeoutInstance;
16
17
  return function(...args) {
17
18
  clearTimeout(timeoutInstance);
18
19
  timeoutInstance = safeSetTimeout(() => callback(...args), timeout);
package/dist/async.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/async.ts"],
4
- "sourcesContent": ["//\n// Asynchronous functionality\n// ---\nimport { safeSetTimeout } from './error'\n\nexport function throttle (callback, timeout) {\n var timeoutInstance\n return function (...args) {\n if (!timeoutInstance) {\n timeoutInstance = safeSetTimeout(function () {\n timeoutInstance = undefined\n callback(...args)\n }, timeout)\n }\n }\n}\n\nexport function debounce (callback, timeout) {\n var timeoutInstance\n return function (...args) {\n clearTimeout(timeoutInstance)\n timeoutInstance = safeSetTimeout(() => callback(...args), timeout)\n }\n}\n"],
5
- "mappings": ";AAGA;AAEO,yBAAmB,UAAU,SAAS;AAC3C,MAAI;AACJ,SAAO,YAAa,MAAM;AACxB,QAAI,CAAC,iBAAiB;AACpB,wBAAkB,eAAe,WAAY;AAC3C,0BAAkB;AAClB,iBAAS,GAAG,IAAI;AAAA,MAClB,GAAG,OAAO;AAAA,IACZ;AAAA,EACF;AACF;AAEO,yBAAmB,UAAU,SAAS;AAC3C,MAAI;AACJ,SAAO,YAAa,MAAM;AACxB,iBAAa,eAAe;AAC5B,sBAAkB,eAAe,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO;AAAA,EACnE;AACF;",
4
+ "sourcesContent": ["//\n// Asynchronous functionality\n// ---\nimport { safeSetTimeout } from './error'\n\nexport function throttle(callback, timeout) {\n let timeoutInstance: ReturnType<typeof setTimeout> | undefined\n return function (...args) {\n if (!timeoutInstance) {\n timeoutInstance = safeSetTimeout(function () {\n timeoutInstance = undefined\n callback(...args)\n }, timeout)\n }\n }\n}\n\nexport function debounce(callback, timeout: number) {\n let timeoutInstance: ReturnType<typeof setTimeout>\n return function (...args) {\n clearTimeout(timeoutInstance)\n timeoutInstance = safeSetTimeout(() => callback(...args), timeout)\n }\n}\n"],
5
+ "mappings": ";;AAGA,SAAS,sBAAsB;AAExB,gBAAS,SAAS,UAAU,SAAS;AAC1C,MAAI;AACJ,SAAO,YAAa,MAAM;AACxB,QAAI,CAAC,iBAAiB;AACpB,wBAAkB,eAAe,WAAY;AAC3C,0BAAkB;AAClB,iBAAS,GAAG,IAAI;AAAA,MAClB,GAAG,OAAO;AAAA,IACZ;AAAA,EACF;AACF;AAEO,gBAAS,SAAS,UAAU,SAAiB;AAClD,MAAI;AACJ,SAAO,YAAa,MAAM;AACxB,iBAAa,eAAe;AAC5B,sBAAkB,eAAe,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO;AAAA,EACnE;AACF;",
6
6
  "names": []
7
7
  }
package/dist/css.js CHANGED
@@ -1,8 +1,9 @@
1
- // @tko/utils 🥊 4.0.0-beta1.0 ESM
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
2
3
  import { arrayForEach, addOrRemoveItem } from "./array";
3
- var cssClassNameRegex = /\S+/g;
4
+ const cssClassNameRegex = /\S+/g;
4
5
  function toggleDomNodeCssClass(node, classNames, shouldHaveClass) {
5
- var addOrRemoveFn;
6
+ let addOrRemoveFn;
6
7
  if (!classNames) {
7
8
  return;
8
9
  }
@@ -18,7 +19,7 @@ function toggleDomNodeCssClass(node, classNames, shouldHaveClass) {
18
19
  }
19
20
  }
20
21
  function toggleObjectClassPropertyString(obj, prop, classNames, shouldHaveClass) {
21
- var currentClassNames = obj[prop].match(cssClassNameRegex) || [];
22
+ const currentClassNames = obj[prop].match(cssClassNameRegex) || [];
22
23
  arrayForEach(classNames.match(cssClassNameRegex), function(className) {
23
24
  addOrRemoveItem(currentClassNames, className, shouldHaveClass);
24
25
  });
package/dist/css.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/css.ts"],
4
- "sourcesContent": ["//\n// DOM - CSS\n//\n\nimport { arrayForEach, addOrRemoveItem } from './array'\n\n// For details on the pattern for changing node classes\n// see: https://github.com/knockout/knockout/issues/1597\nvar cssClassNameRegex = /\\S+/g\n\nfunction toggleDomNodeCssClass (node, classNames, shouldHaveClass) {\n var addOrRemoveFn\n if (!classNames) { return }\n if (typeof node.classList === 'object') {\n addOrRemoveFn = node.classList[shouldHaveClass ? 'add' : 'remove']\n arrayForEach(classNames.match(cssClassNameRegex), function (className) {\n addOrRemoveFn.call(node.classList, className)\n })\n } else if (typeof node.className['baseVal'] === 'string') {\n // SVG tag .classNames is an SVGAnimatedString instance\n toggleObjectClassPropertyString(node.className, 'baseVal', classNames, shouldHaveClass)\n } else {\n // node.className ought to be a string.\n toggleObjectClassPropertyString(node, 'className', classNames, shouldHaveClass)\n }\n}\n\nfunction toggleObjectClassPropertyString (obj, prop, classNames, shouldHaveClass) {\n // obj/prop is either a node/'className' or a SVGAnimatedString/'baseVal'.\n var currentClassNames = obj[prop].match(cssClassNameRegex) || []\n arrayForEach(classNames.match(cssClassNameRegex), function (className) {\n addOrRemoveItem(currentClassNames, className, shouldHaveClass)\n })\n obj[prop] = currentClassNames.join(' ')\n}\n\nexport { toggleDomNodeCssClass }\n"],
5
- "mappings": ";AAIA;AAIA,IAAI,oBAAoB;AAExB,+BAAgC,MAAM,YAAY,iBAAiB;AACjE,MAAI;AACJ,MAAI,CAAC,YAAY;AAAE;AAAA,EAAO;AAC1B,MAAI,OAAO,KAAK,cAAc,UAAU;AACtC,oBAAgB,KAAK,UAAU,kBAAkB,QAAQ;AACzD,iBAAa,WAAW,MAAM,iBAAiB,GAAG,SAAU,WAAW;AACrE,oBAAc,KAAK,KAAK,WAAW,SAAS;AAAA,IAC9C,CAAC;AAAA,EACH,WAAW,OAAO,KAAK,UAAU,eAAe,UAAU;AAExD,oCAAgC,KAAK,WAAW,WAAW,YAAY,eAAe;AAAA,EACxF,OAAO;AAEL,oCAAgC,MAAM,aAAa,YAAY,eAAe;AAAA,EAChF;AACF;AAEA,yCAA0C,KAAK,MAAM,YAAY,iBAAiB;AAEhF,MAAI,oBAAoB,IAAI,MAAM,MAAM,iBAAiB,KAAK,CAAC;AAC/D,eAAa,WAAW,MAAM,iBAAiB,GAAG,SAAU,WAAW;AACrE,oBAAgB,mBAAmB,WAAW,eAAe;AAAA,EAC/D,CAAC;AACD,MAAI,QAAQ,kBAAkB,KAAK,GAAG;AACxC;AAEA;",
4
+ "sourcesContent": ["//\n// DOM - CSS\n//\n\nimport { arrayForEach, addOrRemoveItem } from './array'\n\n// For details on the pattern for changing node classes\n// see: https://github.com/knockout/knockout/issues/1597\nconst cssClassNameRegex = /\\S+/g\n\nfunction toggleDomNodeCssClass(node: Element, classNames: string, shouldHaveClass?: boolean): void {\n let addOrRemoveFn\n if (!classNames) {\n return\n }\n if (typeof node.classList === 'object') {\n addOrRemoveFn = node.classList[shouldHaveClass ? 'add' : 'remove']\n arrayForEach(classNames.match(cssClassNameRegex)!, function (className) {\n addOrRemoveFn.call(node.classList, className)\n })\n } else if (typeof node.className['baseVal'] === 'string') {\n // SVG tag .classNames is an SVGAnimatedString instance\n toggleObjectClassPropertyString(node.className, 'baseVal', classNames, shouldHaveClass)\n } else {\n // node.className ought to be a string.\n toggleObjectClassPropertyString(node, 'className', classNames, shouldHaveClass)\n }\n}\n\nfunction toggleObjectClassPropertyString(obj, prop, classNames, shouldHaveClass) {\n // obj/prop is either a node/'className' or a SVGAnimatedString/'baseVal'.\n const currentClassNames = obj[prop].match(cssClassNameRegex) || []\n arrayForEach(classNames.match(cssClassNameRegex), function (className) {\n addOrRemoveItem(currentClassNames, className, shouldHaveClass)\n })\n obj[prop] = currentClassNames.join(' ')\n}\n\nexport { toggleDomNodeCssClass }\n"],
5
+ "mappings": ";;AAIA,SAAS,cAAc,uBAAuB;AAI9C,MAAM,oBAAoB;AAE1B,SAAS,sBAAsB,MAAe,YAAoB,iBAAiC;AACjG,MAAI;AACJ,MAAI,CAAC,YAAY;AACf;AAAA,EACF;AACA,MAAI,OAAO,KAAK,cAAc,UAAU;AACtC,oBAAgB,KAAK,UAAU,kBAAkB,QAAQ,QAAQ;AACjE,iBAAa,WAAW,MAAM,iBAAiB,GAAI,SAAU,WAAW;AACtE,oBAAc,KAAK,KAAK,WAAW,SAAS;AAAA,IAC9C,CAAC;AAAA,EACH,WAAW,OAAO,KAAK,UAAU,SAAS,MAAM,UAAU;AAExD,oCAAgC,KAAK,WAAW,WAAW,YAAY,eAAe;AAAA,EACxF,OAAO;AAEL,oCAAgC,MAAM,aAAa,YAAY,eAAe;AAAA,EAChF;AACF;AAEA,SAAS,gCAAgC,KAAK,MAAM,YAAY,iBAAiB;AAE/E,QAAM,oBAAoB,IAAI,IAAI,EAAE,MAAM,iBAAiB,KAAK,CAAC;AACjE,eAAa,WAAW,MAAM,iBAAiB,GAAG,SAAU,WAAW;AACrE,oBAAgB,mBAAmB,WAAW,eAAe;AAAA,EAC/D,CAAC;AACD,MAAI,IAAI,IAAI,kBAAkB,KAAK,GAAG;AACxC;AAEA,SAAS;",
6
6
  "names": []
7
7
  }
package/dist/dom/data.js CHANGED
@@ -1,63 +1,53 @@
1
- // @tko/utils 🥊 4.0.0-beta1.0 ESM
2
- import { ieVersion } from "../ie";
3
- const datastoreTime = new Date().getTime();
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
3
+ const datastoreTime = (/* @__PURE__ */ new Date()).getTime();
4
4
  const dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`;
5
- const dataStoreSymbol = Symbol("Knockout data");
6
- var dataStore;
5
+ const dataStoreSymbol = /* @__PURE__ */ Symbol("Knockout data");
6
+ const dataStore = {};
7
7
  let uniqueId = 0;
8
- const modern = {
9
- getDataForNode(node, createIfNotFound) {
10
- let dataForNode = node[dataStoreSymbol];
11
- if (!dataForNode && createIfNotFound) {
12
- dataForNode = node[dataStoreSymbol] = {};
13
- }
14
- return dataForNode;
15
- },
16
- clear(node) {
17
- if (node[dataStoreSymbol]) {
18
- delete node[dataStoreSymbol];
19
- return true;
20
- }
21
- return false;
8
+ function isSafeKey(key) {
9
+ return key !== "__proto__" && key !== "constructor" && key !== "prototype";
10
+ }
11
+ function getDataForNode(node, createIfNotFound) {
12
+ let dataForNode = node[dataStoreSymbol];
13
+ if (!dataForNode && createIfNotFound) {
14
+ dataForNode = node[dataStoreSymbol] = {};
22
15
  }
23
- };
24
- const IE = {
25
- getDataforNode(node, createIfNotFound) {
26
- let dataStoreKey = node[dataStoreKeyExpandoPropertyName];
27
- const hasExistingDataStore = dataStoreKey && dataStoreKey !== "null" && dataStore[dataStoreKey];
28
- if (!hasExistingDataStore) {
29
- if (!createIfNotFound) {
30
- return void 0;
31
- }
32
- dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++;
33
- dataStore[dataStoreKey] = {};
34
- }
35
- return dataStore[dataStoreKey];
36
- },
37
- clear(node) {
38
- const dataStoreKey = node[dataStoreKeyExpandoPropertyName];
39
- if (dataStoreKey) {
40
- delete dataStore[dataStoreKey];
41
- node[dataStoreKeyExpandoPropertyName] = null;
42
- return true;
43
- }
44
- return false;
16
+ return dataForNode;
17
+ }
18
+ function clear(node) {
19
+ if (node[dataStoreSymbol]) {
20
+ delete node[dataStoreSymbol];
21
+ return true;
45
22
  }
46
- };
47
- const { getDataForNode, clear } = ieVersion ? IE : modern;
23
+ return false;
24
+ }
48
25
  export function nextKey() {
49
26
  return uniqueId++ + dataStoreKeyExpandoPropertyName;
50
27
  }
51
28
  function get(node, key) {
29
+ if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key);
52
30
  const dataForNode = getDataForNode(node, false);
53
31
  return dataForNode && dataForNode[key];
54
32
  }
55
33
  function set(node, key, value) {
56
- var dataForNode = getDataForNode(node, value !== void 0);
57
- dataForNode && (dataForNode[key] = value);
34
+ if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key);
35
+ const dataForNode = getDataForNode(
36
+ node,
37
+ value !== void 0
38
+ /* createIfNotFound */
39
+ );
40
+ if (dataForNode) {
41
+ dataForNode[key] = value;
42
+ }
58
43
  }
59
44
  function getOrSet(node, key, value) {
60
- const dataForNode = getDataForNode(node, true);
45
+ if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key);
46
+ const dataForNode = getDataForNode(
47
+ node,
48
+ true
49
+ /* createIfNotFound */
50
+ );
61
51
  return dataForNode[key] || (dataForNode[key] = value);
62
52
  }
63
53
  export { get, set, getOrSet, clear };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/data.ts"],
4
- "sourcesContent": ["//\n// DOM node data\n//\nimport { ieVersion } from '../ie'\n\nconst datastoreTime = new Date().getTime()\nconst dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`\nconst dataStoreSymbol = Symbol('Knockout data')\nvar dataStore\nlet uniqueId = 0\n\n/*\n * We considered using WeakMap, but it has a problem in IE 11 and Edge that\n * prevents using it cross-window, so instead we just store the data directly\n * on the node. See https://github.com/knockout/knockout/issues/2141\n */\nconst modern = {\n getDataForNode (node, createIfNotFound) {\n let dataForNode = node[dataStoreSymbol]\n if (!dataForNode && createIfNotFound) {\n dataForNode = node[dataStoreSymbol] = {}\n }\n return dataForNode\n },\n\n clear (node) {\n if (node[dataStoreSymbol]) {\n delete node[dataStoreSymbol]\n return true\n }\n return false\n }\n}\n\n/**\n * Old IE versions have memory issues if you store objects on the node, so we\n * use a separate data storage and link to it from the node using a string key.\n */\nconst IE = {\n getDataforNode (node, createIfNotFound) {\n let dataStoreKey = node[dataStoreKeyExpandoPropertyName]\n const hasExistingDataStore = dataStoreKey && (dataStoreKey !== 'null') && dataStore[dataStoreKey]\n if (!hasExistingDataStore) {\n if (!createIfNotFound) {\n return undefined\n }\n dataStoreKey = node[dataStoreKeyExpandoPropertyName] = 'ko' + uniqueId++\n dataStore[dataStoreKey] = {}\n }\n return dataStore[dataStoreKey]\n },\n\n clear (node) {\n const dataStoreKey = node[dataStoreKeyExpandoPropertyName]\n if (dataStoreKey) {\n delete dataStore[dataStoreKey]\n node[dataStoreKeyExpandoPropertyName] = null\n return true // Exposing 'did clean' flag purely so specs can infer whether things have been cleaned up as intended\n }\n return false\n }\n}\n\nconst {getDataForNode, clear} = ieVersion ? IE : modern\n\n/**\n * Create a unique key-string identifier.\n */\nexport function nextKey () {\n return (uniqueId++) + dataStoreKeyExpandoPropertyName\n}\n\nfunction get (node, key) {\n const dataForNode = getDataForNode(node, false)\n return dataForNode && dataForNode[key]\n}\n\nfunction set (node, key, value) {\n // Make sure we don't actually create a new domData key if we are actually deleting a value\n var dataForNode = getDataForNode(node, value !== undefined /* createIfNotFound */)\n dataForNode && (dataForNode[key] = value)\n}\n\nfunction getOrSet (node, key, value) {\n const dataForNode = getDataForNode(node, true, /* createIfNotFound */)\n return dataForNode[key] || (dataForNode[key] = value)\n}\n\nexport { get, set, getOrSet, clear }\n"],
5
- "mappings": ";AAGA;AAEA,MAAM,gBAAgB,IAAI,KAAK,EAAE,QAAQ;AACzC,MAAM,kCAAkC,SAAS;AACjD,MAAM,kBAAkB,OAAO,eAAe;AAC9C,IAAI;AACJ,IAAI,WAAW;AAOf,MAAM,SAAS;AAAA,EACb,eAAgB,MAAM,kBAAkB;AACtC,QAAI,cAAc,KAAK;AACvB,QAAI,CAAC,eAAe,kBAAkB;AACpC,oBAAc,KAAK,mBAAmB,CAAC;AAAA,IACzC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAO,MAAM;AACX,QAAI,KAAK,kBAAkB;AACzB,aAAO,KAAK;AACZ,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AACF;AAMA,MAAM,KAAK;AAAA,EACT,eAAgB,MAAM,kBAAkB;AACtC,QAAI,eAAe,KAAK;AACxB,UAAM,uBAAuB,gBAAiB,iBAAiB,UAAW,UAAU;AACpF,QAAI,CAAC,sBAAsB;AACzB,UAAI,CAAC,kBAAkB;AACrB,eAAO;AAAA,MACT;AACA,qBAAe,KAAK,mCAAmC,OAAO;AAC9D,gBAAU,gBAAgB,CAAC;AAAA,IAC7B;AACA,WAAO,UAAU;AAAA,EACnB;AAAA,EAEA,MAAO,MAAM;AACX,UAAM,eAAe,KAAK;AAC1B,QAAI,cAAc;AAChB,aAAO,UAAU;AACjB,WAAK,mCAAmC;AACxC,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AACF;AAEA,MAAM,EAAC,gBAAgB,UAAS,YAAY,KAAK;AAK1C,0BAAoB;AACzB,SAAQ,aAAc;AACxB;AAEA,aAAc,MAAM,KAAK;AACvB,QAAM,cAAc,eAAe,MAAM,KAAK;AAC9C,SAAO,eAAe,YAAY;AACpC;AAEA,aAAc,MAAM,KAAK,OAAO;AAE9B,MAAI,cAAc,eAAe,MAAM,UAAU,MAAgC;AACjF,iBAAgB,aAAY,OAAO;AACrC;AAEA,kBAAmB,MAAM,KAAK,OAAO;AACnC,QAAM,cAAc,eAAe,MAAM,IAA4B;AACrE,SAAO,YAAY,QAAS,aAAY,OAAO;AACjD;AAEA;",
4
+ "sourcesContent": ["//\n// DOM node data\n//\n\nconst datastoreTime = new Date().getTime()\nconst dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`\nconst dataStoreSymbol = Symbol('Knockout data')\nconst dataStore = {}\nlet uniqueId = 0\n\n// Prevent prototype pollution by restricting special property names\nfunction isSafeKey(key: string): boolean {\n return key !== '__proto__' && key !== 'constructor' && key !== 'prototype'\n}\n\n/*\n * We considered using WeakMap, but it has a problem in IE 11 and Edge that\n * prevents using it cross-window, so instead we just store the data directly\n * on the node. See https://github.com/knockout/knockout/issues/2141\n */\nfunction getDataForNode(node: Node, createIfNotFound: boolean): any {\n let dataForNode = node[dataStoreSymbol]\n if (!dataForNode && createIfNotFound) {\n dataForNode = node[dataStoreSymbol] = {}\n }\n return dataForNode\n}\n\nfunction clear(node: Node): boolean {\n if (node[dataStoreSymbol]) {\n delete node[dataStoreSymbol]\n return true\n }\n return false\n}\n\n/**\n * Create a unique key-string identifier.\n */\nexport function nextKey() {\n return uniqueId++ + dataStoreKeyExpandoPropertyName\n}\n\nfunction get(node: Node, key: string) {\n if (!isSafeKey(key)) throw new Error('Unsafe key for DOM data: ' + key)\n\n const dataForNode = getDataForNode(node, false)\n return dataForNode && dataForNode[key]\n}\n\nfunction set(node: Node, key: string, value: any) {\n if (!isSafeKey(key)) throw new Error('Unsafe key for DOM data: ' + key)\n // Make sure we don't actually create a new domData key if we are actually deleting a value\n const dataForNode = getDataForNode(node, value !== undefined /* createIfNotFound */)\n if (dataForNode) {\n dataForNode[key] = value\n }\n}\n\nfunction getOrSet(node: Node, key: string, value: any) {\n if (!isSafeKey(key)) throw new Error('Unsafe key for DOM data: ' + key)\n const dataForNode = getDataForNode(node, true /* createIfNotFound */)\n return dataForNode[key] || (dataForNode[key] = value)\n}\n\nexport { get, set, getOrSet, clear }\n"],
5
+ "mappings": ";;AAIA,MAAM,iBAAgB,oBAAI,KAAK,GAAE,QAAQ;AACzC,MAAM,kCAAkC,SAAS,aAAa;AAC9D,MAAM,kBAAkB,uBAAO,eAAe;AAC9C,MAAM,YAAY,CAAC;AACnB,IAAI,WAAW;AAGf,SAAS,UAAU,KAAsB;AACvC,SAAO,QAAQ,eAAe,QAAQ,iBAAiB,QAAQ;AACjE;AAOA,SAAS,eAAe,MAAY,kBAAgC;AAClE,MAAI,cAAc,KAAK,eAAe;AACtC,MAAI,CAAC,eAAe,kBAAkB;AACpC,kBAAc,KAAK,eAAe,IAAI,CAAC;AAAA,EACzC;AACA,SAAO;AACT;AAEA,SAAS,MAAM,MAAqB;AAClC,MAAI,KAAK,eAAe,GAAG;AACzB,WAAO,KAAK,eAAe;AAC3B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAKO,gBAAS,UAAU;AACxB,SAAO,aAAa;AACtB;AAEA,SAAS,IAAI,MAAY,KAAa;AACpC,MAAI,CAAC,UAAU,GAAG,EAAG,OAAM,IAAI,MAAM,8BAA8B,GAAG;AAEtE,QAAM,cAAc,eAAe,MAAM,KAAK;AAC9C,SAAO,eAAe,YAAY,GAAG;AACvC;AAEA,SAAS,IAAI,MAAY,KAAa,OAAY;AAChD,MAAI,CAAC,UAAU,GAAG,EAAG,OAAM,IAAI,MAAM,8BAA8B,GAAG;AAEtE,QAAM,cAAc;AAAA,IAAe;AAAA,IAAM,UAAU;AAAA;AAAA,EAAgC;AACnF,MAAI,aAAa;AACf,gBAAY,GAAG,IAAI;AAAA,EACrB;AACF;AAEA,SAAS,SAAS,MAAY,KAAa,OAAY;AACrD,MAAI,CAAC,UAAU,GAAG,EAAG,OAAM,IAAI,MAAM,8BAA8B,GAAG;AACtE,QAAM,cAAc;AAAA,IAAe;AAAA,IAAM;AAAA;AAAA,EAA2B;AACpE,SAAO,YAAY,GAAG,MAAM,YAAY,GAAG,IAAI;AACjD;AAEA,SAAS,KAAK,KAAK,UAAU;",
6
6
  "names": []
7
7
  }
@@ -1,15 +1,15 @@
1
- // @tko/utils 🥊 4.0.0-beta1.0 ESM
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
2
3
  import * as domData from "./data";
3
4
  import { default as options } from "../options";
4
5
  import { arrayRemoveItem, arrayIndexOf } from "../array";
5
- import { jQueryInstance } from "../jquery";
6
- var domDataKey = domData.nextKey();
7
- var cleanableNodeTypes = { 1: true, 8: true, 9: true };
8
- var cleanableNodeTypesWithDescendants = { 1: true, 9: true };
6
+ const domDataKey = domData.nextKey();
7
+ const cleanableNodeTypes = { 1: true, 8: true, 9: true };
8
+ const cleanableNodeTypesWithDescendants = { 1: true, 9: true };
9
9
  function getDisposeCallbacksCollection(node, createIfNotFound) {
10
- var allDisposeCallbacks = domData.get(node, domDataKey);
10
+ let allDisposeCallbacks = domData.get(node, domDataKey);
11
11
  if (allDisposeCallbacks === void 0 && createIfNotFound) {
12
- allDisposeCallbacks = [];
12
+ allDisposeCallbacks = new Array();
13
13
  domData.set(node, domDataKey, allDisposeCallbacks);
14
14
  }
15
15
  return allDisposeCallbacks;
@@ -18,7 +18,7 @@ function destroyCallbacksCollection(node) {
18
18
  domData.set(node, domDataKey, void 0);
19
19
  }
20
20
  function cleanSingleNode(node) {
21
- var callbacks = getDisposeCallbacksCollection(node, false);
21
+ let callbacks = getDisposeCallbacksCollection(node, false);
22
22
  if (callbacks) {
23
23
  callbacks = callbacks.slice(0);
24
24
  for (let i = 0; i < callbacks.length; i++) {
@@ -33,14 +33,18 @@ function cleanSingleNode(node) {
33
33
  options.cleanExternalData(node);
34
34
  }
35
35
  if (cleanableNodeTypesWithDescendants[node.nodeType]) {
36
- cleanNodesInList(node.childNodes, true);
36
+ cleanNodesInList(
37
+ node.childNodes,
38
+ true
39
+ /* onlyComments */
40
+ );
37
41
  }
38
42
  }
39
43
  function cleanNodesInList(nodeList, onlyComments) {
40
- const cleanedNodes = [];
44
+ const cleanedNodes = new Array();
41
45
  let lastCleanedNode;
42
- for (var i = 0; i < nodeList.length; i++) {
43
- if (!onlyComments || nodeList[i].nodeType === 8) {
46
+ for (let i = 0; i < nodeList.length; i++) {
47
+ if (!onlyComments || nodeList[i].nodeType === Node.COMMENT_NODE) {
44
48
  cleanSingleNode(cleanedNodes[cleanedNodes.length] = lastCleanedNode = nodeList[i]);
45
49
  if (nodeList[i] !== lastCleanedNode) {
46
50
  while (i-- && arrayIndexOf(cleanedNodes, nodeList[i]) === -1) {
@@ -56,7 +60,7 @@ export function addDisposeCallback(node, callback) {
56
60
  getDisposeCallbacksCollection(node, true).push(callback);
57
61
  }
58
62
  export function removeDisposeCallback(node, callback) {
59
- var callbacksCollection = getDisposeCallbacksCollection(node, false);
63
+ const callbacksCollection = getDisposeCallbacksCollection(node, false);
60
64
  if (callbacksCollection) {
61
65
  arrayRemoveItem(callbacksCollection, callback);
62
66
  if (callbacksCollection.length === 0) {
@@ -67,19 +71,22 @@ export function removeDisposeCallback(node, callback) {
67
71
  export function cleanNode(node) {
68
72
  if (cleanableNodeTypes[node.nodeType]) {
69
73
  cleanSingleNode(node);
70
- if (cleanableNodeTypesWithDescendants[node.nodeType]) {
74
+ if (cleanableNodeTypesWithDescendants[node.nodeType] && node instanceof Element) {
71
75
  cleanNodesInList(node.getElementsByTagName("*"));
72
76
  }
73
77
  }
74
78
  return node;
75
79
  }
76
80
  export function removeNode(node) {
81
+ if (!node) {
82
+ return;
83
+ }
77
84
  cleanNode(node);
78
85
  if (node.parentNode) {
79
86
  node.parentNode.removeChild(node);
80
87
  }
81
88
  }
82
- export const otherNodeCleanerFunctions = [];
89
+ export const otherNodeCleanerFunctions = new Array();
83
90
  export function addCleaner(fn) {
84
91
  otherNodeCleanerFunctions.push(fn);
85
92
  }
@@ -90,7 +97,7 @@ export function removeCleaner(fn) {
90
97
  }
91
98
  }
92
99
  export function cleanjQueryData(node) {
93
- var jQueryCleanNodeFn = jQueryInstance ? jQueryInstance.cleanData : null;
100
+ const jQueryCleanNodeFn = options.jQuery ? options.jQuery.cleanData : null;
94
101
  if (jQueryCleanNodeFn) {
95
102
  jQueryCleanNodeFn([node]);
96
103
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/disposal.ts"],
4
- "sourcesContent": ["//\n// DOM node disposal\n//\n/* eslint no-cond-assign: 0 */\nimport * as domData from './data'\nimport { default as options } from '../options'\nimport {arrayRemoveItem, arrayIndexOf} from '../array'\nimport {jQueryInstance} from '../jquery'\n\nvar domDataKey = domData.nextKey()\n// Node types:\n// 1: Element\n// 8: Comment\n// 9: Document\nvar cleanableNodeTypes = { 1: true, 8: true, 9: true }\nvar cleanableNodeTypesWithDescendants = { 1: true, 9: true }\n\nfunction getDisposeCallbacksCollection (node, createIfNotFound) {\n var allDisposeCallbacks = domData.get(node, domDataKey)\n if ((allDisposeCallbacks === undefined) && createIfNotFound) {\n allDisposeCallbacks = []\n domData.set(node, domDataKey, allDisposeCallbacks)\n }\n return allDisposeCallbacks\n}\nfunction destroyCallbacksCollection (node) {\n domData.set(node, domDataKey, undefined)\n}\n\nfunction cleanSingleNode (node) {\n // Run all the dispose callbacks\n var callbacks = getDisposeCallbacksCollection(node, false)\n if (callbacks) {\n callbacks = callbacks.slice(0) // Clone, as the array may be modified during iteration (typically, callbacks will remove themselves)\n for (let i = 0; i < callbacks.length; i++) { callbacks[i](node) }\n }\n\n // Erase the DOM data\n domData.clear(node)\n\n // Perform cleanup needed by external libraries (currently only jQuery, but can be extended)\n for (let i = 0, j = otherNodeCleanerFunctions.length; i < j; ++i) {\n otherNodeCleanerFunctions[i](node)\n }\n\n if (options.cleanExternalData) {\n options.cleanExternalData(node)\n }\n\n // Clear any immediate-child comment nodes, as these wouldn't have been found by\n // node.getElementsByTagName('*') in cleanNode() (comment nodes aren't elements)\n if (cleanableNodeTypesWithDescendants[node.nodeType]) {\n cleanNodesInList(node.childNodes, true /* onlyComments */)\n }\n}\n\nfunction cleanNodesInList (nodeList, onlyComments) {\n const cleanedNodes = []\n let lastCleanedNode\n for (var i = 0; i < nodeList.length; i++) {\n if (!onlyComments || nodeList[i].nodeType === 8) {\n cleanSingleNode(cleanedNodes[cleanedNodes.length] = lastCleanedNode = nodeList[i]);\n if (nodeList[i] !== lastCleanedNode) {\n while (i-- && arrayIndexOf(cleanedNodes, nodeList[i]) === -1) {}\n }\n }\n }\n}\n\n// Exports\nexport function addDisposeCallback (node, callback) {\n if (typeof callback !== 'function') { throw new Error('Callback must be a function') }\n getDisposeCallbacksCollection(node, true).push(callback)\n}\n\nexport function removeDisposeCallback (node, callback) {\n var callbacksCollection = getDisposeCallbacksCollection(node, false)\n if (callbacksCollection) {\n arrayRemoveItem(callbacksCollection, callback)\n if (callbacksCollection.length === 0) { destroyCallbacksCollection(node) }\n }\n}\n\nexport function cleanNode (node) {\n // First clean this node, where applicable\n if (cleanableNodeTypes[node.nodeType]) {\n cleanSingleNode(node)\n\n // ... then its descendants, where applicable\n if (cleanableNodeTypesWithDescendants[node.nodeType]) {\n cleanNodesInList(node.getElementsByTagName(\"*\"))\n }\n }\n return node\n}\n\nexport function removeNode (node) {\n cleanNode(node)\n if (node.parentNode) { node.parentNode.removeChild(node) }\n}\n\n// Expose supplemental node cleaning functions.\nexport const otherNodeCleanerFunctions = []\n\nexport function addCleaner (fn) {\n otherNodeCleanerFunctions.push(fn)\n}\n\nexport function removeCleaner (fn) {\n const fnIndex = otherNodeCleanerFunctions.indexOf(fn)\n if (fnIndex >= 0) { otherNodeCleanerFunctions.splice(fnIndex, 1) }\n}\n\n// Special support for jQuery here because it's so commonly used.\n// Many jQuery plugins (including jquery.tmpl) store data using jQuery's equivalent of domData\n// so notify it to tear down any resources associated with the node & descendants here.\nexport function cleanjQueryData (node) {\n var jQueryCleanNodeFn = jQueryInstance ? jQueryInstance.cleanData : null\n\n if (jQueryCleanNodeFn) {\n jQueryCleanNodeFn([node])\n }\n}\n\notherNodeCleanerFunctions.push(cleanjQueryData)\n"],
5
- "mappings": ";AAIA;AACA;AACA;AACA;AAEA,IAAI,aAAa,QAAQ,QAAQ;AAKjC,IAAI,qBAAqB,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK;AACrD,IAAI,oCAAoC,EAAE,GAAG,MAAM,GAAG,KAAK;AAE3D,uCAAwC,MAAM,kBAAkB;AAC9D,MAAI,sBAAsB,QAAQ,IAAI,MAAM,UAAU;AACtD,MAAK,wBAAwB,UAAc,kBAAkB;AAC3D,0BAAsB,CAAC;AACvB,YAAQ,IAAI,MAAM,YAAY,mBAAmB;AAAA,EACnD;AACA,SAAO;AACT;AACA,oCAAqC,MAAM;AACzC,UAAQ,IAAI,MAAM,YAAY,MAAS;AACzC;AAEA,yBAA0B,MAAM;AAE9B,MAAI,YAAY,8BAA8B,MAAM,KAAK;AACzD,MAAI,WAAW;AACb,gBAAY,UAAU,MAAM,CAAC;AAC7B,aAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AAAE,gBAAU,GAAG,IAAI;AAAA,IAAE;AAAA,EAClE;AAGA,UAAQ,MAAM,IAAI;AAGlB,WAAS,IAAI,GAAG,IAAI,0BAA0B,QAAQ,IAAI,GAAG,EAAE,GAAG;A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BAAqB,IAAI;AAC9B,4BAA0B,KAAK,EAAE;AACnC;AAEO,8BAAwB,IAAI;AACjC,QAAM,UAAU,0BAA0B,QAAQ,EAAE;AACpD,MAAI,WAAW,GAAG;AAAE,8BAA0B,OAAO,SAAS,CAAC;AAAA,EAAE;AACnE;AAKO,gCAA0B,MAAM;AACrC,MAAI,oBAAoB,iBAAiB,eAAe,YAAY;AAEpE,MAAI,mBAAmB;AACrB,sBAAkB,CAAC,IAAI,CAAC;AAAA,EAC1B;AACF;AAEA,0BAA0B,KAAK,eAAe;",
4
+ "sourcesContent": ["//\n// DOM node disposal\n//\n/* eslint no-cond-assign: 0 */\nimport * as domData from './data'\nimport { default as options } from '../options'\nimport { arrayRemoveItem, arrayIndexOf } from '../array'\n\nconst domDataKey = domData.nextKey()\n// Node types:\n// 1: Element\n// 8: Comment\n// 9: Document\nconst cleanableNodeTypes = { 1: true, 8: true, 9: true }\nconst cleanableNodeTypesWithDescendants = { 1: true, 9: true }\n\nfunction getDisposeCallbacksCollection(node: Node, createIfNotFound: boolean) {\n let allDisposeCallbacks = domData.get(node, domDataKey)\n if (allDisposeCallbacks === undefined && createIfNotFound) {\n allDisposeCallbacks = new Array()\n domData.set(node, domDataKey, allDisposeCallbacks)\n }\n return allDisposeCallbacks\n}\nfunction destroyCallbacksCollection(node: Node) {\n domData.set(node, domDataKey, undefined)\n}\n\nfunction cleanSingleNode(node: Node) {\n // Run all the dispose callbacks\n let callbacks = getDisposeCallbacksCollection(node, false)\n if (callbacks) {\n callbacks = callbacks.slice(0) // Clone, as the array may be modified during iteration (typically, callbacks will remove themselves)\n for (let i = 0; i < callbacks.length; i++) {\n callbacks[i](node)\n }\n }\n\n // Erase the DOM data\n domData.clear(node)\n\n // Perform cleanup needed by external libraries (currently only jQuery, but can be extended)\n for (let i = 0, j = otherNodeCleanerFunctions.length; i < j; ++i) {\n otherNodeCleanerFunctions[i](node)\n }\n\n if (options.cleanExternalData) {\n options.cleanExternalData(node)\n }\n\n // Clear any immediate-child comment nodes, as these wouldn't have been found by\n // node.getElementsByTagName('*') in cleanNode() (comment nodes aren't elements)\n if (cleanableNodeTypesWithDescendants[node.nodeType]) {\n cleanNodesInList(node.childNodes, true /* onlyComments */)\n }\n}\n\nfunction cleanNodesInList(nodeList: NodeList | HTMLCollectionBase, onlyComments?: boolean) {\n const cleanedNodes = new Array<Node>()\n let lastCleanedNode\n for (let i = 0; i < nodeList.length; i++) {\n if (!onlyComments || nodeList[i].nodeType === Node.COMMENT_NODE) {\n cleanSingleNode((cleanedNodes[cleanedNodes.length] = lastCleanedNode = nodeList[i]))\n if (nodeList[i] !== lastCleanedNode) {\n while (i-- && arrayIndexOf(cleanedNodes, nodeList[i]) === -1) {}\n }\n }\n }\n}\n\n// Exports\nexport function addDisposeCallback(node: Node, callback: (node: Node) => void) {\n if (typeof callback !== 'function') {\n throw new Error('Callback must be a function')\n }\n getDisposeCallbacksCollection(node, true).push(callback)\n}\n\nexport function removeDisposeCallback(node: Node, callback: (node: Node) => void) {\n const callbacksCollection = getDisposeCallbacksCollection(node, false)\n if (callbacksCollection) {\n arrayRemoveItem(callbacksCollection, callback)\n if (callbacksCollection.length === 0) {\n destroyCallbacksCollection(node)\n }\n }\n}\n\nexport function cleanNode(node: Node): typeof node {\n // First clean this node, where applicable\n if (cleanableNodeTypes[node.nodeType]) {\n cleanSingleNode(node)\n\n // ... then its descendants, where applicable\n if (cleanableNodeTypesWithDescendants[node.nodeType] && node instanceof Element) {\n cleanNodesInList(node.getElementsByTagName('*'))\n }\n }\n return node\n}\n\nexport function removeNode(node: Node | null) {\n if (!node) {\n return\n }\n\n cleanNode(node)\n if (node.parentNode) {\n node.parentNode.removeChild(node)\n }\n}\n\n// Expose supplemental node cleaning functions.\nexport const otherNodeCleanerFunctions = new Array<Function>()\n\nexport function addCleaner(fn: Function) {\n otherNodeCleanerFunctions.push(fn)\n}\n\nexport function removeCleaner(fn: Function) {\n const fnIndex = otherNodeCleanerFunctions.indexOf(fn)\n if (fnIndex >= 0) {\n otherNodeCleanerFunctions.splice(fnIndex, 1)\n }\n}\n\n// Special support for jQuery here because it's so commonly used.\n// Many jQuery plugins (including jquery.tmpl) store data using jQuery's equivalent of domData\n// so notify it to tear down any resources associated with the node & descendants here.\nexport function cleanjQueryData(node: Node) {\n const jQueryCleanNodeFn = options.jQuery ? options.jQuery.cleanData : null\n\n if (jQueryCleanNodeFn) {\n jQueryCleanNodeFn([node])\n }\n}\n\notherNodeCleanerFunctions.push(cleanjQueryData)\n"],
5
+ "mappings": ";;AAIA,YAAY,aAAa;AACzB,SAAS,WAAW,eAAe;AACnC,SAAS,iBAAiB,oBAAoB;AAE9C,MAAM,aAAa,QAAQ,QAAQ;AAKnC,MAAM,qBAAqB,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK;AACvD,MAAM,oCAAoC,EAAE,GAAG,MAAM,GAAG,KAAK;AAE7D,SAAS,8BAA8B,MAAY,kBAA2B;AAC5E,MAAI,sBAAsB,QAAQ,IAAI,MAAM,UAAU;AACtD,MAAI,wBAAwB,UAAa,kBAAkB;AACzD,0BAAsB,IAAI,MAAM;AAChC,YAAQ,IAAI,MAAM,YAAY,mBAAmB;AAAA,EACnD;AACA,SAAO;AACT;AACA,SAAS,2BAA2B,MAAY;AAC9C,UAAQ,IAAI,MAAM,YAAY,MAAS;AACzC;AAEA,SAAS,gBAAgB,MAAY;AAEnC,MAAI,YAAY,8BAA8B,MAAM,KAAK;AACzD,MAAI,WAAW;AACb,gBAAY,UAAU,MAAM,CAAC;AAC7B,aAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,gBAAU,CAAC,EAAE,IAAI;AAAA,IACnB;AAAA,EACF;AAGA,UAAQ,MAAM,IAAI;AAGlB,WAAS,IAAI,GAAG,IAAI,0BAA0B,QAAQ,IAAI,GAAG,EAAE,GAAG;AAChE,8BAA0B,CAAC,EAAE,IAAI;AAAA,EACnC;AAEA,MAAI,QAAQ,mBAAmB;AAC7B,YAAQ,kB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