@tko/utils
Advanced tools
+39
-35
@@ -1,6 +0,7 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| const { isArray } = Array; | ||
| export function arrayForEach(array, action, thisArg) { | ||
| export function arrayForEach(array, action, actionOwner) { | ||
| if (arguments.length > 2) { | ||
| action = action.bind(thisArg); | ||
| action = action.bind(actionOwner); | ||
| } | ||
@@ -17,3 +18,3 @@ for (let i = 0, j = array.length; i < j; ++i) { | ||
| } | ||
| export function arrayMap(array = [], mapping, thisArg) { | ||
| export function arrayMap(array, mapping, thisArg) { | ||
| if (arguments.length > 2) { | ||
@@ -25,3 +26,3 @@ mapping = mapping.bind(thisArg); | ||
| export function arrayRemoveItem(array, itemToRemove) { | ||
| var index = arrayIndexOf(array, itemToRemove); | ||
| const index = arrayIndexOf(array, itemToRemove); | ||
| if (index > 0) { | ||
@@ -33,3 +34,3 @@ array.splice(index, 1); | ||
| } | ||
| export function arrayGetDistinctValues(array = []) { | ||
| export function arrayGetDistinctValues(array) { | ||
| const seen = /* @__PURE__ */ new Set(); | ||
@@ -41,5 +42,5 @@ if (array === null) { | ||
| } | ||
| export function arrayFilter(array, predicate, thisArg) { | ||
| export function arrayFilter(array, predicate, predicateOwner) { | ||
| if (arguments.length > 2) { | ||
| predicate = predicate.bind(thisArg); | ||
| predicate = predicate.bind(predicateOwner); | ||
| } | ||
@@ -52,3 +53,3 @@ return array === null ? [] : (isArray(array) ? array : [...array]).filter(predicate); | ||
| } else { | ||
| for (var i = 0, j = valuesToPush.length; i < j; i++) { | ||
| for (let i = 0, j = valuesToPush.length; i < j; i++) { | ||
| array.push(valuesToPush[i]); | ||
@@ -60,3 +61,3 @@ } | ||
| export function addOrRemoveItem(array, value, included) { | ||
| var existingEntryIndex = arrayIndexOf(typeof array.peek === "function" ? array.peek() : array, value); | ||
| const existingEntryIndex = arrayIndexOf(typeof array.peek === "function" ? array.peek() : array, value); | ||
| if (existingEntryIndex < 0) { | ||
@@ -76,6 +77,6 @@ if (included) { | ||
| export function range(min, max) { | ||
| min = typeof min === "function" ? min() : min; | ||
| max = typeof max === "function" ? max() : max; | ||
| var result = []; | ||
| for (var i = min; i <= max; i++) { | ||
| const minimum = typeof min === "function" ? min() : min; | ||
| const maximum = typeof max === "function" ? max() : max; | ||
| const result = []; | ||
| for (let i = minimum; i <= maximum; i++) { | ||
| result.push(i); | ||
@@ -87,3 +88,3 @@ } | ||
| if (left.length && right.length) { | ||
| var failedCompares, l, r, leftItem, rightItem; | ||
| let failedCompares, l, r, leftItem, rightItem; | ||
| for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) { | ||
@@ -116,6 +117,6 @@ for (r = 0; rightItem = right[r]; ++r) { | ||
| function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, options) { | ||
| 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; | ||
| 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; | ||
| for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) { | ||
| lastRow = thisRow; | ||
| editDistanceMatrix.push(thisRow = []); | ||
| editDistanceMatrix.push(thisRow = new Array()); | ||
| bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange); | ||
@@ -131,4 +132,4 @@ bigIndexMinForRow = myMax(0, smlIndex - 1); | ||
| } else { | ||
| var northDistance = lastRow[bigIndex] || maxDistance; | ||
| var westDistance = thisRow[bigIndex - 1] || maxDistance; | ||
| const northDistance = lastRow[bigIndex] || maxDistance; | ||
| const westDistance = thisRow[bigIndex - 1] || maxDistance; | ||
| thisRow[bigIndex] = myMin(northDistance, westDistance) + 1; | ||
@@ -138,25 +139,28 @@ } | ||
| } | ||
| var editScript = [], meMinusOne, notInSml = [], notInBig = []; | ||
| let editScript = new Array(), meMinusOne, notInSml = new Array(), notInBig = new Array(); | ||
| for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex; ) { | ||
| meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1; | ||
| if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) { | ||
| notInSml.push(editScript[editScript.length] = { | ||
| "status": statusNotInSml, | ||
| "value": bigArray[--bigIndex], | ||
| "index": bigIndex | ||
| }); | ||
| notInSml.push( | ||
| editScript[editScript.length] = { | ||
| // added | ||
| status: statusNotInSml, | ||
| value: bigArray[--bigIndex], | ||
| index: bigIndex | ||
| } | ||
| ); | ||
| } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) { | ||
| notInBig.push(editScript[editScript.length] = { | ||
| "status": statusNotInBig, | ||
| "value": smlArray[--smlIndex], | ||
| "index": smlIndex | ||
| }); | ||
| notInBig.push( | ||
| editScript[editScript.length] = { | ||
| // deleted | ||
| status: statusNotInBig, | ||
| value: smlArray[--smlIndex], | ||
| index: smlIndex | ||
| } | ||
| ); | ||
| } else { | ||
| --bigIndex; | ||
| --smlIndex; | ||
| if (!options.sparse) { | ||
| editScript.push({ | ||
| "status": "retained", | ||
| "value": bigArray[bigIndex] | ||
| }); | ||
| if (!options?.sparse) { | ||
| editScript.push({ status: "retained", value: bigArray[bigIndex] }); | ||
| } | ||
@@ -163,0 +167,0 @@ } |
| { | ||
| "version": 3, | ||
| "sources": ["../src/array.ts"], | ||
| "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"], | ||
| "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,6BAAu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mBAAmB,UAAU,YAAY;AACtD,QAAI,YAAY,eAAe,mBAAmB,UAAU,WAAW,IAAI;AACzE,eAAS,KAAK,WAAW,WAAW,UAAU;AAAA,QAC5C,UAAU;AAAA,QACV,SAAS,SAAS,EAAE;AAAA,QACpB,SAAS;AAAA,MAAS,CAAC;AAAA,IACvB,WAAW,YAAY,eAAe,mBAAmB,WAAW,GAAG,WAAW;AAChF,eAAS,KAAK,WAAW,WAAW,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;", | ||
| "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"], | ||
| "mappings": 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beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { safeSetTimeout } from "./error"; | ||
| export function throttle(callback, timeout) { | ||
| var timeoutInstance; | ||
| let timeoutInstance; | ||
| return function(...args) { | ||
@@ -15,3 +16,3 @@ if (!timeoutInstance) { | ||
| export function debounce(callback, timeout) { | ||
| var timeoutInstance; | ||
| let timeoutInstance; | ||
| return function(...args) { | ||
@@ -18,0 +19,0 @@ clearTimeout(timeoutInstance); |
| { | ||
| "version": 3, | ||
| "sources": ["../src/async.ts"], | ||
| "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"], | ||
| "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;", | ||
| "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"], | ||
| "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;", | ||
| "names": [] | ||
| } |
+5
-4
@@ -1,6 +0,7 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { arrayForEach, addOrRemoveItem } from "./array"; | ||
| var cssClassNameRegex = /\S+/g; | ||
| const cssClassNameRegex = /\S+/g; | ||
| function toggleDomNodeCssClass(node, classNames, shouldHaveClass) { | ||
| var addOrRemoveFn; | ||
| let addOrRemoveFn; | ||
| if (!classNames) { | ||
@@ -21,3 +22,3 @@ return; | ||
| function toggleObjectClassPropertyString(obj, prop, classNames, shouldHaveClass) { | ||
| var currentClassNames = obj[prop].match(cssClassNameRegex) || []; | ||
| const currentClassNames = obj[prop].match(cssClassNameRegex) || []; | ||
| arrayForEach(classNames.match(cssClassNameRegex), function(className) { | ||
@@ -24,0 +25,0 @@ addOrRemoveItem(currentClassNames, className, shouldHaveClass); |
+2
-2
| { | ||
| "version": 3, | ||
| "sources": ["../src/css.ts"], | ||
| "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"], | ||
| "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;", | ||
| "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"], | ||
| "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;", | ||
| "names": [] | ||
| } |
+36
-46
@@ -1,48 +0,25 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| import { ieVersion } from "../ie"; | ||
| const datastoreTime = new Date().getTime(); | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| const datastoreTime = (/* @__PURE__ */ new Date()).getTime(); | ||
| const dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`; | ||
| const dataStoreSymbol = Symbol("Knockout data"); | ||
| var dataStore; | ||
| const dataStoreSymbol = /* @__PURE__ */ Symbol("Knockout data"); | ||
| const dataStore = {}; | ||
| let uniqueId = 0; | ||
| const modern = { | ||
| getDataForNode(node, createIfNotFound) { | ||
| let dataForNode = node[dataStoreSymbol]; | ||
| if (!dataForNode && createIfNotFound) { | ||
| dataForNode = node[dataStoreSymbol] = {}; | ||
| } | ||
| return dataForNode; | ||
| }, | ||
| clear(node) { | ||
| if (node[dataStoreSymbol]) { | ||
| delete node[dataStoreSymbol]; | ||
| return true; | ||
| } | ||
| return false; | ||
| function isSafeKey(key) { | ||
| return key !== "__proto__" && key !== "constructor" && key !== "prototype"; | ||
| } | ||
| function getDataForNode(node, createIfNotFound) { | ||
| let dataForNode = node[dataStoreSymbol]; | ||
| if (!dataForNode && createIfNotFound) { | ||
| dataForNode = node[dataStoreSymbol] = {}; | ||
| } | ||
| }; | ||
| const IE = { | ||
| getDataforNode(node, createIfNotFound) { | ||
| let dataStoreKey = node[dataStoreKeyExpandoPropertyName]; | ||
| const hasExistingDataStore = dataStoreKey && dataStoreKey !== "null" && dataStore[dataStoreKey]; | ||
| if (!hasExistingDataStore) { | ||
| if (!createIfNotFound) { | ||
| return void 0; | ||
| } | ||
| dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++; | ||
| dataStore[dataStoreKey] = {}; | ||
| } | ||
| return dataStore[dataStoreKey]; | ||
| }, | ||
| clear(node) { | ||
| const dataStoreKey = node[dataStoreKeyExpandoPropertyName]; | ||
| if (dataStoreKey) { | ||
| delete dataStore[dataStoreKey]; | ||
| node[dataStoreKeyExpandoPropertyName] = null; | ||
| return true; | ||
| } | ||
| return false; | ||
| return dataForNode; | ||
| } | ||
| function clear(node) { | ||
| if (node[dataStoreSymbol]) { | ||
| delete node[dataStoreSymbol]; | ||
| return true; | ||
| } | ||
| }; | ||
| const { getDataForNode, clear } = ieVersion ? IE : modern; | ||
| return false; | ||
| } | ||
| export function nextKey() { | ||
@@ -52,2 +29,3 @@ return uniqueId++ + dataStoreKeyExpandoPropertyName; | ||
| function get(node, key) { | ||
| if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key); | ||
| const dataForNode = getDataForNode(node, false); | ||
@@ -57,9 +35,21 @@ return dataForNode && dataForNode[key]; | ||
| function set(node, key, value) { | ||
| var dataForNode = getDataForNode(node, value !== void 0); | ||
| dataForNode && (dataForNode[key] = value); | ||
| if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key); | ||
| const dataForNode = getDataForNode( | ||
| node, | ||
| value !== void 0 | ||
| /* createIfNotFound */ | ||
| ); | ||
| if (dataForNode) { | ||
| dataForNode[key] = value; | ||
| } | ||
| } | ||
| function getOrSet(node, key, value) { | ||
| const dataForNode = getDataForNode(node, true); | ||
| if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key); | ||
| const dataForNode = getDataForNode( | ||
| node, | ||
| true | ||
| /* createIfNotFound */ | ||
| ); | ||
| return dataForNode[key] || (dataForNode[key] = value); | ||
| } | ||
| export { get, set, getOrSet, clear }; |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/data.ts"], | ||
| "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"], | ||
| "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;", | ||
| "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"], | ||
| "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;", | ||
| "names": [] | ||
| } |
+23
-16
@@ -1,13 +0,13 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import * as domData from "./data"; | ||
| import { default as options } from "../options"; | ||
| import { arrayRemoveItem, arrayIndexOf } from "../array"; | ||
| import { jQueryInstance } from "../jquery"; | ||
| var domDataKey = domData.nextKey(); | ||
| var cleanableNodeTypes = { 1: true, 8: true, 9: true }; | ||
| var cleanableNodeTypesWithDescendants = { 1: true, 9: true }; | ||
| const domDataKey = domData.nextKey(); | ||
| const cleanableNodeTypes = { 1: true, 8: true, 9: true }; | ||
| const cleanableNodeTypesWithDescendants = { 1: true, 9: true }; | ||
| function getDisposeCallbacksCollection(node, createIfNotFound) { | ||
| var allDisposeCallbacks = domData.get(node, domDataKey); | ||
| let allDisposeCallbacks = domData.get(node, domDataKey); | ||
| if (allDisposeCallbacks === void 0 && createIfNotFound) { | ||
| allDisposeCallbacks = []; | ||
| allDisposeCallbacks = new Array(); | ||
| domData.set(node, domDataKey, allDisposeCallbacks); | ||
@@ -21,3 +21,3 @@ } | ||
| function cleanSingleNode(node) { | ||
| var callbacks = getDisposeCallbacksCollection(node, false); | ||
| let callbacks = getDisposeCallbacksCollection(node, false); | ||
| if (callbacks) { | ||
@@ -37,10 +37,14 @@ callbacks = callbacks.slice(0); | ||
| if (cleanableNodeTypesWithDescendants[node.nodeType]) { | ||
| cleanNodesInList(node.childNodes, true); | ||
| cleanNodesInList( | ||
| node.childNodes, | ||
| true | ||
| /* onlyComments */ | ||
| ); | ||
| } | ||
| } | ||
| function cleanNodesInList(nodeList, onlyComments) { | ||
| const cleanedNodes = []; | ||
| const cleanedNodes = new Array(); | ||
| let lastCleanedNode; | ||
| for (var i = 0; i < nodeList.length; i++) { | ||
| if (!onlyComments || nodeList[i].nodeType === 8) { | ||
| for (let i = 0; i < nodeList.length; i++) { | ||
| if (!onlyComments || nodeList[i].nodeType === Node.COMMENT_NODE) { | ||
| cleanSingleNode(cleanedNodes[cleanedNodes.length] = lastCleanedNode = nodeList[i]); | ||
@@ -61,3 +65,3 @@ if (nodeList[i] !== lastCleanedNode) { | ||
| export function removeDisposeCallback(node, callback) { | ||
| var callbacksCollection = getDisposeCallbacksCollection(node, false); | ||
| const callbacksCollection = getDisposeCallbacksCollection(node, false); | ||
| if (callbacksCollection) { | ||
@@ -73,3 +77,3 @@ arrayRemoveItem(callbacksCollection, callback); | ||
| cleanSingleNode(node); | ||
| if (cleanableNodeTypesWithDescendants[node.nodeType]) { | ||
| if (cleanableNodeTypesWithDescendants[node.nodeType] && node instanceof Element) { | ||
| cleanNodesInList(node.getElementsByTagName("*")); | ||
@@ -81,2 +85,5 @@ } | ||
| export function removeNode(node) { | ||
| if (!node) { | ||
| return; | ||
| } | ||
| cleanNode(node); | ||
@@ -87,3 +94,3 @@ if (node.parentNode) { | ||
| } | ||
| export const otherNodeCleanerFunctions = []; | ||
| export const otherNodeCleanerFunctions = new Array(); | ||
| export function addCleaner(fn) { | ||
@@ -99,3 +106,3 @@ otherNodeCleanerFunctions.push(fn); | ||
| export function cleanjQueryData(node) { | ||
| var jQueryCleanNodeFn = jQueryInstance ? jQueryInstance.cleanData : null; | ||
| const jQueryCleanNodeFn = options.jQuery ? options.jQuery.cleanData : null; | ||
| if (jQueryCleanNodeFn) { | ||
@@ -102,0 +109,0 @@ jQueryCleanNodeFn([node]); |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/disposal.ts"], | ||
| "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 =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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"], | ||
| "mappings": ";;AAIA,YAAY,aAAa;AACzB,SAAS,WAAW,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OAAO,YAAY;AAEtE,MAAI,mBAAmB;AACrB,sBAAkB,CAAC,IAAI,CAAC;AAAA,EAC1B;AACF;AAEA,0BAA0B,KAAK,eAAe;", | ||
| "names": [] | ||
| } |
+39
-41
@@ -1,12 +0,9 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { objectForEach } from "../object"; | ||
| import { jQueryInstance } from "../jquery"; | ||
| import { ieVersion } from "../ie"; | ||
| import { catchFunctionErrors } from "../error"; | ||
| import { tagNameLower } from "./info"; | ||
| import { addDisposeCallback } from "./disposal"; | ||
| import options from "../options"; | ||
| var knownEvents = {}, knownEventTypesByEventName = {}; | ||
| var keyEventTypeName = options.global.navigator && /Firefox\/2/i.test(options.global.navigator.userAgent) ? "KeyboardEvent" : "UIEvents"; | ||
| knownEvents[keyEventTypeName] = ["keyup", "keydown", "keypress"]; | ||
| const knownEvents = {}, knownEventTypesByEventName = {}; | ||
| knownEvents["UIEvents"] = ["keyup", "keydown", "keypress"]; | ||
| knownEvents["MouseEvents"] = [ | ||
@@ -25,3 +22,3 @@ "click", | ||
| if (knownEventsForType.length) { | ||
| for (var i = 0, j = knownEventsForType.length; i < j; i++) { | ||
| for (let i = 0, j = knownEventsForType.length; i < j; i++) { | ||
| knownEventTypesByEventName[knownEventsForType[i]] = eventType; | ||
@@ -32,35 +29,22 @@ } | ||
| function isClickOnCheckableElement(element, eventType) { | ||
| if (tagNameLower(element) !== "input" || !element.type) | ||
| return false; | ||
| if (eventType.toLowerCase() != "click") | ||
| return false; | ||
| var inputType = element.type; | ||
| if (tagNameLower(element) !== "input" || !element.type) return false; | ||
| if (eventType.toLowerCase() != "click") return false; | ||
| const inputType = element.type; | ||
| return inputType == "checkbox" || inputType == "radio"; | ||
| } | ||
| var eventsThatMustBeRegisteredUsingAttachEvent = { "propertychange": true }; | ||
| let jQueryEventAttachName; | ||
| export function registerEventHandler(element, eventType, handler, eventOptions = false) { | ||
| const wrappedHandler = catchFunctionErrors(handler); | ||
| const mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType]; | ||
| const mustUseNative = Boolean(eventOptions); | ||
| if (!options.useOnlyNativeEvents && !mustUseAttachEvent && !mustUseNative && jQueryInstance) { | ||
| if (!jQueryEventAttachName) { | ||
| jQueryEventAttachName = typeof jQueryInstance(element).on === "function" ? "on" : "bind"; | ||
| } | ||
| jQueryInstance(element)[jQueryEventAttachName](eventType, wrappedHandler); | ||
| } else if (!mustUseAttachEvent && typeof element.addEventListener === "function") { | ||
| const jQuery = options.jQuery; | ||
| if (!options.useOnlyNativeEvents && !mustUseNative && jQuery) { | ||
| jQuery(element).on(eventType, wrappedHandler); | ||
| } else if (typeof element.addEventListener === "function") { | ||
| element.addEventListener(eventType, wrappedHandler, eventOptions); | ||
| } else if (typeof element.attachEvent !== "undefined") { | ||
| const attachEventHandler = function(event) { | ||
| wrappedHandler.call(element, event); | ||
| }; | ||
| const attachEventName = "on" + eventType; | ||
| element.attachEvent(attachEventName, attachEventHandler); | ||
| addDisposeCallback(element, function() { | ||
| element.detachEvent(attachEventName, attachEventHandler); | ||
| }); | ||
| } else { | ||
| throw new Error("Browser doesn't support addEventListener or attachEvent"); | ||
| throw new Error("Browser doesn't support addEventListener"); | ||
| } | ||
| } | ||
| function hasClick(element) { | ||
| return typeof element.click === "function"; | ||
| } | ||
| export function triggerEvent(element, eventType) { | ||
@@ -70,10 +54,26 @@ if (!(element && element.nodeType)) { | ||
| } | ||
| var useClickWorkaround = isClickOnCheckableElement(element, eventType); | ||
| if (!options.useOnlyNativeEvents && jQueryInstance && !useClickWorkaround) { | ||
| jQueryInstance(element).trigger(eventType); | ||
| const useClickWorkaround = isClickOnCheckableElement(element, eventType); | ||
| if (!options.useOnlyNativeEvents && options.jQuery && !useClickWorkaround) { | ||
| options.jQuery(element).trigger(eventType); | ||
| } else if (typeof document.createEvent === "function") { | ||
| if (typeof element.dispatchEvent === "function") { | ||
| var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents"; | ||
| var event = document.createEvent(eventCategory); | ||
| event.initEvent(eventType, true, true, options.global, 0, 0, 0, 0, 0, false, false, false, false, 0, element); | ||
| const eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents"; | ||
| const event = document.createEvent(eventCategory); | ||
| event.initEvent( | ||
| eventType, | ||
| true, | ||
| true, | ||
| options.global, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| false, | ||
| false, | ||
| false, | ||
| false, | ||
| 0, | ||
| element | ||
| ); | ||
| element.dispatchEvent(event); | ||
@@ -83,6 +83,4 @@ } else { | ||
| } | ||
| } else if (useClickWorkaround && element.click) { | ||
| } else if (useClickWorkaround && hasClick(element)) { | ||
| element.click(); | ||
| } else if (typeof element.fireEvent !== "undefined") { | ||
| element.fireEvent("on" + eventType); | ||
| } else { | ||
@@ -89,0 +87,0 @@ throw new Error("Browser doesn't support triggering events"); |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/event.ts"], | ||
| "sourcesContent": ["//\n// DOM Events\n//\n\nimport { objectForEach } from '../object'\nimport { jQueryInstance } from '../jquery'\nimport { ieVersion } from '../ie'\nimport { catchFunctionErrors } from '../error'\n\nimport { tagNameLower } from './info'\nimport { addDisposeCallback } from './disposal'\nimport options from '../options'\n\n// Represent the known event types in a compact way, then at runtime transform it into a hash with event name as key (for fast lookup)\nvar knownEvents = {},\n knownEventTypesByEventName = {}\n\nvar keyEventTypeName = (options.global.navigator && /Firefox\\/2/i.test(options.global.navigator.userAgent)) ? 'KeyboardEvent' : 'UIEvents'\n\nknownEvents[keyEventTypeName] = ['keyup', 'keydown', 'keypress']\n\nknownEvents['MouseEvents'] = [\n 'click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover',\n 'mouseout', 'mouseenter', 'mouseleave']\n\nobjectForEach(knownEvents, function (eventType, knownEventsForType) {\n if (knownEventsForType.length) {\n for (var i = 0, j = knownEventsForType.length; i < j; i++) { knownEventTypesByEventName[knownEventsForType[i]] = eventType }\n }\n})\n\nfunction isClickOnCheckableElement (element, eventType) {\n if ((tagNameLower(element) !== 'input') || !element.type) return false\n if (eventType.toLowerCase() != 'click') return false\n var inputType = element.type\n return (inputType == 'checkbox') || (inputType == 'radio')\n}\n\n// Workaround for an IE9 issue - https://github.com/SteveSanderson/knockout/issues/406\nvar eventsThatMustBeRegisteredUsingAttachEvent = { 'propertychange': true }\nlet jQueryEventAttachName\n\nexport function registerEventHandler (element, eventType, handler, eventOptions = false) {\n const wrappedHandler = catchFunctionErrors(handler)\n const mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType]\n const mustUseNative = Boolean(eventOptions)\n\n if (!options.useOnlyNativeEvents && !mustUseAttachEvent && !mustUseNative && jQueryInstance) {\n if (!jQueryEventAttachName) {\n jQueryEventAttachName = (typeof jQueryInstance(element).on === 'function') ? 'on' : 'bind'\n }\n jQueryInstance(element)[jQueryEventAttachName](eventType, wrappedHandler)\n } else if (!mustUseAttachEvent && typeof element.addEventListener === 'function') {\n element.addEventListener(eventType, wrappedHandler, eventOptions)\n } else if (typeof element.attachEvent !== 'undefined') {\n const attachEventHandler = function (event) { wrappedHandler.call(element, event) }\n const attachEventName = 'on' + eventType\n element.attachEvent(attachEventName, attachEventHandler)\n\n // IE does not dispose attachEvent handlers automatically (unlike with addEventListener)\n // so to avoid leaks, we have to remove them manually. See bug #856\n addDisposeCallback(element, function () {\n element.detachEvent(attachEventName, attachEventHandler)\n })\n } else {\n throw new Error(\"Browser doesn't support addEventListener or attachEvent\")\n }\n}\n\nexport function triggerEvent (element, eventType) {\n if (!(element && element.nodeType)) { throw new Error('element must be a DOM node when calling triggerEvent') }\n\n // For click events on checkboxes and radio buttons, jQuery toggles the element checked state *after* the\n // event handler runs instead of *before*. (This was fixed in 1.9 for checkboxes but not for radio buttons.)\n // IE doesn't change the checked state when you trigger the click event using \"fireEvent\".\n // In both cases, we'll use the click method instead.\n var useClickWorkaround = isClickOnCheckableElement(element, eventType)\n\n if (!options.useOnlyNativeEvents && jQueryInstance && !useClickWorkaround) {\n jQueryInstance(element).trigger(eventType)\n } else if (typeof document.createEvent === 'function') {\n if (typeof element.dispatchEvent === 'function') {\n var eventCategory = knownEventTypesByEventName[eventType] || 'HTMLEvents'\n var event = document.createEvent(eventCategory)\n event.initEvent(eventType, true, true, options.global, 0, 0, 0, 0, 0, false, false, false, false, 0, element)\n element.dispatchEvent(event)\n } else { throw new Error(\"The supplied element doesn't support dispatchEvent\") }\n } else if (useClickWorkaround && element.click) {\n element.click()\n } else if (typeof element.fireEvent !== 'undefined') {\n element.fireEvent('on' + eventType)\n } else {\n throw new Error(\"Browser doesn't support triggering events\")\n }\n}\n"], | ||
| "mappings": ";AAIA;AACA;AACA;AACA;AAEA;AACA;AACA;AAGA,IAAI,cAAc,CAAC,GACjB,6BAA6B,CAAC;AAEhC,IAAI,mBAAoB,QAAQ,OAAO,aAAa,cAAc,KAAK,QAAQ,OAAO,UAAU,SAAS,IAAK,kBAAkB;AAEhI,YAAY,oBAAoB,CAAC,SAAS,WAAW,UAAU;AAE/D,YAAY,iBAAiB;AAAA,EAC3B;AAAA,EAAS;AAAA,EAAY;AAAA,EAAa;AAAA,EAAW;AAAA,EAAa;AAAA,EAC1D;AAAA,EAAY;AAAA,EAAc;AAAY;AAExC,cAAc,aAAa,SAAU,WAAW,oBAAoB;AAClE,MAAI,mBAAmB,QAAQ;AAC7B,aAAS,IAAI,GAAG,IAAI,mBAAmB,QAAQ,IAAI,GAAG,KAAK;AAAE,iCAA2B,mBAAmB,MAAM;AAAA,IAAU;AAAA,EAC7H;AACF,CAAC;AAED,mCAAoC,SAAS,WAAW;AACtD,MAAK,aAAa,OAAO,MAAM,WAAY,CAAC,QAAQ;AAAM,WAAO;AACjE,MAAI,UAAU,YAAY,KAAK;AAAS,WAAO;AAC/C,MAAI,YAAY,QAAQ;AACxB,SAAQ,aAAa,cAAgB,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AAC7D,UAAI,QAAQ,SAAS,YAAY,aAAa;AAC9C,YAAM,UAAU,WAAW,MAAM,MAAM,QAAQ,QAAQ,GAAG,GAAG,GAAG,GAAG,GAAG,OAAO,OAAO,OAAO,OAAO,GAAG,OAAO;AAC5G,cAAQ,cAAc,KAAK;AAAA,IAC7B,OAAO;AAAE,YAAM,IAAI,MAAM,oDAAoD;AAAA,IAAE;AAAA,EACjF,WAAW,sBAAsB,QAAQ,OAAO;AAC9C,YAAQ,MAAM;AAAA,EAChB,WAAW,OAAO,QAAQ,cAAc,aAAa;AACnD,YAAQ,UAAU,OAAO,SAAS;AAAA,EACpC,OAAO;AACL,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AACF;", | ||
| "sourcesContent": ["//\n// DOM Events\n//\n\nimport { objectForEach } from '../object'\nimport { catchFunctionErrors } from '../error'\nimport { tagNameLower } from './info'\n\nimport options from '../options'\n\n// Represent the known event types in a compact way, then at runtime transform it into a hash with event name as key (for fast lookup)\nconst knownEvents = {},\n knownEventTypesByEventName = {}\n\nknownEvents['UIEvents'] = ['keyup', 'keydown', 'keypress']\n\nknownEvents['MouseEvents'] = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseover',\n 'mouseout',\n 'mouseenter',\n 'mouseleave'\n]\n\nobjectForEach(knownEvents, function (eventType, knownEventsForType) {\n if (knownEventsForType.length) {\n for (let i = 0, j = knownEventsForType.length; i < j; i++) {\n knownEventTypesByEventName[knownEventsForType[i]] = eventType\n }\n }\n})\n\nfunction isClickOnCheckableElement(element: Element, eventType: string) {\n if (tagNameLower(element) !== 'input' || !(element as HTMLInputElement).type) return false\n if (eventType.toLowerCase() != 'click') return false\n const inputType = (element as HTMLInputElement).type\n return inputType == 'checkbox' || inputType == 'radio'\n}\n\nexport function registerEventHandler(\n element: Element,\n eventType: string,\n handler: EventListener,\n eventOptions = false\n): void {\n const wrappedHandler = catchFunctionErrors(handler)\n const mustUseNative = Boolean(eventOptions)\n const jQuery = options.jQuery\n\n if (!options.useOnlyNativeEvents && !mustUseNative && jQuery) {\n jQuery(element).on(eventType, wrappedHandler)\n } else if (typeof element.addEventListener === 'function') {\n element.addEventListener(eventType, wrappedHandler, eventOptions)\n } else {\n throw new Error(\"Browser doesn't support addEventListener\")\n }\n}\n\nfunction hasClick(element: Element): element is Element & { click(): void } {\n return typeof (element as any).click === 'function'\n}\n\nexport function triggerEvent(element: Element, eventType: string): void {\n if (!(element && element.nodeType)) {\n throw new Error('element must be a DOM node when calling triggerEvent')\n }\n\n // For click events on checkboxes and radio buttons, jQuery toggles the element checked state *after* the\n // event handler runs instead of *before*. (This was fixed in 1.9 for checkboxes but not for radio buttons.)\n const useClickWorkaround = isClickOnCheckableElement(element, eventType)\n\n if (!options.useOnlyNativeEvents && options.jQuery && !useClickWorkaround) {\n options.jQuery(element).trigger(eventType)\n } else if (typeof document.createEvent === 'function') {\n if (typeof element.dispatchEvent === 'function') {\n const eventCategory = knownEventTypesByEventName[eventType] || 'HTMLEvents'\n const event = document.createEvent(eventCategory)\n ;(event as any).initEvent(\n eventType,\n true,\n true,\n options.global,\n 0,\n 0,\n 0,\n 0,\n 0,\n false,\n false,\n false,\n false,\n 0,\n element\n )\n element.dispatchEvent(event)\n } else {\n throw new Error(\"The supplied element doesn't support dispatchEvent\")\n }\n } else if (useClickWorkaround && hasClick(element)) {\n element.click()\n } else {\n throw new Error(\"Browser doesn't support triggering events\")\n }\n}\n"], | ||
| "mappings": ";;AAIA,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAE7B,OAAO,aAAa;AAGpB,MAAM,cAAc,CAAC,GACnB,6BAA6B,CAAC;AAEhC,YAAY,UAAU,IAAI,CAAC,SAAS,WAAW,UAAU;AAEzD,YAAY,aAAa,IAAI;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;A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gB,2BAA2B,SAAS,KAAK;AAC/D,YAAM,QAAQ,SAAS,YAAY,aAAa;AAC/C,MAAC,MAAc;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,cAAQ,cAAc,KAAK;AAAA,IAC7B,OAAO;AACL,YAAM,IAAI,MAAM,oDAAoD;AAAA,IACtE;AAAA,EACF,WAAW,sBAAsB,SAAS,OAAO,GAAG;AAClD,YAAQ,MAAM;AAAA,EAChB,OAAO;AACL,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AACF;", | ||
| "names": [] | ||
| } |
+5
-24
@@ -1,6 +0,6 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| import { ieVersion } from "../ie"; | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) { | ||
| if (continuousNodeArray.length) { | ||
| parentNode = parentNode.nodeType === 8 && parentNode.parentNode || parentNode; | ||
| parentNode = parentNode.nodeType === Node.COMMENT_NODE && parentNode.parentNode || parentNode; | ||
| while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) { | ||
@@ -13,3 +13,3 @@ continuousNodeArray.splice(0, 1); | ||
| if (continuousNodeArray.length > 1) { | ||
| var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1]; | ||
| let current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1]; | ||
| continuousNodeArray.length = 0; | ||
@@ -26,22 +26,3 @@ while (current !== last) { | ||
| export function setOptionNodeSelectionState(optionNode, isSelected) { | ||
| if (ieVersion < 7) { | ||
| optionNode.setAttribute("selected", isSelected); | ||
| } else { | ||
| optionNode.selected = isSelected; | ||
| } | ||
| optionNode.selected = isSelected; | ||
| } | ||
| export function forceRefresh(node) { | ||
| if (ieVersion >= 9) { | ||
| var elem = node.nodeType == 1 ? node : node.parentNode; | ||
| if (elem.style) { | ||
| elem.style.zoom = elem.style.zoom; | ||
| } | ||
| } | ||
| } | ||
| export function ensureSelectElementIsRenderedCorrectly(selectElement) { | ||
| if (ieVersion) { | ||
| var originalWidth = selectElement.style.width; | ||
| selectElement.style.width = 0; | ||
| selectElement.style.width = originalWidth; | ||
| } | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/fixes.ts"], | ||
| "sourcesContent": ["//\n// DOM node manipulation\n//\nimport { ieVersion } from '../ie'\n\nexport function fixUpContinuousNodeArray (continuousNodeArray, parentNode) {\n // Before acting on a set of nodes that were previously outputted by a template function, we have to reconcile\n // them against what is in the DOM right now. It may be that some of the nodes have already been removed, or that\n // new nodes might have been inserted in the middle, for example by a binding. Also, there may previously have been\n // leading comment nodes (created by rewritten string-based templates) that have since been removed during binding.\n // So, this function translates the old \"map\" output array into its best guess of the set of current DOM nodes.\n //\n // Rules:\n // [A] Any leading nodes that have been removed should be ignored\n // These most likely correspond to memoization nodes that were already removed during binding\n // See https://github.com/knockout/knockout/pull/440\n // [B] Any trailing nodes that have been remove should be ignored\n // This prevents the code here from adding unrelated nodes to the array while processing rule [C]\n // See https://github.com/knockout/knockout/pull/1903\n // [C] We want to output a continuous series of nodes. So, ignore any nodes that have already been removed,\n // and include any nodes that have been inserted among the previous collection\n\n if (continuousNodeArray.length) {\n // The parent node can be a virtual element; so get the real parent node\n parentNode = (parentNode.nodeType === 8 && parentNode.parentNode) || parentNode\n\n // Rule [A]\n while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) { continuousNodeArray.splice(0, 1) }\n\n // Rule [B]\n while (continuousNodeArray.length > 1 && continuousNodeArray[continuousNodeArray.length - 1].parentNode !== parentNode) { continuousNodeArray.length-- }\n\n // Rule [C]\n if (continuousNodeArray.length > 1) {\n var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1]\n // Replace with the actual new continuous node set\n continuousNodeArray.length = 0\n while (current !== last) {\n continuousNodeArray.push(current)\n current = current.nextSibling\n }\n continuousNodeArray.push(last)\n }\n }\n return continuousNodeArray\n}\n\nexport function setOptionNodeSelectionState (optionNode, isSelected) {\n // IE6 sometimes throws \"unknown error\" if you try to write to .selected directly, whereas Firefox struggles with setAttribute. Pick one based on browser.\n if (ieVersion < 7) { optionNode.setAttribute('selected', isSelected) } else { optionNode.selected = isSelected }\n}\n\nexport function forceRefresh (node) {\n // Workaround for an IE9 rendering bug - https://github.com/SteveSanderson/knockout/issues/209\n if (ieVersion >= 9) {\n // For text nodes and comment nodes (most likely virtual elements), we will have to refresh the container\n var elem = node.nodeType == 1 ? node : node.parentNode\n if (elem.style) { elem.style.zoom = elem.style.zoom }\n }\n}\n\nexport function ensureSelectElementIsRenderedCorrectly (selectElement) {\n // Workaround for IE9 rendering bug - it doesn't reliably display all the text in dynamically-added select boxes unless you force it to re-render by updating the width.\n // (See https://github.com/SteveSanderson/knockout/issues/312, http://stackoverflow.com/questions/5908494/select-only-shows-first-char-of-selected-option)\n // Also fixes IE7 and IE8 bug that causes selects to be zero width if enclosed by 'if' or 'with'. (See issue #839)\n if (ieVersion) {\n var originalWidth = selectElement.style.width\n selectElement.style.width = 0\n selectElement.style.width = originalWidth\n }\n}\n"], | ||
| "mappings": ";AAGA;AAEO,yCAAmC,qBAAqB,YAAY;AAiBzE,MAAI,oBAAoB,QAAQ;AAE9B,iBAAc,WAAW,aAAa,KAAK,WAAW,cAAe;AAGrE,WAAO,oBAAoB,UAAU,oBAAoB,GAAG,eAAe,YAAY;AAAE,0BAAoB,OAAO,GAAG,CAAC;AAAA,IAAE;AAG1H,WAAO,oBAAoB,SAAS,KAAK,oBAAoB,oBAAoB,SAAS,GAAG,eAAe,YAAY;AAAE,0BAAoB;AAAA,IAAS;AAGvJ,QAAI,oBAAoB,SAAS,GAAG;AAClC,UAAI,UAAU,oBAAoB,IAAI,OAAO,oBAAoB,oBAAoB,SAAS;AAE9F,0BAAoB,SAAS;AAC7B,aAAO,YAAY,MAAM;AACvB,4BAAoB,KAAK,OAAO;AAChC,kBAAU,QAAQ;AAAA,MACpB;AACA,0BAAoB,KAAK,IAAI;AAAA,IAC/B;AAAA,EACF;AACA,SAAO;AACT;AAEO,4CAAsC,YAAY,YAAY;AAEnE,MAAI,YAAY,GAAG;AAAE,eAAW,aAAa,YAAY,UAAU;AAAA,EAAE,OAAO;AAAE,eAAW,WAAW;AAAA,EAAW;AACjH;AAEO,6BAAuB,MAAM;AAElC,MAAI,aAAa,GAAG;AAElB,QAAI,OAAO,KAAK,YAAY,IAAI,OAAO,KAAK;AAC5C,QAAI,KAAK,OAAO;AAAE,WAAK,MAAM,OAAO,KAAK,MAAM;AAAA,IAAK;AAAA,EACtD;AACF;AAEO,uDAAiD,eAAe;AAIrE,MAAI,WAAW;AACb,QAAI,gBAAgB,cAAc,MAAM;AACxC,kBAAc,MAAM,QAAQ;AAC5B,kBAAc,MAAM,QAAQ;AAAA,EAC9B;AACF;", | ||
| "sourcesContent": ["//\n// DOM node manipulation\n//\n\nexport function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {\n // Before acting on a set of nodes that were previously outputted by a template function, we have to reconcile\n // them against what is in the DOM right now. It may be that some of the nodes have already been removed, or that\n // new nodes might have been inserted in the middle, for example by a binding. Also, there may previously have been\n // leading comment nodes (created by rewritten string-based templates) that have since been removed during binding.\n // So, this function translates the old \"map\" output array into its best guess of the set of current DOM nodes.\n //\n // Rules:\n // [A] Any leading nodes that have been removed should be ignored\n // These most likely correspond to memoization nodes that were already removed during binding\n // See https://github.com/knockout/knockout/pull/440\n // [B] Any trailing nodes that have been remove should be ignored\n // This prevents the code here from adding unrelated nodes to the array while processing rule [C]\n // See https://github.com/knockout/knockout/pull/1903\n // [C] We want to output a continuous series of nodes. So, ignore any nodes that have already been removed,\n // and include any nodes that have been inserted among the previous collection\n\n if (continuousNodeArray.length) {\n // The parent node can be a virtual element; so get the real parent node\n parentNode = (parentNode.nodeType === Node.COMMENT_NODE && parentNode.parentNode) || parentNode\n\n // Rule [A]\n while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) {\n continuousNodeArray.splice(0, 1)\n }\n\n // Rule [B]\n while (\n continuousNodeArray.length > 1\n && continuousNodeArray[continuousNodeArray.length - 1].parentNode !== parentNode\n ) {\n continuousNodeArray.length--\n }\n\n // Rule [C]\n if (continuousNodeArray.length > 1) {\n let current = continuousNodeArray[0],\n last = continuousNodeArray[continuousNodeArray.length - 1]\n // Replace with the actual new continuous node set\n continuousNodeArray.length = 0\n while (current !== last) {\n continuousNodeArray.push(current)\n current = current.nextSibling\n }\n continuousNodeArray.push(last)\n }\n }\n return continuousNodeArray\n}\n\nexport function setOptionNodeSelectionState(optionNode, isSelected) {\n optionNode.selected = isSelected\n}\n"], | ||
| "mappings": ";;AAIO,gBAAS,yBAAyB,qBAAqB,YAAY;AAiBxE,MAAI,oBAAoB,QAAQ;AAE9B,iBAAc,WAAW,aAAa,KAAK,gBAAgB,WAAW,cAAe;AAGrF,WAAO,oBAAoB,UAAU,oBAAoB,CAAC,EAAE,eAAe,YAAY;AACrF,0BAAoB,OAAO,GAAG,CAAC;AAAA,IACjC;AAGA,WACE,oBAAoB,SAAS,KAC1B,oBAAoB,oBAAoB,SAAS,CAAC,EAAE,eAAe,YACtE;AACA,0BAAoB;AAAA,IACtB;AAGA,QAAI,oBAAoB,SAAS,GAAG;AAClC,UAAI,UAAU,oBAAoB,CAAC,GACjC,OAAO,oBAAoB,oBAAoB,SAAS,CAAC;AAE3D,0BAAoB,SAAS;AAC7B,aAAO,YAAY,MAAM;AACvB,4BAAoB,KAAK,OAAO;AAChC,kBAAU,QAAQ;AAAA,MACpB;AACA,0BAAoB,KAAK,IAAI;AAAA,IAC/B;AAAA,EACF;AACA,SAAO;AACT;AAEO,gBAAS,4BAA4B,YAAY,YAAY;AAClE,aAAW,WAAW;AACxB;", | ||
| "names": [] | ||
| } |
+46
-61
@@ -1,43 +0,15 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| import { stringTrim } from "../string"; | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { makeArray } from "../array"; | ||
| import { emptyDomNode, moveCleanedNodesToContainerElement } from "./manipulation"; | ||
| import { jQueryInstance } from "../jquery"; | ||
| import { forceRefresh } from "./fixes"; | ||
| import * as virtualElements from "./virtualElements"; | ||
| import options from "../options"; | ||
| var none = [0, "", ""], table = [1, "<table>", "</table>"], tbody = [2, "<table><tbody>", "</tbody></table>"], colgroup = [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"], tr = [3, "<table><tbody><tr>", "</tr></tbody></table>"], select = [1, "<select multiple='multiple'>", "</select>"], fieldset = [1, "<fieldset>", "</fieldset>"], map = [1, "<map>", "</map>"], object = [1, "<object>", "</object>"], lookup = { | ||
| "area": map, | ||
| "col": colgroup, | ||
| "colgroup": table, | ||
| "caption": table, | ||
| "legend": fieldset, | ||
| "thead": table, | ||
| "tbody": table, | ||
| "tfoot": table, | ||
| "tr": tbody, | ||
| "td": tr, | ||
| "th": tr, | ||
| "option": select, | ||
| "optgroup": select, | ||
| "param": object | ||
| }, supportsTemplateTag = options.document && "content" in options.document.createElement("template"); | ||
| function getWrap(tags) { | ||
| const m = tags.match(/^(?:<!--.*?-->\s*?)*?<([a-z]+)[\s>]/); | ||
| return m && lookup[m[1]] || none; | ||
| } | ||
| const supportsTemplateTag = options.useTemplateTag && options.document && "content" in options.document.createElement("template"); | ||
| function simpleHtmlParse(html, documentContext) { | ||
| documentContext || (documentContext = document); | ||
| var windowContext = documentContext["parentWindow"] || documentContext["defaultView"] || window; | ||
| var tags = stringTrim(html).toLowerCase(), div = documentContext.createElement("div"), wrap = getWrap(tags), depth = wrap[0]; | ||
| var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>"; | ||
| if (typeof windowContext["innerShiv"] === "function") { | ||
| div.appendChild(windowContext["innerShiv"](markup)); | ||
| } else { | ||
| div.innerHTML = markup; | ||
| if (!documentContext) { | ||
| documentContext = document; | ||
| } | ||
| while (depth--) { | ||
| div = div.lastChild; | ||
| } | ||
| return makeArray(div.lastChild.childNodes); | ||
| const div = documentContext.createElement("div"); | ||
| div.innerHTML = html; | ||
| return makeArray(div.childNodes); | ||
| } | ||
@@ -48,3 +20,3 @@ function templateHtmlParse(html, documentContext) { | ||
| } | ||
| var template = documentContext.createElement("template"); | ||
| const template = documentContext.createElement("template"); | ||
| template.innerHTML = html; | ||
@@ -54,21 +26,27 @@ return makeArray(template.content.childNodes); | ||
| function jQueryHtmlParse(html, documentContext) { | ||
| if (jQueryInstance.parseHTML) { | ||
| return jQueryInstance.parseHTML(html, documentContext) || []; | ||
| } else { | ||
| var elems = jQueryInstance.clean([html], documentContext); | ||
| if (elems && elems[0]) { | ||
| var elem = elems[0]; | ||
| while (elem.parentNode && elem.parentNode.nodeType !== 11) { | ||
| elem = elem.parentNode; | ||
| } | ||
| if (elem.parentNode) { | ||
| elem.parentNode.removeChild(elem); | ||
| } | ||
| } | ||
| return elems; | ||
| const jQuery = options.jQuery; | ||
| if (jQuery) { | ||
| return jQuery.parseHTML(html, documentContext) || []; | ||
| } | ||
| return []; | ||
| } | ||
| export function parseHtmlFragment(html, documentContext) { | ||
| return supportsTemplateTag ? templateHtmlParse(html, documentContext) : jQueryInstance ? jQueryHtmlParse(html, documentContext) : simpleHtmlParse(html, documentContext); | ||
| const saferHtml = validateHTMLInput(html); | ||
| if (supportsTemplateTag) return templateHtmlParse(saferHtml, documentContext); | ||
| if (options.jQuery) { | ||
| return jQueryHtmlParse(saferHtml, documentContext); | ||
| } | ||
| return simpleHtmlParse(saferHtml, documentContext); | ||
| } | ||
| const scriptTagPattern = /<script\b[^>]*>([\s\S]*?)<\/script[^>]*>/i; | ||
| function validateHTMLInput(html) { | ||
| if (!html) return ""; | ||
| if (options.templateSizeLimit > 0 && html.length > options.templateSizeLimit) { | ||
| throw new Error("Template is too long. Please configure the 'templateSizeLimit'"); | ||
| } | ||
| if (!options.allowScriptTagsInTemplates && scriptTagPattern.test(html)) { | ||
| throw new Error("Script-tag in template detected."); | ||
| } | ||
| return options.sanitizeHtmlTemplate(html); | ||
| } | ||
| export function parseHtmlForTemplateNodes(html, documentContext) { | ||
@@ -87,7 +65,14 @@ const nodes = parseHtmlFragment(html, documentContext); | ||
| } | ||
| if (jQueryInstance && !supportsTemplateTag) { | ||
| jQueryInstance(node).html(html); | ||
| const jQuery = options.jQuery; | ||
| if (jQuery && !supportsTemplateTag) { | ||
| const saferHtml = validateHTMLInput(html); | ||
| jQuery(node).html(saferHtml); | ||
| } else { | ||
| var parsedNodes = parseHtmlFragment(html, node.ownerDocument); | ||
| if (node.nodeType === 8) { | ||
| let parsedNodes; | ||
| if (node.ownerDocument) { | ||
| parsedNodes = parseHtmlFragment(html, node.ownerDocument); | ||
| } else { | ||
| parsedNodes = parseHtmlFragment(html); | ||
| } | ||
| if (node.nodeType === Node.COMMENT_NODE) { | ||
| if (html === null) { | ||
@@ -99,3 +84,3 @@ virtualElements.emptyNode(node); | ||
| } else { | ||
| for (var i = 0; i < parsedNodes.length; i++) { | ||
| for (let i = 0; i < parsedNodes.length; i++) { | ||
| node.appendChild(parsedNodes[i]); | ||
@@ -108,13 +93,13 @@ } | ||
| export function setTextContent(element, textContent) { | ||
| var value = typeof textContent === "function" ? textContent() : textContent; | ||
| let value = typeof textContent === "function" ? textContent() : textContent; | ||
| if (value === null || value === void 0) { | ||
| value = ""; | ||
| } | ||
| var innerTextNode = virtualElements.firstChild(element); | ||
| if (!innerTextNode || innerTextNode.nodeType != 3 || virtualElements.nextSibling(innerTextNode)) { | ||
| const innerTextNode = virtualElements.firstChild(element); | ||
| if (!innerTextNode || innerTextNode.nodeType !== Node.TEXT_NODE || virtualElements.nextSibling(innerTextNode)) { | ||
| virtualElements.setDomNodeChildren(element, [element.ownerDocument.createTextNode(value)]); | ||
| } else { | ||
| ; | ||
| innerTextNode.data = value; | ||
| } | ||
| forceRefresh(element); | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/html.ts"], | ||
| "sourcesContent": ["//\n// HTML-based manipulation\n//\nimport { stringTrim } from '../string'\nimport { makeArray } from '../array'\nimport { emptyDomNode, moveCleanedNodesToContainerElement } from './manipulation'\nimport { jQueryInstance } from '../jquery'\nimport { forceRefresh } from './fixes'\nimport * as virtualElements from './virtualElements'\nimport options from '../options'\n\nvar none = [0, '', ''],\n table = [1, '<table>', '</table>'],\n tbody = [2, '<table><tbody>', '</tbody></table>'],\n colgroup = [ 2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],\n tr = [3, '<table><tbody><tr>', '</tr></tbody></table>'],\n select = [1, \"<select multiple='multiple'>\", '</select>'],\n fieldset = [1, '<fieldset>', '</fieldset>'],\n map = [1, '<map>', '</map>'],\n object = [1, '<object>', '</object>'],\n lookup = {\n 'area': map,\n 'col': colgroup,\n 'colgroup': table,\n 'caption': table,\n 'legend': fieldset,\n 'thead': table,\n 'tbody': table,\n 'tfoot': table,\n 'tr': tbody,\n 'td': tr,\n 'th': tr,\n 'option': select,\n 'optgroup': select,\n 'param': object\n },\n\n // The canonical way to test that the HTML5 <template> tag is supported\n supportsTemplateTag = options.document && 'content' in options.document.createElement('template')\n\nfunction getWrap (tags) {\n const m = tags.match(/^(?:<!--.*?-->\\s*?)*?<([a-z]+)[\\s>]/)\n return (m && lookup[m[1]]) || none\n}\n\nfunction simpleHtmlParse (html, documentContext) {\n documentContext || (documentContext = document)\n var windowContext = documentContext['parentWindow'] || documentContext['defaultView'] || window\n\n // Based on jQuery's \"clean\" function, but only accounting for table-related elements.\n // If you have referenced jQuery, this won't be used anyway - KO will use jQuery's \"clean\" function directly\n\n // Note that there's still an issue in IE < 9 whereby it will discard comment nodes that are the first child of\n // a descendant node. For example: \"<div><!-- mycomment -->abc</div>\" will get parsed as \"<div>abc</div>\"\n // This won't affect anyone who has referenced jQuery, and there's always the workaround of inserting a dummy node\n // (possibly a text node) in front of the comment. So, KO does not attempt to workaround this IE issue automatically at present.\n\n // Trim whitespace, otherwise indexOf won't work as expected\n var tags = stringTrim(html).toLowerCase(), div = documentContext.createElement('div'),\n wrap = getWrap(tags),\n depth = wrap[0]\n\n // Go to html and back, then peel off extra wrappers\n // Note that we always prefix with some dummy text, because otherwise, IE<9 will strip out leading comment nodes in descendants. Total madness.\n var markup = 'ignored<div>' + wrap[1] + html + wrap[2] + '</div>'\n if (typeof windowContext['innerShiv'] === 'function') {\n // Note that innerShiv is deprecated in favour of html5shiv. We should consider adding\n // support for html5shiv (except if no explicit support is needed, e.g., if html5shiv\n // somehow shims the native APIs so it just works anyway)\n div.appendChild(windowContext['innerShiv'](markup))\n } else {\n div.innerHTML = markup\n }\n\n // Move to the right depth\n while (depth--) { div = div.lastChild }\n\n return makeArray(div.lastChild.childNodes)\n}\n\nfunction templateHtmlParse (html, documentContext) {\n if (!documentContext) { documentContext = document }\n var template = documentContext.createElement('template')\n template.innerHTML = html\n return makeArray(template.content.childNodes)\n}\n\nfunction jQueryHtmlParse (html, documentContext) {\n // jQuery's \"parseHTML\" function was introduced in jQuery 1.8.0 and is a documented public API.\n if (jQueryInstance.parseHTML) {\n return jQueryInstance.parseHTML(html, documentContext) || [] // Ensure we always return an array and never null\n } else {\n // For jQuery < 1.8.0, we fall back on the undocumented internal \"clean\" function.\n var elems = jQueryInstance.clean([html], documentContext)\n\n // As of jQuery 1.7.1, jQuery parses the HTML by appending it to some dummy parent nodes held in an in-memory document fragment.\n // Unfortunately, it never clears the dummy parent nodes from the document fragment, so it leaks memory over time.\n // Fix this by finding the top-most dummy parent element, and detaching it from its owner fragment.\n if (elems && elems[0]) {\n // Find the top-most parent element that's a direct child of a document fragment\n var elem = elems[0]\n while (elem.parentNode && elem.parentNode.nodeType !== 11 /* i.e., DocumentFragment */) { elem = elem.parentNode }\n // ... then detach it\n if (elem.parentNode) { elem.parentNode.removeChild(elem) }\n }\n\n return elems\n }\n}\n\n/**\n * parseHtmlFragment converts a string into an array of DOM Nodes.\n * If supported, it uses <template>-tag parsing, falling back on\n * jQuery parsing (if jQuery is present), and finally on a\n * straightforward parser.\n *\n * @param {string} html To be parsed.\n * @param {Object} documentContext That owns the executing code.\n * @return {[DOMNode]} Parsed DOM Nodes\n */\nexport function parseHtmlFragment (html, documentContext) {\n // Prefer <template>-tag based HTML parsing.\n return supportsTemplateTag ? templateHtmlParse(html, documentContext)\n\n // Benefit from jQuery's on old browsers, where possible\n // NOTE: jQuery's HTML parsing fails on element names like tr-*.\n // See: https://github.com/jquery/jquery/pull/1988\n : (jQueryInstance ? jQueryHtmlParse(html, documentContext)\n\n // ... otherwise, this simple logic will do in most common cases.\n : simpleHtmlParse(html, documentContext))\n}\n\nexport function parseHtmlForTemplateNodes (html, documentContext) {\n const nodes = parseHtmlFragment(html, documentContext)\n return (nodes.length && nodes[0].parentElement) || moveCleanedNodesToContainerElement(nodes)\n}\n\n/**\n * setHtml empties the node's contents, unwraps the HTML, and\n * sets the node's HTML using jQuery.html or parseHtmlFragment\n *\n * @param {DOMNode} node Node in which HTML needs to be set\n * @param {DOMNode} html HTML to be inserted in node\n * @returns undefined\n */\nexport function setHtml (node, html) {\n emptyDomNode(node)\n\n // There's few cases where we would want to display a stringified\n // function, so we unwrap it.\n if (typeof html === 'function') {\n html = html()\n }\n\n if ((html !== null) && (html !== undefined)) {\n if (typeof html !== 'string') { html = html.toString() }\n\n // If the browser supports <template> tags, prefer that, as\n // it obviates all the complex workarounds of jQuery.\n //\n // However, jQuery contains a lot of sophisticated code to parse arbitrary HTML fragments,\n // for example <tr> elements which are not normally allowed to exist on their own.\n // If you've referenced jQuery (and template tags are not supported) we'll use that rather than duplicating its code.\n if (jQueryInstance && !supportsTemplateTag) {\n jQueryInstance(node).html(html)\n } else {\n // ... otherwise, use KO's own parsing logic.\n var parsedNodes = parseHtmlFragment(html, node.ownerDocument)\n\n if (node.nodeType === 8) {\n if (html === null) {\n virtualElements.emptyNode(node)\n } else {\n virtualElements.setDomNodeChildren(node, parsedNodes)\n }\n } else {\n for (var i = 0; i < parsedNodes.length; i++) { node.appendChild(parsedNodes[i]) }\n }\n }\n }\n}\n\n\nexport function setTextContent (element, textContent) {\n var value = typeof textContent === 'function' ? textContent() : textContent\n if ((value === null) || (value === undefined)) { value = '' }\n\n // We need there to be exactly one child: a text node.\n // If there are no children, more than one, or if it's not a text node,\n // we'll clear everything and create a single text node.\n var innerTextNode = virtualElements.firstChild(element)\n if (!innerTextNode || innerTextNode.nodeType != 3 || virtualElements.nextSibling(innerTextNode)) {\n virtualElements.setDomNodeChildren(element, [element.ownerDocument.createTextNode(value)])\n } else {\n innerTextNode.data = value\n }\n\n forceRefresh(element)\n}\n"], | ||
| "mappings": ";AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAI,OAAO,CAAC,GAAG,IAAI,EAAE,GACnB,QAAQ,CAAC,GAAG,WAAW,UAAU,GACjC,QAAQ,CAAC,GAAG,kBAAkB,kBAAkB,GAChD,WAAW,CAAE,GAAG,oCAAoC,qBAAqB,GACzE,KAAK,CAAC,GAAG,sBAAsB,uBAAuB,GACtD,SAAS,CAAC,GAAG,gCAAgC,WAAW,GACxD,WAAW,CAAC,GAAG,cAAc,aAAa,GAC1C,MAAM,CAAC,GAAG,SAAS,QAAQ,GAC3B,SAAS,CAAC,GAAG,YAAY,WAAW,GACpC,SAAS;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,SAAS;AACX,GAGA,sBAAsB,QAAQ,YAAY,aAAa,QAAQ,SAAS,cAAc,UAAU;AAElG,iBAAkB,MAAM;AACtB,QAAM,IAAI,KAAK,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A,eAAa,OAAO;AACtB;", | ||
| "sourcesContent": ["//\n// HTML-based manipulation\n//\nimport { makeArray } from '../array'\nimport { emptyDomNode, moveCleanedNodesToContainerElement } from './manipulation'\nimport * as virtualElements from './virtualElements'\nimport options from '../options'\n\n// The canonical way to test that the HTML5 <template> tag is supported\nconst supportsTemplateTag =\n options.useTemplateTag && options.document && 'content' in options.document.createElement('template')\n\n/** @deprecated HTMLTemplateTag or the jquery-template-function as fallback are enough */\nfunction simpleHtmlParse(html: string, documentContext?: Document): Node[] {\n if (!documentContext) {\n documentContext = document\n }\n const div = documentContext.createElement('div')\n div.innerHTML = html\n return makeArray(div.childNodes)\n}\n\nfunction templateHtmlParse(html: string, documentContext?: Document): Node[] {\n if (!documentContext) {\n documentContext = document\n }\n const template = documentContext.createElement('template') as HTMLTemplateElement\n template.innerHTML = html\n return makeArray(template.content.childNodes)\n}\n\nfunction jQueryHtmlParse(html: string, documentContext?: Document): Node[] {\n const jQuery = options.jQuery\n\n // jQuery's \"parseHTML\" function was introduced in jQuery 1.8.0 and is a documented public API.\n if (jQuery) {\n return jQuery.parseHTML(html, documentContext) || [] // Ensure we always return an array and never null\n }\n\n return []\n}\n\n/**\n * parseHtmlFragment converts a string into an array of DOM Nodes.\n * If supported, it uses <template>-tag parsing, falling back on\n * jQuery parsing (if jQuery is present), and finally on a\n * straightforward parser.\n *\n * @param {string} html To be parsed.\n * @param {Document} documentContext That owns the executing code.\n * @return {[Node]} Parsed DOM Nodes\n */\nexport function parseHtmlFragment(html: string, documentContext?: Document): Node[] {\n const saferHtml = validateHTMLInput(html)\n\n // Prefer <template>-tag based HTML parsing.\n if (supportsTemplateTag) return templateHtmlParse(saferHtml, documentContext)\n\n //TODO: It is always true in modern browsers (higher IE11), so we can theoretically remove jQueryHtmlParse and simpleHtmlParse\n if (options.jQuery) {\n // Benefit from jQuery's on old browsers, where possible\n // NOTE: jQuery's HTML parsing fails on element names like tr-*.\n // See: https://github.com/jquery/jquery/pull/1988\n return jQueryHtmlParse(saferHtml, documentContext)\n }\n\n return simpleHtmlParse(saferHtml, documentContext)\n}\n\nconst scriptTagPattern = /<script\\b[^>]*>([\\s\\S]*?)<\\/script[^>]*>/i\nfunction validateHTMLInput(html: string): string {\n if (!html) return ''\n\n if (options.templateSizeLimit > 0 && html.length > options.templateSizeLimit) {\n throw new Error(\"Template is too long. Please configure the 'templateSizeLimit'\")\n }\n\n if (!options.allowScriptTagsInTemplates && scriptTagPattern.test(html)) {\n throw new Error('Script-tag in template detected.')\n }\n\n return options.sanitizeHtmlTemplate(html)\n}\n\nexport function parseHtmlForTemplateNodes(html, documentContext) {\n const nodes = parseHtmlFragment(html, documentContext)\n return (nodes.length && nodes[0].parentElement) || moveCleanedNodesToContainerElement(nodes)\n}\n\n/**\n * setHtml empties the node's contents, unwraps the HTML, and\n * sets the node's HTML using jQuery.html or parseHtmlFragment\n *\n * @param {DOMNode} node Node in which HTML needs to be set\n * @param {DOMNode} html HTML to be inserted in node\n * @returns undefined\n */\nexport function setHtml(node: Node, html: Function | string) {\n emptyDomNode(node)\n\n // There's few cases where we would want to display a stringified\n // function, so we unwrap it.\n if (typeof html === 'function') {\n html = html()\n }\n\n if (html !== null && html !== undefined) {\n if (typeof html !== 'string') {\n html = html.toString()\n }\n\n const jQuery = options.jQuery\n // If the browser supports <template> tags, prefer that, as\n // it obviates all the complex workarounds of jQuery.\n //\n // However, jQuery contains a lot of sophisticated code to parse arbitrary HTML fragments,\n // for example <tr> elements which are not normally allowed to exist on their own.\n // If you've referenced jQuery (and template tags are not supported) we'll use that rather than duplicating its code.\n if (jQuery && !supportsTemplateTag) {\n const saferHtml = validateHTMLInput(html)\n jQuery(node).html(saferHtml)\n } else {\n // ... otherwise, use KO's own parsing logic.\n let parsedNodes: Node[]\n if (node.ownerDocument) {\n parsedNodes = parseHtmlFragment(html, node.ownerDocument)\n } else {\n parsedNodes = parseHtmlFragment(html)\n }\n\n if (node.nodeType === Node.COMMENT_NODE) {\n if (html === null) {\n virtualElements.emptyNode(node)\n } else {\n virtualElements.setDomNodeChildren(node, parsedNodes)\n }\n } else {\n for (let i = 0; i < parsedNodes.length; i++) {\n node.appendChild(parsedNodes[i])\n }\n }\n }\n }\n}\n\n//TODO May be MaybeSubscribable<string> -> I actually don't want the dependency\ntype TextContent = string | null | undefined | Function\nexport function setTextContent(element: Node, textContent?: TextContent): void {\n let value = typeof textContent === 'function' ? (textContent as Function)() : textContent\n if (value === null || value === undefined) {\n value = ''\n }\n\n // We need there to be exactly one child: a text node.\n // If there are no children, more than one, or if it's not a text node,\n // we'll clear everything and create a single text node.\n const innerTextNode = virtualElements.firstChild(element)\n if (!innerTextNode || innerTextNode.nodeType !== Node.TEXT_NODE || virtualElements.nextSibling(innerTextNode)) {\n virtualElements.setDomNodeChildren(element, [element.ownerDocument!.createTextNode(value)])\n } else {\n ;(innerTextNode as Text).data = value\n }\n}\n"], | ||
| "mappings": ";;AAGA,SAAS,iBAAiB;AAC1B,SAAS,cAAc,0CAA0C;AACjE,YAAY,qBAAqB;AACjC,OAAO,aAAa;AAGpB,MAAM,sBACJ,QAAQ,kBAAkB,QAAQ,YAAY,aAAa,QAAQ,SAAS,cAAc,UAAU;AAGtG,SAAS,gBAAgB,MAAc,iBAAoC;AACzE,MAAI,CAAC,iBAAiB;AACpB,sBAAkB;AAAA,EACpB;AACA,QAAM,MAAM,gBAAgB,cAAc,KAAK;AAC/C,MAAI,YAAY;AAChB,SAAO,UAAU,IAAI,UAAU;AACjC;AAEA,SAAS,kBAAkB,MAAc,iBAAoC;AAC3E,MAAI,CAAC,iBAAiB;AACpB,sBAAkB;AAAA,EACpB;AACA,QAAM,WAAW,gBAAgB,cAAc,UAAU;AACzD,WAAS,YAAY;AACrB,SAAO,UAAU,SAAS,QAAQ,UAAU;AAC9C;AAEA,SAAS,gBAAgB,MAAc,iBAAoC;AACzE,QAAM,SAAS,QAAQ;AAGvB,MAAI,QAAQ;AACV,WAAO,OAAO,UAAU,MAAM,eAAe,KAAK,CAAC;AAA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AA,MACtC;AAEA,UAAI,KAAK,aAAa,KAAK,cAAc;AACvC,YAAI,SAAS,MAAM;AACjB,0BAAgB,UAAU,IAAI;AAAA,QAChC,OAAO;AACL,0BAAgB,mBAAmB,MAAM,WAAW;AAAA,QACtD;AAAA,MACF,OAAO;AACL,iBAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;AAC3C,eAAK,YAAY,YAAY,CAAC,CAAC;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAIO,gBAAS,eAAe,SAAe,aAAiC;AAC7E,MAAI,QAAQ,OAAO,gBAAgB,aAAc,YAAyB,IAAI;AAC9E,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,YAAQ;AAAA,EACV;AAKA,QAAM,gBAAgB,gBAAgB,WAAW,OAAO;AACxD,MAAI,CAAC,iBAAiB,cAAc,aAAa,KAAK,aAAa,gBAAgB,YAAY,aAAa,GAAG;AAC7G,oBAAgB,mBAAmB,SAAS,CAAC,QAAQ,cAAe,eAAe,KAAK,CAAC,CAAC;AAAA,EAC5F,OAAO;AACL;AAAC,IAAC,cAAuB,OAAO;AAAA,EAClC;AACF;", | ||
| "names": [] | ||
| } |
+10
-8
@@ -1,2 +0,3 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { arrayFirst } from "../array"; | ||
@@ -7,7 +8,7 @@ export function domNodeIsContainedBy(node, containedByNode) { | ||
| } | ||
| if (node.nodeType === 11) { | ||
| if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | ||
| return false; | ||
| } | ||
| if (containedByNode.contains) { | ||
| return containedByNode.contains(node.nodeType !== 1 ? node.parentNode : node); | ||
| return containedByNode.contains(node.nodeType !== Node.ELEMENT_NODE ? node.parentNode : node); | ||
| } | ||
@@ -17,6 +18,7 @@ if (containedByNode.compareDocumentPosition) { | ||
| } | ||
| while (node && node != containedByNode) { | ||
| node = node.parentNode; | ||
| let parentNode = node; | ||
| while (parentNode && parentNode != containedByNode) { | ||
| parentNode = parentNode.parentNode; | ||
| } | ||
| return !!node; | ||
| return !!parentNode; | ||
| } | ||
@@ -36,3 +38,3 @@ export function domNodeIsAttachedToDocument(node) { | ||
| } else { | ||
| return obj && obj.tagName && obj.nodeType === 1; | ||
| return obj && obj.tagName && obj.nodeType === Node.ELEMENT_NODE; | ||
| } | ||
@@ -44,4 +46,4 @@ } | ||
| } else { | ||
| return obj && obj.nodeType === 11; | ||
| return obj && obj.nodeType === Node.DOCUMENT_FRAGMENT_NODE; | ||
| } | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/info.ts"], | ||
| "sourcesContent": ["//\n// Information about the DOM\n//\nimport { arrayFirst } from '../array'\n\nexport function domNodeIsContainedBy (node, containedByNode) {\n if (node === containedByNode) { return true }\n if (node.nodeType === 11) { return false } // Fixes issue #1162 - can't use node.contains for document fragments on IE8\n if (containedByNode.contains) { return containedByNode.contains(node.nodeType !== 1 ? node.parentNode : node) }\n if (containedByNode.compareDocumentPosition) { return (containedByNode.compareDocumentPosition(node) & 16) == 16 }\n while (node && node != containedByNode) {\n node = node.parentNode\n }\n return !!node\n}\n\nexport function domNodeIsAttachedToDocument (node) {\n return domNodeIsContainedBy(node, node.ownerDocument.documentElement)\n}\n\nexport function anyDomNodeIsAttachedToDocument (nodes) {\n return !!arrayFirst(nodes, domNodeIsAttachedToDocument)\n}\n\nexport function tagNameLower (element) {\n // For HTML elements, tagName will always be upper case; for XHTML elements, it'll be lower case.\n // Possible future optimization: If we know it's an element from an XHTML document (not HTML),\n // we don't need to do the .toLowerCase() as it will always be lower case anyway.\n return element && element.tagName && element.tagName.toLowerCase()\n}\n\nexport function isDomElement (obj) {\n if (window.HTMLElement) {\n return obj instanceof HTMLElement\n } else {\n return obj && obj.tagName && obj.nodeType === 1\n }\n}\n\nexport function isDocumentFragment (obj) {\n if (window.DocumentFragment) {\n return obj instanceof DocumentFragment\n } else {\n return obj && obj.nodeType === 11\n }\n}\n"], | ||
| "mappings": ";AAGA;AAEO,qCAA+B,MAAM,iBAAiB;AAC3D,MAAI,SAAS,iBAAiB;AAAE,WAAO;AAAA,EAAK;AAC5C,MAAI,KAAK,aAAa,IAAI;AAAE,WAAO;AAAA,EAAM;AACzC,MAAI,gBAAgB,UAAU;AAAE,WAAO,gBAAgB,SAAS,KAAK,aAAa,IAAI,KAAK,aAAa,IAAI;AAAA,EAAE;AAC9G,MAAI,gBAAgB,yBAAyB;AAAE,WAAQ,iBAAgB,wBAAwB,IAAI,IAAI,OAAO;AAAA,EAAG;AACjH,SAAO,QAAQ,QAAQ,iBAAiB;AACtC,WAAO,KAAK;AAAA,EACd;AACA,SAAO,CAAC,CAAC;AACX;AAEO,4CAAsC,MAAM;AACjD,SAAO,qBAAqB,MAAM,KAAK,cAAc,eAAe;AACtE;AAEO,+CAAyC,OAAO;AACrD,SAAO,CAAC,CAAC,WAAW,OAAO,2BAA2B;AACxD;AAEO,6BAAuB,SAAS;AAIrC,SAAO,WAAW,QAAQ,WAAW,QAAQ,QAAQ,YAAY;AACnE;AAEO,6BAAuB,KAAK;AACjC,MAAI,OAAO,aAAa;AACtB,WAAO,eAAe;AAAA,EACxB,OAAO;AACL,WAAO,OAAO,IAAI,WAAW,IAAI,aAAa;AAAA,EAChD;AACF;AAEO,mCAA6B,KAAK;AACvC,MAAI,OAAO,kBAAkB;AAC3B,WAAO,eAAe;AAAA,EACxB,OAAO;AACL,WAAO,OAAO,IAAI,aAAa;AAAA,EACjC;AACF;", | ||
| "sourcesContent": ["//\n// Information about the DOM\n//\nimport { arrayFirst } from '../array'\n\nexport function domNodeIsContainedBy(node: Node, containedByNode: Node) {\n if (node === containedByNode) {\n return true\n }\n if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n return false\n } // Fixes issue #1162 - can't use node.contains for document fragments on IE8\n if (containedByNode.contains) {\n return containedByNode.contains(node.nodeType !== Node.ELEMENT_NODE ? node.parentNode : node)\n }\n if (containedByNode.compareDocumentPosition) {\n return (containedByNode.compareDocumentPosition(node) & 16) == 16\n }\n\n let parentNode: Node | null = node\n while (parentNode && parentNode != containedByNode) {\n parentNode = parentNode.parentNode\n }\n return !!parentNode\n}\n\nexport function domNodeIsAttachedToDocument(node) {\n return domNodeIsContainedBy(node, node.ownerDocument.documentElement)\n}\n\nexport function anyDomNodeIsAttachedToDocument(nodes) {\n return !!arrayFirst(nodes, domNodeIsAttachedToDocument)\n}\n\nexport function tagNameLower(element: Element) {\n // For HTML elements, tagName will always be upper case; for XHTML elements, it'll be lower case.\n // Possible future optimization: If we know it's an element from an XHTML document (not HTML),\n // we don't need to do the .toLowerCase() as it will always be lower case anyway.\n return element && element.tagName && element.tagName.toLowerCase()\n}\n\nexport function isDomElement(obj) {\n if (window.HTMLElement) {\n return obj instanceof HTMLElement\n } else {\n return obj && obj.tagName && obj.nodeType === Node.ELEMENT_NODE\n }\n}\n\nexport function isDocumentFragment(obj) {\n if (window.DocumentFragment) {\n return obj instanceof DocumentFragment\n } else {\n return obj && obj.nodeType === Node.DOCUMENT_FRAGMENT_NODE\n }\n}\n"], | ||
| "mappings": ";;AAGA,SAAS,kBAAkB;AAEpB,gBAAS,qBAAqB,MAAY,iBAAuB;AACtE,MAAI,SAAS,iBAAiB;AAC5B,WAAO;AAAA,EACT;AACA,MAAI,KAAK,aAAa,KAAK,wBAAwB;AACjD,WAAO;AAAA,EACT;AACA,MAAI,gBAAgB,UAAU;AAC5B,WAAO,gBAAgB,SAAS,KAAK,aAAa,KAAK,eAAe,KAAK,aAAa,IAAI;AAAA,EAC9F;AACA,MAAI,gBAAgB,yBAAyB;AAC3C,YAAQ,gBAAgB,wBAAwB,IAAI,IAAI,OAAO;AAAA,EACjE;AAEA,MAAI,aAA0B;AAC9B,SAAO,cAAc,cAAc,iBAAiB;AAClD,iBAAa,WAAW;AAAA,EAC1B;AACA,SAAO,CAAC,CAAC;AACX;AAEO,gBAAS,4BAA4B,MAAM;AAChD,SAAO,qBAAqB,MAAM,KAAK,cAAc,eAAe;AACtE;AAEO,gBAAS,+BAA+B,OAAO;AACpD,SAAO,CAAC,CAAC,WAAW,OAAO,2BAA2B;AACxD;AAEO,gBAAS,aAAa,SAAkB;AAI7C,SAAO,WAAW,QAAQ,WAAW,QAAQ,QAAQ,YAAY;AACnE;AAEO,gBAAS,aAAa,KAAK;AAChC,MAAI,OAAO,aAAa;AACtB,WAAO,eAAe;AAAA,EACxB,OAAO;AACL,WAAO,OAAO,IAAI,WAAW,IAAI,aAAa,KAAK;AAAA,EACrD;AACF;AAEO,gBAAS,mBAAmB,KAAK;AACtC,MAAI,OAAO,kBAAkB;AAC3B,WAAO,eAAe;AAAA,EACxB,OAAO;AACL,WAAO,OAAO,IAAI,aAAa,KAAK;AAAA,EACtC;AACF;", | ||
| "names": [] | ||
| } |
+16
-24
@@ -1,10 +0,10 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { makeArray } from "../array"; | ||
| import { ieVersion } from "../ie"; | ||
| import { cleanNode, removeNode } from "./disposal"; | ||
| export function moveCleanedNodesToContainerElement(nodes) { | ||
| var nodesArray = makeArray(nodes); | ||
| var templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document; | ||
| var container = templateDocument.createElement("div"); | ||
| for (var i = 0, j = nodesArray.length; i < j; i++) { | ||
| const nodesArray = makeArray(nodes); | ||
| const templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document; | ||
| const container = templateDocument.createElement("div"); | ||
| for (let i = 0, j = nodesArray.length; i < j; i++) { | ||
| container.appendChild(cleanNode(nodesArray[i])); | ||
@@ -15,4 +15,5 @@ } | ||
| export function cloneNodes(nodesArray, shouldCleanNodes) { | ||
| for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) { | ||
| var clonedNode = nodesArray[i].cloneNode(true); | ||
| const newNodesArray = new Array(); | ||
| for (let i = 0; i < nodesArray.length; i++) { | ||
| const clonedNode = nodesArray[i].cloneNode(true); | ||
| newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode); | ||
@@ -25,3 +26,3 @@ } | ||
| if (childNodes) { | ||
| for (var i = 0, j = childNodes.length; i < j; i++) { | ||
| for (let i = 0; i < childNodes.length; i++) { | ||
| domNode.appendChild(childNodes[i]); | ||
@@ -32,10 +33,10 @@ } | ||
| export function replaceDomNodes(nodeToReplaceOrNodeArray, newNodesArray) { | ||
| var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray; | ||
| const nodesToReplaceArray = Array.isArray(nodeToReplaceOrNodeArray) ? nodeToReplaceOrNodeArray : [nodeToReplaceOrNodeArray]; | ||
| if (nodesToReplaceArray.length > 0) { | ||
| var insertionPoint = nodesToReplaceArray[0]; | ||
| var parent = insertionPoint.parentNode; | ||
| for (var i = 0, j = newNodesArray.length; i < j; i++) { | ||
| parent.insertBefore(newNodesArray[i], insertionPoint); | ||
| const insertionPoint = nodesToReplaceArray[0]; | ||
| const parent = insertionPoint.parentNode; | ||
| for (let i = 0; i < newNodesArray.length; i++) { | ||
| parent?.insertBefore(newNodesArray[i], insertionPoint); | ||
| } | ||
| for (i = 0, j = nodesToReplaceArray.length; i < j; i++) { | ||
| for (let i = 0; i < nodesToReplaceArray.length; i++) { | ||
| removeNode(nodesToReplaceArray[i]); | ||
@@ -45,11 +46,2 @@ } | ||
| } | ||
| export function setElementName(element, name) { | ||
| element.name = name; | ||
| if (ieVersion <= 7) { | ||
| try { | ||
| element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false); | ||
| } catch (e) { | ||
| } | ||
| } | ||
| } | ||
| export function emptyDomNode(domNode) { | ||
@@ -56,0 +48,0 @@ while (domNode.firstChild) { |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/manipulation.ts"], | ||
| "sourcesContent": ["//\n// DOM manipulation\n//\n/* eslint no-empty: 0 */\nimport { makeArray } from '../array'\nimport { ieVersion } from '../ie'\nimport { cleanNode, removeNode } from './disposal'\n\nexport function moveCleanedNodesToContainerElement (nodes) {\n // Ensure it's a real array, as we're about to reparent the nodes and\n // we don't want the underlying collection to change while we're doing that.\n var nodesArray = makeArray(nodes)\n var templateDocument = (nodesArray[0] && nodesArray[0].ownerDocument) || document\n\n var container = templateDocument.createElement('div')\n for (var i = 0, j = nodesArray.length; i < j; i++) {\n container.appendChild(cleanNode(nodesArray[i]))\n }\n return container\n}\n\nexport function cloneNodes (nodesArray, shouldCleanNodes) {\n for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) {\n var clonedNode = nodesArray[i].cloneNode(true)\n newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode)\n }\n return newNodesArray\n}\n\nexport function setDomNodeChildren (domNode, childNodes) {\n emptyDomNode(domNode)\n if (childNodes) {\n for (var i = 0, j = childNodes.length; i < j; i++) { domNode.appendChild(childNodes[i]) }\n }\n}\n\nexport function replaceDomNodes (nodeToReplaceOrNodeArray, newNodesArray) {\n var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray\n if (nodesToReplaceArray.length > 0) {\n var insertionPoint = nodesToReplaceArray[0]\n var parent = insertionPoint.parentNode\n for (var i = 0, j = newNodesArray.length; i < j; i++) { parent.insertBefore(newNodesArray[i], insertionPoint) }\n for (i = 0, j = nodesToReplaceArray.length; i < j; i++) {\n removeNode(nodesToReplaceArray[i])\n }\n }\n}\n\nexport function setElementName (element, name) {\n element.name = name\n\n // Workaround IE 6/7 issue\n // - https://github.com/SteveSanderson/knockout/issues/197\n // - http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/\n if (ieVersion <= 7) {\n try {\n element.mergeAttributes(document.createElement(\"<input name='\" + element.name + \"'/>\"), false)\n } catch (e) {} // For IE9 with doc mode \"IE9 Standards\" and browser mode \"IE9 Compatibility View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M;AAC7C,UAAQ,OAAO;AAKf,MAAI,aAAa,GAAG;AAClB,QAAI;AACF,cAAQ,gBAAgB,SAAS,cAAc,kBAAkB,QAAQ,OAAO,KAAK,GAAG,KAAK;AAAA,IAC/F,SAAS,GAAP;AAAA,IAAW;AAAA,EACf;AACF;AAEO,6BAAuB,SAAS;AACrC,SAAO,QAAQ,YAAY;AACzB,eAAW,QAAQ,UAAU;AAAA,EAC/B;AACF;", | ||
| "sourcesContent": ["//\n// DOM manipulation\n//\n/* eslint no-empty: 0 */\nimport { makeArray } from '../array'\nimport { cleanNode, removeNode } from './disposal'\n\nexport function moveCleanedNodesToContainerElement(nodes: ArrayLike<Node>) {\n // Ensure it's a real array, as we're about to reparent the nodes and\n // we don't want the underlying collection to change while we're doing that.\n const nodesArray = makeArray(nodes) as Node[]\n const templateDocument = (nodesArray[0] && nodesArray[0].ownerDocument) || document\n\n const container = templateDocument.createElement('div')\n for (let i = 0, j = nodesArray.length; i < j; i++) {\n container.appendChild(cleanNode(nodesArray[i]))\n }\n return container\n}\n\nexport function cloneNodes(nodesArray: ArrayLike<Node>, shouldCleanNodes?: boolean) {\n const newNodesArray = new Array()\n\n for (let i = 0; i < nodesArray.length; i++) {\n const clonedNode = nodesArray[i].cloneNode(true)\n newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode)\n }\n\n return newNodesArray\n}\n\nexport function setDomNodeChildren(domNode: Node, childNodes: ArrayLike<Node>) {\n emptyDomNode(domNode)\n if (childNodes) {\n for (let i = 0; i < childNodes.length; i++) {\n domNode.appendChild(childNodes[i])\n }\n }\n}\n\nexport function replaceDomNodes(nodeToReplaceOrNodeArray: Node[] | Node, newNodesArray: Node[]) {\n const nodesToReplaceArray = Array.isArray(nodeToReplaceOrNodeArray)\n ? nodeToReplaceOrNodeArray\n : [nodeToReplaceOrNodeArray]\n if (nodesToReplaceArray.length > 0) {\n const insertionPoint = nodesToReplaceArray[0]\n const parent = insertionPoint.parentNode\n\n for (let i = 0; i < newNodesArray.length; i++) {\n parent?.insertBefore(newNodesArray[i], insertionPoint)\n }\n for (let i = 0; i < nodesToReplaceArray.length; i++) {\n removeNode(nodesToReplaceArray[i])\n }\n }\n}\n\nexport function emptyDomNode(domNode: Node) {\n while (domNode.firstChild) {\n removeNode(domNode.firstChild)\n }\n}\n"], | ||
| "mappings": ";;AAIA,SAAS,iBAAiB;AAC1B,SAAS,WAAW,kBAAkB;AAE/B,gBAAS,mCAAmC,OAAwB;AAGzE,QAAM,aAAa,UAAU,KAAK;AAClC,QAAM,mBAAoB,WAAW,CAAC,KAAK,WAAW,CAAC,EAAE,iBAAkB;AAE3E,QAAM,YAAY,iBAAiB,cAAc,KAAK;AACtD,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,IAAI,GAAG,KAAK;AACjD,cAAU,YAAY,UAAU,WAAW,CAAC,CAAC,CAAC;AAAA,EAChD;AACA,SAAO;AACT;AAEO,gBAAS,WAAW,YAA6B,kBAA4B;AAClF,QAAM,gBAAgB,IAAI,MAAM;AAEhC,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,UAAM,aAAa,WAAW,CAAC,EAAE,UAAU,IAAI;AAC/C,kBAAc,KAAK,mBAAmB,UAAU,UAAU,IAAI,UAAU;AAAA,EAC1E;AAEA,SAAO;AACT;AAEO,gBAAS,mBAAmB,SAAe,YAA6B;AAC7E,eAAa,OAAO;AACpB,MAAI,YAAY;AACd,aAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,cAAQ,YAAY,WAAW,CAAC,CAAC;AAAA,IACnC;AAAA,EACF;AACF;AAEO,gBAAS,gBAAgB,0BAAyC,eAAuB;AAC9F,QAAM,sBAAsB,MAAM,QAAQ,wBAAwB,IAC9D,2BACA,CAAC,wBAAwB;AAC7B,MAAI,oBAAoB,SAAS,GAAG;AAClC,UAAM,iBAAiB,oBAAoB,CAAC;AAC5C,UAAM,SAAS,eAAe;AAE9B,aAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;AAC7C,cAAQ,aAAa,cAAc,CAAC,GAAG,cAAc;AAAA,IACvD;AACA,aAAS,IAAI,GAAG,IAAI,oBAAoB,QAAQ,KAAK;AACnD,iBAAW,oBAAoB,CAAC,CAAC;AAAA,IACnC;AAAA,EACF;AACF;AAEO,gBAAS,aAAa,SAAe;AAC1C,SAAO,QAAQ,YAAY;AACzB,eAAW,QAAQ,UAAU;AAAA,EAC/B;AACF;", | ||
| "names": [] | ||
| } |
@@ -1,10 +0,11 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { tagNameLower } from "./info"; | ||
| import * as domData from "./data"; | ||
| var hasDomDataExpandoProperty = Symbol("Knockout selectExtensions hasDomDataProperty"); | ||
| export var selectExtensions = { | ||
| const hasDomDataExpandoProperty = /* @__PURE__ */ Symbol("Knockout selectExtensions hasDomDataProperty"); | ||
| export const selectExtensions = { | ||
| optionValueDomDataKey: domData.nextKey(), | ||
| readValue: function(element) { | ||
| switch (tagNameLower(element)) { | ||
| case "option": | ||
| case "option": { | ||
| if (element[hasDomDataExpandoProperty] === true) { | ||
@@ -14,4 +15,7 @@ return domData.get(element, selectExtensions.optionValueDomDataKey); | ||
| return element.value; | ||
| case "select": | ||
| return element.selectedIndex >= 0 ? selectExtensions.readValue(element.options[element.selectedIndex]) : void 0; | ||
| } | ||
| case "select": { | ||
| const selectElement = element; | ||
| return selectElement.selectedIndex >= 0 ? selectExtensions.readValue(selectElement.options[selectElement.selectedIndex]) : void 0; | ||
| } | ||
| default: | ||
@@ -29,27 +33,32 @@ return element.value; | ||
| } | ||
| ; | ||
| element.value = value; | ||
| } else { | ||
| const el = element; | ||
| domData.set(element, selectExtensions.optionValueDomDataKey, value); | ||
| element[hasDomDataExpandoProperty] = true; | ||
| element.value = typeof value === "number" ? value : ""; | ||
| el[hasDomDataExpandoProperty] = true; | ||
| el.value = typeof value === "number" ? value : ""; | ||
| } | ||
| break; | ||
| case "select": | ||
| if (value === "" || value === null) { | ||
| value = void 0; | ||
| } | ||
| var selection = -1; | ||
| for (let i = 0, n = element.options.length, optionValue; i < n; ++i) { | ||
| optionValue = selectExtensions.readValue(element.options[i]); | ||
| const strictEqual = optionValue === value; | ||
| const blankEqual = optionValue === "" && value === void 0; | ||
| const numericEqual = typeof value === "number" && Number(optionValue) === value; | ||
| if (strictEqual || blankEqual || numericEqual) { | ||
| selection = i; | ||
| break; | ||
| { | ||
| if (value === "" || value === null) { | ||
| value = void 0; | ||
| } | ||
| let selection = -1; | ||
| const selectElement = element; | ||
| for (let i = 0, n = selectElement.options.length, optionValue; i < n; ++i) { | ||
| optionValue = selectExtensions.readValue(selectElement.options[i]); | ||
| const strictEqual = optionValue === value; | ||
| const blankEqual = optionValue === "" && value === void 0; | ||
| const numericEqual = typeof value === "number" && Number(optionValue) === value; | ||
| if (strictEqual || blankEqual || numericEqual) { | ||
| selection = i; | ||
| break; | ||
| } | ||
| } | ||
| if (allowUnset || selection >= 0 || value === void 0 && selectElement.size > 1) { | ||
| selectElement.selectedIndex = selection; | ||
| } | ||
| } | ||
| if (allowUnset || selection >= 0 || value === void 0 && element.size > 1) { | ||
| element.selectedIndex = selection; | ||
| } | ||
| break; | ||
@@ -60,2 +69,3 @@ default: | ||
| } | ||
| ; | ||
| element.value = value; | ||
@@ -62,0 +72,0 @@ break; |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/selectExtensions.ts"], | ||
| "sourcesContent": ["\nimport { ieVersion } from '../ie'\nimport { safeSetTimeout } from '../error'\n\nimport { tagNameLower } from './info'\nimport * as domData from './data'\n\nvar hasDomDataExpandoProperty = Symbol('Knockout selectExtensions hasDomDataProperty')\n\n// Normally, SELECT elements and their OPTIONs can only take value of type 'string' (because the values\n// are stored on DOM attributes). ko.selectExtensions provides a way for SELECTs/OPTIONs to have values\n// that are arbitrary objects. This is very convenient when implementing things like cascading dropdowns.\n//\nexport var selectExtensions = {\n optionValueDomDataKey: domData.nextKey(),\n\n readValue: function (element) {\n switch (tagNameLower(element)) {\n case 'option':\n if (element[hasDomDataExpandoProperty] === true) { return domData.get(element, selectExtensions.optionValueDomDataKey) }\n return element.value\n case 'select':\n return element.selectedIndex >= 0 ? selectExtensions.readValue(element.options[element.selectedIndex]) : undefined\n default:\n return element.value\n }\n },\n\n writeValue: function (element, value, allowUnset) {\n switch (tagNameLower(element)) {\n case 'option':\n if (typeof value === 'string') {\n domData.set(element, selectExtensions.optionValueDomDataKey, undefined)\n if (hasDomDataExpandoProperty in element) { // IE <= 8 throws errors if you delete non-existent properties from a DOM node\n delete element[hasDomDataExpandoProperty]\n }\n element.value = value\n } else {\n // Store arbitrary object using DomData\n domData.set(element, selectExtensions.optionValueDomDataKey, value)\n element[hasDomDataExpandoProperty] = true\n // Special treatment of numbers is just for backward compatibility. KO 1.2.1 wrote numerical values to element.value.\n element.value = typeof value === 'number' ? value : ''\n }\n\n break\n case 'select':\n if (value === '' || value === null) {\n // A blank string or null value will select the caption\n value = undefined\n }\n var selection = -1\n for (let i = 0, n = element.options.length, optionValue; i < n; ++i) {\n optionValue = selectExtensions.readValue(element.options[i])\n // Include special check to handle selecting a caption with a blank string value\n // Note that the looser == check here is intentional so that integer model values will match string element values.\n const strictEqual = optionValue === value\n const blankEqual = optionValue === '' && value === undefined\n const numericEqual = typeof value === 'number' && Number(optionValue) === value\n if (strictEqual || blankEqual || numericEqual) {\n selection = i\n break\n }\n }\n if (allowUnset || selection >= 0 || (value === undefined && element.size > 1)) {\n element.selectedIndex = selection\n }\n break\n default:\n if ((value === null) || (value === undefined)) { value = '' }\n element.value = value\n break\n }\n }\n}\n"], | ||
| "mappings": ";AAIA;AACA;AAEA,IAAI,4BAA4B,OAAO,8CAA8C;AAM9E,WAAI,mBAAmB;AAAA,EAC5B,uBAAuB,QAAQ,QAAQ;AAAA,EAEvC,WAAW,SAAU,SAAS;AAC5B,YAAQ,aAAa,OAAO;AAAA,WACrB;A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C5D,gBAAQ,QAAQ;AAChB;AAAA;AAAA,EAEN;AACF;", | ||
| "sourcesContent": ["import { tagNameLower } from './info'\nimport * as domData from './data'\n\nconst hasDomDataExpandoProperty = Symbol('Knockout selectExtensions hasDomDataProperty')\n\n// Normally, SELECT elements and their OPTIONs can only take value of type 'string' (because the values\n// are stored on DOM attributes). ko.selectExtensions provides a way for SELECTs/OPTIONs to have values\n// that are arbitrary objects. This is very convenient when implementing things like cascading dropdowns.\n//\nexport const selectExtensions = {\n optionValueDomDataKey: domData.nextKey(),\n\n readValue: function (element: HTMLElement) {\n switch (tagNameLower(element)) {\n case 'option': {\n if (element[hasDomDataExpandoProperty] === true) {\n return domData.get(element, selectExtensions.optionValueDomDataKey)\n }\n return (element as HTMLOptionElement).value\n }\n case 'select': {\n const selectElement = element as HTMLSelectElement\n return selectElement.selectedIndex >= 0\n ? selectExtensions.readValue(selectElement.options[selectElement.selectedIndex])\n : undefined\n }\n default:\n return (element as HTMLInputElement).value\n }\n },\n\n writeValue: function (element: HTMLElement, value?: any, allowUnset?: boolean) {\n switch (tagNameLower(element)) {\n case 'option':\n if (typeof value === 'string') {\n domData.set(element, selectExtensions.optionValueDomDataKey, undefined)\n if (hasDomDataExpandoProperty in element) {\n // IE <= 8 throws errors if you delete non-existent properties from a DOM node\n delete element[hasDomDataExpandoProperty]\n }\n ;(element as HTMLOptionElement).value = value\n } else {\n const el = element as any //TODO Custom-Type with hasDomDataExpandoProperty\n // Store arbitrary object using DomData\n domData.set(element, selectExtensions.optionValueDomDataKey, value)\n el[hasDomDataExpandoProperty] = true\n // Special treatment of numbers is just for backward compatibility. KO 1.2.1 wrote numerical values to element.value.\n el.value = typeof value === 'number' ? value : ''\n }\n\n break\n case 'select':\n {\n if (value === '' || value === null) {\n // A blank string or null value will select the caption\n value = undefined\n }\n let selection = -1\n\n const selectElement = element as HTMLSelectElement\n\n for (let i = 0, n = selectElement.options.length, optionValue; i < n; ++i) {\n optionValue = selectExtensions.readValue(selectElement.options[i])\n // Include special check to handle selecting a caption with a blank string value\n // Note that the looser == check here is intentional so that integer model values will match string element values.\n const strictEqual = optionValue === value\n const blankEqual = optionValue === '' && value === undefined\n const numericEqual = typeof value === 'number' && Number(optionValue) === value\n if (strictEqual || blankEqual || numericEqual) {\n selection = i\n break\n }\n }\n if (allowUnset || selection >= 0 || (value === undefined && selectElement.size > 1)) {\n selectElement.selectedIndex = selection\n }\n }\n break\n default:\n if (value === null || value === undefined) {\n value = ''\n }\n ;(element as HTMLInputElement).value = value\n break\n }\n }\n}\n"], | ||
| "mappings": ";;AAAA,SAAS,oBAAoB;AAC7B,YAAY,aAAa;AAEzB,MAAM,4BAA4B,uBAAO,8CAA8C;AAMhF,aAAM,mBAAmB;AAAA,EAC9B,uBAAuB,QAAQ,QAAQ;AAAA,EAEvC,WAAW,SAAU,SAAsB;AACzC,YAAQ,aAAa,OAAO,GAAG;AAAA,MAC7B,KAAK,UAAU;AACb,YAAI,QAAQ,yBAAyB,MAAM,MAAM;AAC/C,iBAAO,QAAQ,IAAI,SAAS,iBAAiB,qBAAqB;AAAA,QACpE;AACA,eAAQ,QAA8B;AAAA,MACxC;AAAA,MACA,KAAK,UAAU;AACb,cAAM,gBAAgB;AACtB,eAAO,cAAc,iBAAiB,IAClC,iBAAiB,UAAU,cAAc,QAAQ,cAAc,aAAa,CAAC,IAC7E;AAAA,MACN;AAAA,MACA;AACE,eAAQ,QAA6B;AAAA,IACzC;AAAA,EACF;AAAA,EAEA,YAAY,SAAU,SAAsB,OAAa,YAAsB;AAC7E,YAAQ,aAAa,OAAO,GAAG;AAAA,MAC7B,KAAK;AACH,YAAI,OAAO,UAAU,UAAU;AAC7B,kBAAQ,IAAI,SAAS,iBAAiB,uBAAuB,MAAS;AACtE,cAAI,6BAA6B,SAAS;AAExC,mBAAO,QAAQ,yBAAyB;AAAA,UAC1C;AACA;AAAC,UAAC,QAA8B,QAAQ;AAAA,QAC1C,OAAO;AACL,gBAAM,KAAK;AAEX,kBAAQ,IAAI,SAAS,iBAAiB,uBAAuB,KAAK;AAClE,aAAG,yBAAyB,IAAI;AAEhC,aAAG,QAAQ,OAAO,UAAU,WAAW,QAAQ;AAAA,QACjD;AAEA;AAAA,MACF,KAAK;AACH;AACE,cAAI,UAAU,MAAM,UAAU,MAAM;AAElC,oBAAQ;AAAA,UACV;AACA,cAAI,YAAY;AAEhB,gBAAM,gBAAgB;AAEtB,mBAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,QAAQ,aAAa,IAAI,GAAG,EAAE,GAAG;AACzE,0BAAc,iBAAiB,UAAU,cAAc,QAAQ,CAAC,CAAC;AAGjE,kBAAM,cAAc,gBAAgB;AACpC,kBAAM,aAAa,gBAAgB,MAAM,UAAU;AACnD,kBAAM,eAAe,OAAO,UAAU,YAAY,OAAO,WAAW,MAAM;AAC1E,gBAAI,eAAe,cAAc,cAAc;AAC7C,0BAAY;AACZ;AAAA,YACF;AAAA,UACF;AACA,cAAI,cAAc,aAAa,KAAM,UAAU,UAAa,cAAc,OAAO,GAAI;AACnF,0BAAc,gBAAgB;AAAA,UAChC;AAAA,QACF;AACA;AAAA,MACF;AACE,YAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,kBAAQ;AAAA,QACV;AACA;AAAC,QAAC,QAA6B,QAAQ;AACvC;AAAA,IACJ;AAAA,EACF;AACF;", | ||
| "names": [] | ||
| } |
@@ -1,2 +0,3 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { emptyDomNode, setDomNodeChildren as setRegularDomNodeChildren } from "./manipulation"; | ||
@@ -6,12 +7,10 @@ import { removeNode } from "./disposal"; | ||
| import * as domData from "./data"; | ||
| import options from "../options"; | ||
| var commentNodesHaveTextProperty = options.document && options.document.createComment("test").text === "<!--test-->"; | ||
| export var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+([\s\S]+))?\s*-->$/ : /^\s*ko(?:\s+([\s\S]+))?\s*$/; | ||
| export var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/; | ||
| var htmlTagsWithOptionallyClosingChildren = { "ul": true, "ol": true }; | ||
| export const startCommentRegex = /^\s*ko(?:\s+([\s\S]+))?\s*$/; | ||
| export const endCommentRegex = /^\s*\/ko\s*$/; | ||
| const htmlTagsWithOptionallyClosingChildren = { ul: true, ol: true }; | ||
| export function isStartComment(node) { | ||
| return node.nodeType == 8 && startCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue); | ||
| return node.nodeType === Node.COMMENT_NODE && startCommentRegex.test(node.nodeValue); | ||
| } | ||
| export function isEndComment(node) { | ||
| return node.nodeType == 8 && endCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue); | ||
| return node.nodeType === Node.COMMENT_NODE && endCommentRegex.test(node.nodeValue); | ||
| } | ||
@@ -23,5 +22,5 @@ function isUnmatchedEndComment(node) { | ||
| export function getVirtualChildren(startComment, allowUnbalanced) { | ||
| var currentNode = startComment; | ||
| var depth = 1; | ||
| var children = []; | ||
| let currentNode = startComment; | ||
| let depth = 1; | ||
| const children = new Array(); | ||
| while (currentNode = currentNode.nextSibling) { | ||
@@ -46,3 +45,3 @@ if (isEndComment(currentNode)) { | ||
| function getMatchingEndComment(startComment, allowUnbalanced) { | ||
| var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced); | ||
| const allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced); | ||
| if (allVirtualChildren) { | ||
@@ -58,3 +57,3 @@ if (allVirtualChildren.length > 0) { | ||
| function getUnbalancedChildTags(node) { | ||
| var childNode = node.firstChild, captureRemaining = null; | ||
| let childNode = node.firstChild, captureRemaining = null; | ||
| if (childNode) { | ||
@@ -65,3 +64,7 @@ do { | ||
| } else if (isStartComment(childNode)) { | ||
| var matchingEndComment = getMatchingEndComment(childNode, true); | ||
| const matchingEndComment = getMatchingEndComment( | ||
| childNode, | ||
| /* allowUnbalanced: */ | ||
| true | ||
| ); | ||
| if (matchingEndComment) { | ||
@@ -79,4 +82,4 @@ childNode = matchingEndComment; | ||
| } | ||
| export var allowedBindings = {}; | ||
| export var hasBindingValue = isStartComment; | ||
| export const allowedBindings = /* @__PURE__ */ Object.create(null); | ||
| export const hasBindingValue = isStartComment; | ||
| export function childNodes(node) { | ||
@@ -89,4 +92,4 @@ return isStartComment(node) ? getVirtualChildren(node) : node.childNodes; | ||
| } else { | ||
| var virtualChildren = childNodes(node); | ||
| for (var i = 0, j = virtualChildren.length; i < j; i++) { | ||
| const virtualChildren = childNodes(node); | ||
| for (let i = 0, j = virtualChildren.length; i < j; i++) { | ||
| removeNode(virtualChildren[i]); | ||
@@ -102,5 +105,7 @@ } | ||
| const endCommentNode = node.nextSibling; | ||
| const parentNode = endCommentNode.parentNode; | ||
| for (var i = 0, j = childNodes2.length; i < j; ++i) { | ||
| parentNode.insertBefore(childNodes2[i], endCommentNode); | ||
| if (endCommentNode && endCommentNode.parentNode) { | ||
| const parentNode = endCommentNode.parentNode; | ||
| for (let i = 0, j = childNodes2.length; i < j; ++i) { | ||
| parentNode.insertBefore(childNodes2[i], endCommentNode); | ||
| } | ||
| } | ||
@@ -117,3 +122,3 @@ } | ||
| } else { | ||
| containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling); | ||
| containerNode.parentNode?.insertBefore(nodeToPrepend, containerNode.nextSibling); | ||
| } | ||
@@ -131,3 +136,3 @@ } | ||
| } else { | ||
| containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling); | ||
| containerNode.parentNode?.insertBefore(nodeToInsert, insertAfterNode.nextSibling); | ||
| } | ||
@@ -149,2 +154,3 @@ } | ||
| let nextChild = firstChild(node); | ||
| if (!nextChild) return null; | ||
| let lastChildNode; | ||
@@ -162,3 +168,5 @@ do { | ||
| if (isUnmatchedEndComment(node.nextSibling)) { | ||
| throw Error("Found end comment without a matching opening comment, as next sibling of " + node.outerHTML); | ||
| throw Error( | ||
| "Found end comment without a matching opening comment, as next sibling of " + node.outerHTML | ||
| ); | ||
| } | ||
@@ -171,5 +179,5 @@ return null; | ||
| export function previousSibling(node) { | ||
| var depth = 0; | ||
| let depth = 0; | ||
| do { | ||
| if (node.nodeType === 8) { | ||
| if (node.nodeType === Node.COMMENT_NODE) { | ||
| if (isStartComment(node)) { | ||
@@ -190,3 +198,3 @@ if (--depth === 0) { | ||
| export function virtualNodeBindingValue(node) { | ||
| var regexMatch = (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex); | ||
| const regexMatch = node.nodeValue.match(startCommentRegex); | ||
| return regexMatch ? regexMatch[1] : null; | ||
@@ -198,10 +206,10 @@ } | ||
| } | ||
| var childNode = elementVerified.firstChild; | ||
| let childNode = elementVerified.firstChild; | ||
| if (childNode) { | ||
| do { | ||
| if (childNode.nodeType === 1) { | ||
| var unbalancedTags = getUnbalancedChildTags(childNode); | ||
| if (childNode.nodeType === Node.ELEMENT_NODE) { | ||
| const unbalancedTags = getUnbalancedChildTags(childNode); | ||
| if (unbalancedTags) { | ||
| var nodeToInsertBefore = childNode.nextSibling; | ||
| for (var i = 0; i < unbalancedTags.length; i++) { | ||
| const nodeToInsertBefore = childNode.nextSibling; | ||
| for (let i = 0; i < unbalancedTags.length; i++) { | ||
| if (nodeToInsertBefore) { | ||
@@ -208,0 +216,0 @@ elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore); |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/dom/virtualElements.ts"], | ||
| "sourcesContent": ["/* eslint no-cond-assign: 0 */\n//\n// Virtual Elements\n//\n//\n// \"Virtual elements\" is an abstraction on top of the usual DOM API which understands the notion that comment nodes\n// may be used to represent hierarchy (in addition to the DOM's natural hierarchy).\n// If you call the DOM-manipulating functions on ko.virtualElements, you will be able to read and write the state\n// of that virtual hierarchy\n//\n// The point of all this is to support containerless templates (e.g., <!-- ko foreach:someCollection -->blah<!-- /ko -->)\n// without having to scatter special cases all over the binding and templating code.\n\n// IE 9 cannot reliably read the \"nodeValue\" property of a comment node (see https://github.com/SteveSanderson/knockout/issues/186)\n// but it does give them a nonstandard alternative property called \"text\" that it can read reliably. Other browsers don't have that property.\n// So, use node.text where available, and node.nodeValue elsewhere\nimport { emptyDomNode, setDomNodeChildren as setRegularDomNodeChildren } from './manipulation'\nimport { removeNode } from './disposal'\nimport { tagNameLower } from './info'\nimport * as domData from './data'\nimport options from '../options'\n\nvar commentNodesHaveTextProperty = options.document && options.document.createComment('test').text === '<!--test-->'\n\nexport var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\\s*ko(?:\\s+([\\s\\S]+))?\\s*-->$/ : /^\\s*ko(?:\\s+([\\s\\S]+))?\\s*$/\nexport var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\\s*\\/ko\\s*-->$/ : /^\\s*\\/ko\\s*$/\nvar htmlTagsWithOptionallyClosingChildren = { 'ul': true, 'ol': true }\n\nexport function isStartComment (node) {\n return (node.nodeType == 8) && startCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue)\n}\n\nexport function isEndComment (node) {\n return (node.nodeType == 8) && endCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue)\n}\n\nfunction isUnmatchedEndComment (node) {\n return isEndComment(node) && !domData.get(node, matchedEndCommentDataKey)\n}\n\nconst matchedEndCommentDataKey = '__ko_matchedEndComment__'\n\nexport function getVirtualChildren (startComment, allowUnbalanced) {\n var currentNode = startComment\n var depth = 1\n var children = []\n while (currentNode = currentNode.nextSibling) {\n if (isEndComment(currentNode)) {\n domData.set(currentNode, matchedEndCommentDataKey, true)\n depth--\n if (depth === 0) { return children }\n }\n\n children.push(currentNode)\n\n if (isStartComment(currentNode)) { depth++ }\n }\n if (!allowUnbalanced) { throw new Error('Cannot find closing comment tag to match: ' + startComment.nodeValue) }\n return null\n}\n\nfunction getMatchingEndComment (startComment, allowUnbalanced) {\n var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced)\n if (allVirtualChildren) {\n if (allVirtualChildren.length > 0) { return allVirtualChildren[allVirtualChildren.length - 1].nextSibling }\n return startComment.nextSibling\n } else { return null } // Must have no matching end comment, and allowUnbalanced is true\n}\n\nfunction getUnbalancedChildTags (node) {\n // e.g., from <div>OK</div><!-- ko blah --><span>Another</span>, returns: <!-- ko blah --><span>Another</span>\n // from <div>OK</div><!-- /ko --><!-- /ko -->, returns: <!-- /ko --><!-- /ko -->\n var childNode = node.firstChild, captureRemaining = null\n if (childNode) {\n do {\n if (captureRemaining) // We already hit an unbalanced node and are now just scooping up all subsequent nodes\n { captureRemaining.push(childNode) } else if (isStartComment(childNode)) {\n var matchingEndComment = getMatchingEndComment(childNode, /* allowUnbalanced: */ true)\n if (matchingEndComment) // It's a balanced tag, so skip immediately to the end of this virtual set\n { childNode = matchingEndComment } else { captureRemaining = [childNode] } // It's unbalanced, so start capturing from this point\n } else if (isEndComment(childNode)) {\n captureRemaining = [childNode] // It's unbalanced (if it wasn't, we'd have skipped over it already), so start capturing\n }\n } while (childNode = childNode.nextSibling)\n }\n return captureRemaining\n}\n\nexport var allowedBindings = {}\nexport var hasBindingValue = isStartComment\n\nexport function childNodes (node) {\n return isStartComment(node) ? getVirtualChildren(node) : node.childNodes\n}\n\nexport function emptyNode (node) {\n if (!isStartComment(node)) { emptyDomNode(node) } else {\n var virtualChildren = childNodes(node)\n for (var i = 0, j = virtualChildren.length; i < j; i++) { removeNode(virtualChildren[i]) }\n }\n}\n\nexport function setDomNodeChildren (node, childNodes) {\n if (!isStartComment(node)) { setRegularDomNodeChildren(node, childNodes) } else {\n emptyNode(node)\n const endCommentNode = node.nextSibling // Must be the next sibling, as we just emptied the children\n const parentNode = endCommentNode.parentNode\n for (var i = 0, j = childNodes.length; i < j; ++i) {\n parentNode.insertBefore(childNodes[i], endCommentNode)\n }\n }\n}\n\nexport function prepend (containerNode, nodeToPrepend) {\n if (!isStartComment(containerNode)) {\n if (containerNode.firstChild) { containerNode.insertBefore(nodeToPrepend, containerNode.firstChild) } else { containerNode.appendChild(nodeToPrepend) }\n } else {\n // Start comments must always have a parent and at least one following sibling (the end comment)\n containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling)\n }\n}\n\nexport function insertAfter (containerNode, nodeToInsert, insertAfterNode) {\n if (!insertAfterNode) {\n prepend(containerNode, nodeToInsert)\n } else if (!isStartComment(containerNode)) {\n // Insert after insertion point\n if (insertAfterNode.nextSibling) { containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling) } else { containerNode.appendChild(nodeToInsert) }\n } else {\n // Children of start comments must always have a parent and at least one following sibling (the end comment)\n containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling)\n }\n}\n\nexport function firstChild (node) {\n if (!isStartComment(node)) {\n if (node.firstChild && isEndComment(node.firstChild)) {\n throw new Error('Found invalid end comment, as the first child of ' + node.outerHTML)\n }\n return node.firstChild\n }\n if (!node.nextSibling || isEndComment(node.nextSibling)) {\n return null\n }\n return node.nextSibling\n}\n\nexport function lastChild (node) {\n let nextChild = firstChild(node)\n let lastChildNode\n\n do {\n lastChildNode = nextChild\n } while (nextChild = nextSibling(nextChild))\n\n return lastChildNode\n}\n\nexport function nextSibling (node) {\n if (isStartComment(node)) {\n node = getMatchingEndComment(node)\n }\n\n if (node.nextSibling && isEndComment(node.nextSibling)) {\n if (isUnmatchedEndComment(node.nextSibling)) {\n throw Error('Found end comment without a matching opening comment, as next sibling of ' + node.outerHTML)\n }\n return null\n } else {\n return node.nextSibling\n }\n}\n\nexport function previousSibling (node) {\n var depth = 0\n do {\n if (node.nodeType === 8) {\n if (isStartComment(node)) {\n if (--depth === 0) {\n return node\n }\n } else if (isEndComment(node)) {\n depth++\n }\n } else {\n if (depth === 0) { return node }\n }\n } while (node = node.previousSibling)\n}\n\nexport function virtualNodeBindingValue (node) {\n var regexMatch = (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex)\n return regexMatch ? regexMatch[1] : null\n}\n\nexport function normaliseVirtualElementDomStructure (elementVerified) {\n // Workaround for https://github.com/SteveSanderson/knockout/issues/155\n // (IE <= 8 or IE 9 quirks mode parses your HTML weirdly, treating closing </li> tags as if they don't exist, thereby moving comment nodes\n // that are direct descendants of <ul> into the preceding <li>)\n if (!htmlTagsWithOptionallyClosingChildren[tagNameLower(elementVerified)]) { return }\n\n // Scan immediate children to see if they contain unbalanced comment tags. If they do, those comment tags\n // must be intended to appear *after* that child, so move them there.\n var childNode = elementVerified.firstChild\n if (childNode) {\n do {\n if (childNode.nodeType === 1) {\n var unbalancedTags = getUnbalancedChildTags(childNode)\n if (unbalancedTags) {\n // Fix up the DOM by moving the unbalanced tags to where they most likely were intended to be placed - *after* the child\n var nodeToInsertBefore = childNode.nextSibling\n for (var i = 0; i < unbalancedTags.length; i++) {\n if (nodeToInsertBefore) { elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore) } else { elementVerified.appendChild(unbalancedTags[i]) }\n }\n }\n }\n } while (childNode = childNode.nextSibling)\n }\n}\n"], | ||
| "mappings": ";AAgBA;AACA;AACA;AACA;AACA;AAEA,IAAI,+BAA+B,QAAQ,YAAY,QAAQ,SAAS,cAAc,MAAM,EAAE,SAAS;AAEhG,WAAI,oBAAoB,+BAA+B,uCAAuC;AAC9F,WAAI,kBAAkB,+BAA+B,wBAAwB;AACpF,IAAI,wCAAwC,EAAE,MAAM,MAAM,MAAM,KAAK;AAE9D,+BAAyB,MAAM;AACpC,SAAQ,KAAK,YAAY,KAAM,kBAAkB,KAAK,+BAA+B,KAAK,OAAO,KAAK,SAAS;AACjH;AAEO,6BAAuB,MAAM;AAClC,SAAQ,KAAK,YAAY,KAAM,gBAAgB,KAAK,+BAA+B,KAAK,OAAO,KAAK,SAAS;AAC/G;AAEA,+BAAgC,MAAM;AACpC,SAAO,aAAa,IAAI,KAAK,CAAC,QAAQ,IAAI,MAAM,wBAAwB;AAC1E;AAEA,MAAM,2BAA2B;AAE1B,mCAA6B,cAAc,iBAAiB;AACjE,MA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,aAAa,GAAG;AAC5B,YAAI,iBAAiB,uBAAuB,SAAS;AACrD,YAAI,gBAAgB;AAElB,cAAI,qBAAqB,UAAU;AACnC,mBAAS,IAAI,GAAG,IAAI,eAAe,QAAQ,KAAK;AAC9C,gBAAI,oBAAoB;AAAE,8BAAgB,aAAa,eAAe,IAAI,kBAAkB;AAAA,YAAE,OAAO;AAAE,8BAAgB,YAAY,eAAe,EAAE;AAAA,YAAE;AAAA,UACxJ;AAAA,QACF;AAAA,MACF;AAAA,IACF,SAAS,YAAY,UAAU;AAAA,EACjC;AACF;", | ||
| "names": [] | ||
| "sourcesContent": ["/* eslint no-cond-assign: 0 */\n//\n// Virtual Elements\n//\n//\n// \"Virtual elements\" is an abstraction on top of the usual DOM API which understands the notion that comment nodes\n// may be used to represent hierarchy (in addition to the DOM's natural hierarchy).\n// If you call the DOM-manipulating functions on ko.virtualElements, you will be able to read and write the state\n// of that virtual hierarchy\n//\n// The point of all this is to support containerless templates (e.g., <!-- ko foreach:someCollection -->blah<!-- /ko -->)\n// without having to scatter special cases all over the binding and templating code.\n\nimport { emptyDomNode, setDomNodeChildren as setRegularDomNodeChildren } from './manipulation'\nimport { removeNode } from './disposal'\nimport { tagNameLower } from './info'\nimport * as domData from './data'\nimport options from '../options'\n\nexport const startCommentRegex = /^\\s*ko(?:\\s+([\\s\\S]+))?\\s*$/\nexport const endCommentRegex = /^\\s*\\/ko\\s*$/\nconst htmlTagsWithOptionallyClosingChildren = { ul: true, ol: true }\n\nexport function isStartComment(node) {\n return node.nodeType === Node.COMMENT_NODE && startCommentRegex.test(node.nodeValue)\n}\n\nexport function isEndComment(node) {\n return node.nodeType === Node.COMMENT_NODE && endCommentRegex.test(node.nodeValue)\n}\n\nfunction isUnmatchedEndComment(node) {\n return isEndComment(node) && !domData.get(node, matchedEndCommentDataKey)\n}\n\nconst matchedEndCommentDataKey = '__ko_matchedEndComment__'\n\nexport function getVirtualChildren(startComment, allowUnbalanced?) {\n let currentNode = startComment\n let depth = 1\n const children = new Array()\n while ((currentNode = currentNode.nextSibling)) {\n if (isEndComment(currentNode)) {\n domData.set(currentNode, matchedEndCommentDataKey, true)\n depth--\n if (depth === 0) {\n return children\n }\n }\n\n children.push(currentNode)\n\n if (isStartComment(currentNode)) {\n depth++\n }\n }\n if (!allowUnbalanced) {\n throw new Error('Cannot find closing comment tag to match: ' + startComment.nodeValue)\n }\n return null\n}\n\nfunction getMatchingEndComment(startComment, allowUnbalanced?) {\n const allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced)\n if (allVirtualChildren) {\n if (allVirtualChildren.length > 0) {\n return allVirtualChildren[allVirtualChildren.length - 1].nextSibling\n }\n return startComment.nextSibling\n } else {\n return null\n } // Must have no matching end comment, and allowUnbalanced is true\n}\n\nfunction getUnbalancedChildTags(node) {\n // e.g., from <div>OK</div><!-- ko blah --><span>Another</span>, returns: <!-- ko blah --><span>Another</span>\n // from <div>OK</div><!-- /ko --><!-- /ko -->, returns: <!-- /ko --><!-- /ko -->\n let childNode = node.firstChild,\n captureRemaining: any = null\n if (childNode) {\n do {\n if (captureRemaining) // We already hit an unbalanced node and are now just scooping up all subsequent nodes\n {\n captureRemaining.push(childNode)\n } else if (isStartComment(childNode)) {\n const matchingEndComment = getMatchingEndComment(childNode, /* allowUnbalanced: */ true)\n if (matchingEndComment) // It's a balanced tag, so skip immediately to the end of this virtual set\n {\n childNode = matchingEndComment\n } else {\n captureRemaining = [childNode]\n } // It's unbalanced, so start capturing from this point\n } else if (isEndComment(childNode)) {\n captureRemaining = [childNode] // It's unbalanced (if it wasn't, we'd have skipped over it already), so start capturing\n }\n } while ((childNode = childNode.nextSibling))\n }\n return captureRemaining\n}\n\nexport interface VirtualElementsAllowedBindings {\n text: boolean\n foreach: boolean\n if: boolean\n ifnot: boolean\n with: boolean\n let: boolean\n using: boolean\n template: boolean\n component: boolean\n}\n\nexport const allowedBindings: VirtualElementsAllowedBindings = Object.create(null)\nexport const hasBindingValue = isStartComment\n\nexport function childNodes(node: Node): any {\n return isStartComment(node) ? getVirtualChildren(node) : node.childNodes\n}\n\nexport function emptyNode(node: Node) {\n if (!isStartComment(node)) {\n emptyDomNode(node)\n } else {\n const virtualChildren = childNodes(node)\n for (let i = 0, j = virtualChildren.length; i < j; i++) {\n removeNode(virtualChildren[i])\n }\n }\n}\n\nexport function setDomNodeChildren(node: Node, childNodes: Node[]) {\n if (!isStartComment(node)) {\n setRegularDomNodeChildren(node, childNodes)\n } else {\n emptyNode(node)\n const endCommentNode = node.nextSibling // Must be the next sibling, as we just emptied the children\n if (endCommentNode && endCommentNode.parentNode) {\n const parentNode = endCommentNode.parentNode\n for (let i = 0, j = childNodes.length; i < j; ++i) {\n parentNode.insertBefore(childNodes[i], endCommentNode)\n }\n }\n }\n}\n\nexport function prepend(containerNode: Node, nodeToPrepend: Node) {\n if (!isStartComment(containerNode)) {\n if (containerNode.firstChild) {\n containerNode.insertBefore(nodeToPrepend, containerNode.firstChild)\n } else {\n containerNode.appendChild(nodeToPrepend)\n }\n } else {\n // Start comments must always have a parent and at least one following sibling (the end comment)\n containerNode.parentNode?.insertBefore(nodeToPrepend, containerNode.nextSibling)\n }\n}\n\nexport function insertAfter(containerNode: Node, nodeToInsert: Node, insertAfterNode: Node) {\n if (!insertAfterNode) {\n prepend(containerNode, nodeToInsert)\n } else if (!isStartComment(containerNode)) {\n // Insert after insertion point\n if (insertAfterNode.nextSibling) {\n containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling)\n } else {\n containerNode.appendChild(nodeToInsert)\n }\n } else {\n // Children of start comments must always have a parent and at least one following sibling (the end comment)\n containerNode.parentNode?.insertBefore(nodeToInsert, insertAfterNode.nextSibling)\n }\n}\n\nexport function firstChild(node: Node) {\n if (!isStartComment(node)) {\n if (node.firstChild && isEndComment(node.firstChild)) {\n throw new Error('Found invalid end comment, as the first child of ' + (node as Element).outerHTML)\n }\n return node.firstChild\n }\n if (!node.nextSibling || isEndComment(node.nextSibling)) {\n return null\n }\n return node.nextSibling\n}\n\nexport function lastChild(node: Node) {\n let nextChild = firstChild(node)\n if (!nextChild) return null\n\n let lastChildNode\n\n do {\n lastChildNode = nextChild\n } while ((nextChild = nextSibling(nextChild)))\n\n return lastChildNode\n}\n\nexport function nextSibling(node: Node) {\n if (isStartComment(node)) {\n node = getMatchingEndComment(node)\n }\n\n if (node.nextSibling && isEndComment(node.nextSibling)) {\n if (isUnmatchedEndComment(node.nextSibling)) {\n throw Error(\n 'Found end comment without a matching opening comment, as next sibling of ' + (node as Element).outerHTML\n )\n }\n return null\n } else {\n return node.nextSibling\n }\n}\n\nexport function previousSibling(node) {\n let depth = 0\n do {\n if (node.nodeType === Node.COMMENT_NODE) {\n if (isStartComment(node)) {\n if (--depth === 0) {\n return node\n }\n } else if (isEndComment(node)) {\n depth++\n }\n } else {\n if (depth === 0) {\n return node\n }\n }\n } while ((node = node.previousSibling))\n}\n\nexport function virtualNodeBindingValue(node): string | null {\n const regexMatch = node.nodeValue.match(startCommentRegex) as RegExpMatchArray\n return regexMatch ? regexMatch[1] : null\n}\n\nexport function normaliseVirtualElementDomStructure(elementVerified) {\n // Workaround for https://github.com/SteveSanderson/knockout/issues/155\n // (IE <= 8 or IE 9 quirks mode parses your HTML weirdly, treating closing </li> tags as if they don't exist, thereby moving comment nodes\n // that are direct descendants of <ul> into the preceding <li>)\n if (!htmlTagsWithOptionallyClosingChildren[tagNameLower(elementVerified)]) {\n return\n }\n\n // Scan immediate children to see if they contain unbalanced comment tags. If they do, those comment tags\n // must be intended to appear *after* that child, so move them there.\n let childNode = elementVerified.firstChild\n if (childNode) {\n do {\n if (childNode.nodeType === Node.ELEMENT_NODE) {\n const unbalancedTags = getUnbalancedChildTags(childNode)\n if (unbalancedTags) {\n // Fix up the DOM by moving the unbalanced tags to where they most likely were intended to be placed - *after* the child\n const nodeToInsertBefore = childNode.nextSibling\n for (let i = 0; i < unbalancedTags.length; i++) {\n if (nodeToInsertBefore) {\n elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore)\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"names": ["childNodes"] | ||
| } |
+2
-1
@@ -1,2 +0,3 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import options from "./options"; | ||
@@ -3,0 +4,0 @@ export function catchFunctionErrors(delegate) { |
| { | ||
| "version": 3, | ||
| "sources": ["../src/error.ts"], | ||
| "sourcesContent": ["//\n// Error handling\n// ---\n//\n// The default onError handler is to re-throw.\nimport options from './options'\n\nexport function catchFunctionErrors (delegate) {\n if (!options.onError) { return delegate }\n return (...args) => {\n try {\n return delegate(...args)\n } catch (err) {\n options.onError(err)\n }\n }\n}\n\nexport function deferError (error) {\n safeSetTimeout(function () { throw error }, 0)\n}\n\nexport function safeSetTimeout (handler, timeout) {\n return setTimeout(catchFunctionErrors(handler), timeout)\n}\n"], | ||
| "mappings": ";AAKA;AAEO,oCAA8B,UAAU;AAC7C,MAAI,CAAC,QAAQ,SAAS;AAAE,WAAO;AAAA,EAAS;AACxC,SAAO,IAAI,SAAS;AAClB,QAAI;AACF,aAAO,SAAS,GAAG,IAAI;AAAA,IACzB,SAAS,KAAP;AACA,cAAQ,QAAQ,GAAG;AAAA,IACrB;AAAA,EACF;AACF;AAEO,2BAAqB,OAAO;AACjC,iBAAe,WAAY;AAAE,UAAM;AAAA,EAAM,GAAG,CAAC;AAC/C;AAEO,+BAAyB,SAAS,SAAS;AAChD,SAAO,WAAW,oBAAoB,OAAO,GAAG,OAAO;AACzD;", | ||
| "sourcesContent": ["//\n// Error handling\n// ---\n//\n// The default onError handler is to re-throw.\nimport options from './options'\n\nexport function catchFunctionErrors(delegate) {\n if (!options.onError) {\n return delegate\n }\n return (...args) => {\n try {\n return delegate(...args)\n } catch (err) {\n options.onError(err)\n }\n }\n}\n\nexport function deferError(error) {\n safeSetTimeout(function () {\n throw error\n }, 0)\n}\n\nexport function safeSetTimeout(handler, timeout: number) {\n return setTimeout(catchFunctionErrors(handler), timeout)\n}\n"], | ||
| "mappings": ";;AAKA,OAAO,aAAa;AAEb,gBAAS,oBAAoB,UAAU;AAC5C,MAAI,CAAC,QAAQ,SAAS;AACpB,WAAO;AAAA,EACT;AACA,SAAO,IAAI,SAAS;AAClB,QAAI;AACF,aAAO,SAAS,GAAG,IAAI;AAAA,IACzB,SAAS,KAAK;AACZ,cAAQ,QAAQ,GAAG;AAAA,IACrB;AAAA,EACF;AACF;AAEO,gBAAS,WAAW,OAAO;AAChC,iBAAe,WAAY;AACzB,UAAM;AAAA,EACR,GAAG,CAAC;AACN;AAEO,gBAAS,eAAe,SAAS,SAAiB;AACvD,SAAO,WAAW,oBAAoB,OAAO,GAAG,OAAO;AACzD;", | ||
| "names": [] | ||
| } |
+2
-1
@@ -1,2 +0,3 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| function testOverwrite() { | ||
@@ -3,0 +4,0 @@ try { |
| { | ||
| "version": 3, | ||
| "sources": ["../src/function.ts"], | ||
| "sourcesContent": ["\nfunction testOverwrite () {\n try {\n Object.defineProperty(function x () {}, 'length', {})\n return true\n } catch (e) {\n return false\n }\n}\n\nexport const functionSupportsLengthOverwrite = testOverwrite()\n\nexport function overwriteLengthPropertyIfSupported (fn, descriptor) {\n if (functionSupportsLengthOverwrite) {\n Object.defineProperty(fn, 'length', descriptor)\n }\n}\n"], | ||
| "mappings": ";AACA,yBAA0B;AACxB,MAAI;AACF,WAAO,eAAe,aAAc;AAAA,IAAC,GAAG,UAAU,CAAC,CAAC;AACpD,WAAO;AAAA,EACT,SAAS,GAAP;AACA,WAAO;AAAA,EACT;AACF;AAEO,aAAM,kCAAkC,cAAc;AAEtD,mDAA6C,IAAI,YAAY;AAClE,MAAI,iCAAiC;AACnC,WAAO,eAAe,IAAI,UAAU,UAAU;AAAA,EAChD;AACF;", | ||
| "sourcesContent": ["function testOverwrite() {\n try {\n Object.defineProperty(function x() {}, 'length', {})\n return true\n } catch (e) {\n return false\n }\n}\n\nexport const functionSupportsLengthOverwrite = testOverwrite()\n\nexport function overwriteLengthPropertyIfSupported(fn, descriptor) {\n if (functionSupportsLengthOverwrite) {\n Object.defineProperty(fn, 'length', descriptor)\n }\n}\n"], | ||
| "mappings": ";;AAAA,SAAS,gBAAgB;AACvB,MAAI;AACF,WAAO,eAAe,SAAS,IAAI;AAAA,IAAC,GAAG,UAAU,CAAC,CAAC;AACnD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAEO,aAAM,kCAAkC,cAAc;AAEtD,gBAAS,mCAAmC,IAAI,YAAY;AACjE,MAAI,iCAAiC;AACnC,WAAO,eAAe,IAAI,UAAU,UAAU;AAAA,EAChD;AACF;", | ||
| "names": [] | ||
| } |
+446
-449
@@ -1,2 +0,3 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 CommonJS | ||
| // @tko/utils 🥊 4.0.0 CommonJS | ||
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
@@ -21,4 +22,4 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| // index.ts | ||
| var utils_exports = {}; | ||
| __export(utils_exports, { | ||
| var index_exports = {}; | ||
| __export(index_exports, { | ||
| addCleaner: () => addCleaner, | ||
@@ -44,2 +45,3 @@ addDisposeCallback: () => addDisposeCallback, | ||
| debounce: () => debounce, | ||
| default: () => options_default, | ||
| deferError: () => deferError, | ||
@@ -50,18 +52,12 @@ domData: () => data_exports, | ||
| emptyDomNode: () => emptyDomNode, | ||
| ensureSelectElementIsRenderedCorrectly: () => ensureSelectElementIsRenderedCorrectly, | ||
| extend: () => extend, | ||
| findMovesInArrayComparison: () => findMovesInArrayComparison, | ||
| fixUpContinuousNodeArray: () => fixUpContinuousNodeArray, | ||
| forceRefresh: () => forceRefresh, | ||
| functionSupportsLengthOverwrite: () => functionSupportsLengthOverwrite, | ||
| getObjectOwnProperty: () => getObjectOwnProperty, | ||
| hasOwnProperty: () => hasOwnProperty, | ||
| ieVersion: () => ieVersion, | ||
| isDocumentFragment: () => isDocumentFragment, | ||
| isDomElement: () => isDomElement, | ||
| isIe6: () => isIe6, | ||
| isIe7: () => isIe7, | ||
| isObjectLike: () => isObjectLike, | ||
| isThenable: () => isThenable, | ||
| jQuerySetInstance: () => jQuerySetInstance, | ||
| makeArray: () => makeArray, | ||
@@ -88,3 +84,2 @@ memoization: () => memoization_exports, | ||
| setDomNodeChildren: () => setDomNodeChildren, | ||
| setElementName: () => setElementName, | ||
| setHtml: () => setHtml, | ||
@@ -103,9 +98,9 @@ setOptionNodeSelectionState: () => setOptionNodeSelectionState, | ||
| }); | ||
| module.exports = __toCommonJS(utils_exports); | ||
| module.exports = __toCommonJS(index_exports); | ||
| // src/array.ts | ||
| var { isArray } = Array; | ||
| function arrayForEach(array, action, thisArg) { | ||
| function arrayForEach(array, action, actionOwner) { | ||
| if (arguments.length > 2) { | ||
| action = action.bind(thisArg); | ||
| action = action.bind(actionOwner); | ||
| } | ||
@@ -122,3 +117,3 @@ for (let i = 0, j = array.length; i < j; ++i) { | ||
| } | ||
| function arrayMap(array = [], mapping, thisArg) { | ||
| function arrayMap(array, mapping, thisArg) { | ||
| if (arguments.length > 2) { | ||
@@ -130,3 +125,3 @@ mapping = mapping.bind(thisArg); | ||
| function arrayRemoveItem(array, itemToRemove) { | ||
| var index = arrayIndexOf(array, itemToRemove); | ||
| const index = arrayIndexOf(array, itemToRemove); | ||
| if (index > 0) { | ||
@@ -138,3 +133,3 @@ array.splice(index, 1); | ||
| } | ||
| function arrayGetDistinctValues(array = []) { | ||
| function arrayGetDistinctValues(array) { | ||
| const seen = /* @__PURE__ */ new Set(); | ||
@@ -146,5 +141,5 @@ if (array === null) { | ||
| } | ||
| function arrayFilter(array, predicate, thisArg) { | ||
| function arrayFilter(array, predicate, predicateOwner) { | ||
| if (arguments.length > 2) { | ||
| predicate = predicate.bind(thisArg); | ||
| predicate = predicate.bind(predicateOwner); | ||
| } | ||
@@ -157,3 +152,3 @@ return array === null ? [] : (isArray(array) ? array : [...array]).filter(predicate); | ||
| } else { | ||
| for (var i = 0, j = valuesToPush.length; i < j; i++) { | ||
| for (let i = 0, j = valuesToPush.length; i < j; i++) { | ||
| array.push(valuesToPush[i]); | ||
@@ -165,3 +160,3 @@ } | ||
| function addOrRemoveItem(array, value, included) { | ||
| var existingEntryIndex = arrayIndexOf(typeof array.peek === "function" ? array.peek() : array, value); | ||
| const existingEntryIndex = arrayIndexOf(typeof array.peek === "function" ? array.peek() : array, value); | ||
| if (existingEntryIndex < 0) { | ||
@@ -181,6 +176,6 @@ if (included) { | ||
| function range(min, max) { | ||
| min = typeof min === "function" ? min() : min; | ||
| max = typeof max === "function" ? max() : max; | ||
| var result = []; | ||
| for (var i = min; i <= max; i++) { | ||
| const minimum = typeof min === "function" ? min() : min; | ||
| const maximum = typeof max === "function" ? max() : max; | ||
| const result = []; | ||
| for (let i = minimum; i <= maximum; i++) { | ||
| result.push(i); | ||
@@ -192,3 +187,3 @@ } | ||
| if (left.length && right.length) { | ||
| var failedCompares, l, r, leftItem, rightItem; | ||
| let failedCompares, l, r, leftItem, rightItem; | ||
| for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) { | ||
@@ -221,6 +216,6 @@ for (r = 0; rightItem = right[r]; ++r) { | ||
| function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, options2) { | ||
| 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; | ||
| 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; | ||
| for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) { | ||
| lastRow = thisRow; | ||
| editDistanceMatrix.push(thisRow = []); | ||
| editDistanceMatrix.push(thisRow = new Array()); | ||
| bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange); | ||
@@ -236,4 +231,4 @@ bigIndexMinForRow = myMax(0, smlIndex - 1); | ||
| } else { | ||
| var northDistance = lastRow[bigIndex] || maxDistance; | ||
| var westDistance = thisRow[bigIndex - 1] || maxDistance; | ||
| const northDistance = lastRow[bigIndex] || maxDistance; | ||
| const westDistance = thisRow[bigIndex - 1] || maxDistance; | ||
| thisRow[bigIndex] = myMin(northDistance, westDistance) + 1; | ||
@@ -243,25 +238,28 @@ } | ||
| } | ||
| var editScript = [], meMinusOne, notInSml = [], notInBig = []; | ||
| let editScript = new Array(), meMinusOne, notInSml = new Array(), notInBig = new Array(); | ||
| for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex; ) { | ||
| meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1; | ||
| if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) { | ||
| notInSml.push(editScript[editScript.length] = { | ||
| "status": statusNotInSml, | ||
| "value": bigArray[--bigIndex], | ||
| "index": bigIndex | ||
| }); | ||
| notInSml.push( | ||
| editScript[editScript.length] = { | ||
| // added | ||
| status: statusNotInSml, | ||
| value: bigArray[--bigIndex], | ||
| index: bigIndex | ||
| } | ||
| ); | ||
| } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) { | ||
| notInBig.push(editScript[editScript.length] = { | ||
| "status": statusNotInBig, | ||
| "value": smlArray[--smlIndex], | ||
| "index": smlIndex | ||
| }); | ||
| notInBig.push( | ||
| editScript[editScript.length] = { | ||
| // deleted | ||
| status: statusNotInBig, | ||
| value: smlArray[--smlIndex], | ||
| index: smlIndex | ||
| } | ||
| ); | ||
| } else { | ||
| --bigIndex; | ||
| --smlIndex; | ||
| if (!options2.sparse) { | ||
| editScript.push({ | ||
| "status": "retained", | ||
| "value": bigArray[bigIndex] | ||
| }); | ||
| if (!(options2 == null ? void 0 : options2.sparse)) { | ||
| editScript.push({ status: "retained", value: bigArray[bigIndex] }); | ||
| } | ||
@@ -275,36 +273,98 @@ } | ||
| // src/options.ts | ||
| var options = { | ||
| deferUpdates: false, | ||
| useOnlyNativeEvents: false, | ||
| protoProperty: "__ko_proto__", | ||
| defaultBindingAttribute: "data-bind", | ||
| allowVirtualElements: true, | ||
| bindingGlobals: /* @__PURE__ */ Object.create(null), | ||
| bindingProviderInstance: null, | ||
| createChildContextWithAs: false, | ||
| jQuery: globalThis.jQuery, | ||
| Promise: globalThis.Promise, | ||
| taskScheduler: null, | ||
| debug: false, | ||
| global: globalThis, | ||
| document: globalThis.document, | ||
| filters: {}, | ||
| includeDestroyed: false, | ||
| foreachHidesDestroyed: false, | ||
| onError: function(e) { | ||
| throw e; | ||
| }, | ||
| set: function(name, value) { | ||
| options[name] = value; | ||
| }, | ||
| getBindingHandler() { | ||
| }, | ||
| cleanExternalData() { | ||
| var Options = class { | ||
| constructor() { | ||
| // The following options can be set on ko.options to make a function rewriting or something similar. | ||
| this.bindingStringPreparsers = []; | ||
| // Reference to the own knockout instance | ||
| this.knockoutInstance = null; | ||
| this.deferUpdates = false; | ||
| // Don't set this false, with jquery 3.7+ | ||
| this.useOnlyNativeEvents = true; | ||
| // Use HTML5 <template> tags if is supported | ||
| this.useTemplateTag = true; | ||
| this.protoProperty = "__ko_proto__"; | ||
| // Modify the default attribute from `data-bind`. | ||
| this.defaultBindingAttribute = "data-bind"; | ||
| // Enable/disable <!-- ko binding: ... -> style bindings | ||
| this.allowVirtualElements = true; | ||
| // Global variables that can be accessed from bindings. | ||
| this.bindingGlobals = /* @__PURE__ */ Object.create(null); | ||
| // Whether the `with` binding creates a child context when used with `as`. | ||
| this.createChildContextWithAs = false; | ||
| // jQuery will be automatically set to globalThis.jQuery in applyBindings | ||
| // if it is (strictly equal to) undefined. Set it to true to | ||
| // disable automatically setting jQuery. | ||
| this.disableJQueryUsage = false; | ||
| this.Promise = globalThis.Promise; | ||
| this.taskScheduler = null; | ||
| this.debug = false; | ||
| /** | ||
| * The maximum size of template to parse. | ||
| * Set to 0 to disable the limit. | ||
| */ | ||
| this.templateSizeLimit = 4096; | ||
| /** | ||
| * Whether or not to allow script tags in templates. | ||
| * If false, an error will be thrown if a script tag is detected in the template. | ||
| * It is not recommended to set this to true. | ||
| */ | ||
| this.allowScriptTagsInTemplates = false; | ||
| this._sanitizeWarningLogged = false; | ||
| this.global = globalThis; | ||
| this.document = globalThis.document; | ||
| // Filters for bindings | ||
| // data-bind="expression | filter_1 | filter_2" | ||
| this.filters = {}; | ||
| // Used by the template binding. | ||
| this.includeDestroyed = false; | ||
| this.foreachHidesDestroyed = false; | ||
| } | ||
| get jQuery() { | ||
| var _a; | ||
| if (this.disableJQueryUsage) return; | ||
| return (_a = this._jQuery) != null ? _a : globalThis.jQuery; | ||
| } | ||
| /** | ||
| * Set jQuery manuall to be used by TKO. | ||
| * @param jQuery If jQuery set to undefined, TKO will not use jQuery and this.disableJQueryUsage to true. | ||
| */ | ||
| set jQuery(jQuery) { | ||
| if (!jQuery) { | ||
| this.disableJQueryUsage = true; | ||
| this._jQuery = void 0; | ||
| } else { | ||
| this._jQuery = jQuery; | ||
| this.disableJQueryUsage = false; | ||
| } | ||
| } | ||
| /** | ||
| * Sanitize HTML templates before parsing them. Default is a no-op. | ||
| * Please configure something like DOMPurify or validator.js for your environment. | ||
| * @param html HTML string to be sanitized | ||
| * @returns Sanitized HTML string | ||
| */ | ||
| sanitizeHtmlTemplate(html) { | ||
| if (!this._sanitizeWarningLogged) { | ||
| console.warn( | ||
| "WARNING -- You don't have a HTML sanitizer configured. Please configure options.sanitizeHtmlTemplate to avoid XSS vulnerabilities." | ||
| ); | ||
| this._sanitizeWarningLogged = true; | ||
| } | ||
| return html; | ||
| } | ||
| onError(e, throws = true) { | ||
| if (throws) throw e; | ||
| return e; | ||
| } | ||
| set(name, value) { | ||
| this[name] = value; | ||
| } | ||
| // Overload getBindingHandler to have a custom lookup function. | ||
| getBindingHandler(key) { | ||
| return null; | ||
| } | ||
| cleanExternalData(node, callback) { | ||
| } | ||
| }; | ||
| Object.defineProperty(options, "$", { | ||
| get: function() { | ||
| return options.jQuery; | ||
| } | ||
| }); | ||
| var options = new Options(); | ||
| var options_default = options; | ||
@@ -336,3 +396,3 @@ | ||
| function throttle(callback, timeout) { | ||
| var timeoutInstance; | ||
| let timeoutInstance; | ||
| return function(...args) { | ||
@@ -348,3 +408,3 @@ if (!timeoutInstance) { | ||
| function debounce(callback, timeout) { | ||
| var timeoutInstance; | ||
| let timeoutInstance; | ||
| return function(...args) { | ||
@@ -356,16 +416,2 @@ clearTimeout(timeoutInstance); | ||
| // src/ie.ts | ||
| var ieVersion = options_default.document && function() { | ||
| var version = 3, div = options_default.document.createElement("div"), iElems = div.getElementsByTagName("i"); | ||
| while (div.innerHTML = "<!--[if gt IE " + ++version + "]><i></i><![endif]-->", iElems[0]) { | ||
| } | ||
| if (!version) { | ||
| const userAgent = window.navigator.userAgent; | ||
| return ua.match(/MSIE ([^ ]+)/) || ua.match(/rv:([^ )]+)/); | ||
| } | ||
| return version > 4 ? version : void 0; | ||
| }(); | ||
| var isIe6 = ieVersion === 6; | ||
| var isIe7 = ieVersion === 7; | ||
| // src/object.ts | ||
@@ -383,4 +429,5 @@ function hasOwnProperty(obj, propName) { | ||
| if (source) { | ||
| for (var prop in source) { | ||
| for (const prop of Object.keys(source)) { | ||
| if (hasOwnProperty(source, prop)) { | ||
| ; | ||
| target[prop] = source[prop]; | ||
@@ -393,3 +440,3 @@ } | ||
| function objectForEach(obj, action) { | ||
| for (var prop in obj) { | ||
| for (const prop in obj) { | ||
| if (hasOwnProperty(obj, prop)) { | ||
@@ -407,4 +454,4 @@ action(prop, obj[prop]); | ||
| } | ||
| var target = {}; | ||
| for (var prop in source) { | ||
| const target = {}; | ||
| for (const prop in source) { | ||
| if (hasOwnProperty(source, prop)) { | ||
@@ -421,3 +468,3 @@ target[prop] = mapping(source[prop], prop, source); | ||
| if (!seen) { | ||
| seen = []; | ||
| seen = new Array(); | ||
| } | ||
@@ -428,4 +475,4 @@ if (!obj || typeof obj !== "object" || obj.constructor !== Object || seen.indexOf(obj) !== -1) { | ||
| seen.push(obj); | ||
| var result = {}; | ||
| for (var prop in obj) { | ||
| const result = {}; | ||
| for (const prop in obj) { | ||
| if (hasOwnProperty(obj, prop)) { | ||
@@ -449,4 +496,4 @@ result[prop] = clonePlainObjectDeep(obj[prop], seen); | ||
| } | ||
| function isThenable(object2) { | ||
| return isObjectLike(object2) && typeof object2.then === "function"; | ||
| function isThenable(object) { | ||
| return isObjectLike(object) && typeof object.then === "function"; | ||
| } | ||
@@ -486,6 +533,3 @@ | ||
| if (jsonString) { | ||
| if (JSON && JSON.parse) { | ||
| return JSON.parse(jsonString); | ||
| } | ||
| return new Function("return " + jsonString)(); | ||
| return JSON.parse(jsonString); | ||
| } | ||
@@ -505,3 +549,3 @@ } | ||
| function toggleDomNodeCssClass(node, classNames, shouldHaveClass) { | ||
| var addOrRemoveFn; | ||
| let addOrRemoveFn; | ||
| if (!classNames) { | ||
@@ -522,3 +566,3 @@ return; | ||
| function toggleObjectClassPropertyString(obj, prop, classNames, shouldHaveClass) { | ||
| var currentClassNames = obj[prop].match(cssClassNameRegex) || []; | ||
| const currentClassNames = obj[prop].match(cssClassNameRegex) || []; | ||
| arrayForEach(classNames.match(cssClassNameRegex), function(className) { | ||
@@ -530,8 +574,2 @@ addOrRemoveItem(currentClassNames, className, shouldHaveClass); | ||
| // src/jquery.ts | ||
| var jQueryInstance = options_default.global && options_default.global.jQuery; | ||
| function jQuerySetInstance(jquery) { | ||
| options_default.jQuery = jQueryInstance = jquery; | ||
| } | ||
| // src/dom/info.ts | ||
@@ -542,7 +580,7 @@ function domNodeIsContainedBy(node, containedByNode) { | ||
| } | ||
| if (node.nodeType === 11) { | ||
| if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | ||
| return false; | ||
| } | ||
| if (containedByNode.contains) { | ||
| return containedByNode.contains(node.nodeType !== 1 ? node.parentNode : node); | ||
| return containedByNode.contains(node.nodeType !== Node.ELEMENT_NODE ? node.parentNode : node); | ||
| } | ||
@@ -552,6 +590,7 @@ if (containedByNode.compareDocumentPosition) { | ||
| } | ||
| while (node && node != containedByNode) { | ||
| node = node.parentNode; | ||
| let parentNode = node; | ||
| while (parentNode && parentNode != containedByNode) { | ||
| parentNode = parentNode.parentNode; | ||
| } | ||
| return !!node; | ||
| return !!parentNode; | ||
| } | ||
@@ -571,3 +610,3 @@ function domNodeIsAttachedToDocument(node) { | ||
| } else { | ||
| return obj && obj.tagName && obj.nodeType === 1; | ||
| return obj && obj.tagName && obj.nodeType === Node.ELEMENT_NODE; | ||
| } | ||
@@ -579,6 +618,88 @@ } | ||
| } else { | ||
| return obj && obj.nodeType === 11; | ||
| return obj && obj.nodeType === Node.DOCUMENT_FRAGMENT_NODE; | ||
| } | ||
| } | ||
| // src/dom/event.ts | ||
| var knownEvents = {}; | ||
| var knownEventTypesByEventName = {}; | ||
| knownEvents["UIEvents"] = ["keyup", "keydown", "keypress"]; | ||
| knownEvents["MouseEvents"] = [ | ||
| "click", | ||
| "dblclick", | ||
| "mousedown", | ||
| "mouseup", | ||
| "mousemove", | ||
| "mouseover", | ||
| "mouseout", | ||
| "mouseenter", | ||
| "mouseleave" | ||
| ]; | ||
| objectForEach(knownEvents, function(eventType, knownEventsForType) { | ||
| if (knownEventsForType.length) { | ||
| for (let i = 0, j = knownEventsForType.length; i < j; i++) { | ||
| knownEventTypesByEventName[knownEventsForType[i]] = eventType; | ||
| } | ||
| } | ||
| }); | ||
| function isClickOnCheckableElement(element, eventType) { | ||
| if (tagNameLower(element) !== "input" || !element.type) return false; | ||
| if (eventType.toLowerCase() != "click") return false; | ||
| const inputType = element.type; | ||
| return inputType == "checkbox" || inputType == "radio"; | ||
| } | ||
| function registerEventHandler(element, eventType, handler, eventOptions = false) { | ||
| const wrappedHandler = catchFunctionErrors(handler); | ||
| const mustUseNative = Boolean(eventOptions); | ||
| const jQuery = options_default.jQuery; | ||
| if (!options_default.useOnlyNativeEvents && !mustUseNative && jQuery) { | ||
| jQuery(element).on(eventType, wrappedHandler); | ||
| } else if (typeof element.addEventListener === "function") { | ||
| element.addEventListener(eventType, wrappedHandler, eventOptions); | ||
| } else { | ||
| throw new Error("Browser doesn't support addEventListener"); | ||
| } | ||
| } | ||
| function hasClick(element) { | ||
| return typeof element.click === "function"; | ||
| } | ||
| function triggerEvent(element, eventType) { | ||
| if (!(element && element.nodeType)) { | ||
| throw new Error("element must be a DOM node when calling triggerEvent"); | ||
| } | ||
| const useClickWorkaround = isClickOnCheckableElement(element, eventType); | ||
| if (!options_default.useOnlyNativeEvents && options_default.jQuery && !useClickWorkaround) { | ||
| options_default.jQuery(element).trigger(eventType); | ||
| } else if (typeof document.createEvent === "function") { | ||
| if (typeof element.dispatchEvent === "function") { | ||
| const eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents"; | ||
| const event = document.createEvent(eventCategory); | ||
| event.initEvent( | ||
| eventType, | ||
| true, | ||
| true, | ||
| options_default.global, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| false, | ||
| false, | ||
| false, | ||
| false, | ||
| 0, | ||
| element | ||
| ); | ||
| element.dispatchEvent(event); | ||
| } else { | ||
| throw new Error("The supplied element doesn't support dispatchEvent"); | ||
| } | ||
| } else if (useClickWorkaround && hasClick(element)) { | ||
| element.click(); | ||
| } else { | ||
| throw new Error("Browser doesn't support triggering events"); | ||
| } | ||
| } | ||
| // src/dom/data.ts | ||
@@ -593,47 +714,23 @@ var data_exports = {}; | ||
| }); | ||
| var datastoreTime = new Date().getTime(); | ||
| var datastoreTime = (/* @__PURE__ */ new Date()).getTime(); | ||
| var dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`; | ||
| var dataStoreSymbol = Symbol("Knockout data"); | ||
| var dataStore; | ||
| var dataStoreSymbol = /* @__PURE__ */ Symbol("Knockout data"); | ||
| var uniqueId = 0; | ||
| var modern = { | ||
| getDataForNode(node, createIfNotFound) { | ||
| let dataForNode = node[dataStoreSymbol]; | ||
| if (!dataForNode && createIfNotFound) { | ||
| dataForNode = node[dataStoreSymbol] = {}; | ||
| } | ||
| return dataForNode; | ||
| }, | ||
| clear(node) { | ||
| if (node[dataStoreSymbol]) { | ||
| delete node[dataStoreSymbol]; | ||
| return true; | ||
| } | ||
| return false; | ||
| function isSafeKey(key) { | ||
| return key !== "__proto__" && key !== "constructor" && key !== "prototype"; | ||
| } | ||
| function getDataForNode(node, createIfNotFound) { | ||
| let dataForNode = node[dataStoreSymbol]; | ||
| if (!dataForNode && createIfNotFound) { | ||
| dataForNode = node[dataStoreSymbol] = {}; | ||
| } | ||
| }; | ||
| var IE = { | ||
| getDataforNode(node, createIfNotFound) { | ||
| let dataStoreKey = node[dataStoreKeyExpandoPropertyName]; | ||
| const hasExistingDataStore = dataStoreKey && dataStoreKey !== "null" && dataStore[dataStoreKey]; | ||
| if (!hasExistingDataStore) { | ||
| if (!createIfNotFound) { | ||
| return void 0; | ||
| } | ||
| dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++; | ||
| dataStore[dataStoreKey] = {}; | ||
| } | ||
| return dataStore[dataStoreKey]; | ||
| }, | ||
| clear(node) { | ||
| const dataStoreKey = node[dataStoreKeyExpandoPropertyName]; | ||
| if (dataStoreKey) { | ||
| delete dataStore[dataStoreKey]; | ||
| node[dataStoreKeyExpandoPropertyName] = null; | ||
| return true; | ||
| } | ||
| return false; | ||
| return dataForNode; | ||
| } | ||
| function clear(node) { | ||
| if (node[dataStoreSymbol]) { | ||
| delete node[dataStoreSymbol]; | ||
| return true; | ||
| } | ||
| }; | ||
| var { getDataForNode, clear } = ieVersion ? IE : modern; | ||
| return false; | ||
| } | ||
| function nextKey() { | ||
@@ -643,2 +740,3 @@ return uniqueId++ + dataStoreKeyExpandoPropertyName; | ||
| function get(node, key) { | ||
| if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key); | ||
| const dataForNode = getDataForNode(node, false); | ||
@@ -648,7 +746,19 @@ return dataForNode && dataForNode[key]; | ||
| function set(node, key, value) { | ||
| var dataForNode = getDataForNode(node, value !== void 0); | ||
| dataForNode && (dataForNode[key] = value); | ||
| if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key); | ||
| const dataForNode = getDataForNode( | ||
| node, | ||
| value !== void 0 | ||
| /* createIfNotFound */ | ||
| ); | ||
| if (dataForNode) { | ||
| dataForNode[key] = value; | ||
| } | ||
| } | ||
| function getOrSet(node, key, value) { | ||
| const dataForNode = getDataForNode(node, true); | ||
| if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key); | ||
| const dataForNode = getDataForNode( | ||
| node, | ||
| true | ||
| /* createIfNotFound */ | ||
| ); | ||
| return dataForNode[key] || (dataForNode[key] = value); | ||
@@ -662,5 +772,5 @@ } | ||
| function getDisposeCallbacksCollection(node, createIfNotFound) { | ||
| var allDisposeCallbacks = get(node, domDataKey); | ||
| let allDisposeCallbacks = get(node, domDataKey); | ||
| if (allDisposeCallbacks === void 0 && createIfNotFound) { | ||
| allDisposeCallbacks = []; | ||
| allDisposeCallbacks = new Array(); | ||
| set(node, domDataKey, allDisposeCallbacks); | ||
@@ -674,3 +784,3 @@ } | ||
| function cleanSingleNode(node) { | ||
| var callbacks = getDisposeCallbacksCollection(node, false); | ||
| let callbacks = getDisposeCallbacksCollection(node, false); | ||
| if (callbacks) { | ||
@@ -690,10 +800,14 @@ callbacks = callbacks.slice(0); | ||
| if (cleanableNodeTypesWithDescendants[node.nodeType]) { | ||
| cleanNodesInList(node.childNodes, true); | ||
| cleanNodesInList( | ||
| node.childNodes, | ||
| true | ||
| /* onlyComments */ | ||
| ); | ||
| } | ||
| } | ||
| function cleanNodesInList(nodeList, onlyComments) { | ||
| const cleanedNodes = []; | ||
| const cleanedNodes = new Array(); | ||
| let lastCleanedNode; | ||
| for (var i = 0; i < nodeList.length; i++) { | ||
| if (!onlyComments || nodeList[i].nodeType === 8) { | ||
| for (let i = 0; i < nodeList.length; i++) { | ||
| if (!onlyComments || nodeList[i].nodeType === Node.COMMENT_NODE) { | ||
| cleanSingleNode(cleanedNodes[cleanedNodes.length] = lastCleanedNode = nodeList[i]); | ||
@@ -714,3 +828,3 @@ if (nodeList[i] !== lastCleanedNode) { | ||
| function removeDisposeCallback(node, callback) { | ||
| var callbacksCollection = getDisposeCallbacksCollection(node, false); | ||
| const callbacksCollection = getDisposeCallbacksCollection(node, false); | ||
| if (callbacksCollection) { | ||
@@ -726,3 +840,3 @@ arrayRemoveItem(callbacksCollection, callback); | ||
| cleanSingleNode(node); | ||
| if (cleanableNodeTypesWithDescendants[node.nodeType]) { | ||
| if (cleanableNodeTypesWithDescendants[node.nodeType] && node instanceof Element) { | ||
| cleanNodesInList(node.getElementsByTagName("*")); | ||
@@ -734,2 +848,5 @@ } | ||
| function removeNode(node) { | ||
| if (!node) { | ||
| return; | ||
| } | ||
| cleanNode(node); | ||
@@ -740,3 +857,3 @@ if (node.parentNode) { | ||
| } | ||
| var otherNodeCleanerFunctions = []; | ||
| var otherNodeCleanerFunctions = new Array(); | ||
| function addCleaner(fn) { | ||
@@ -752,3 +869,3 @@ otherNodeCleanerFunctions.push(fn); | ||
| function cleanjQueryData(node) { | ||
| var jQueryCleanNodeFn = jQueryInstance ? jQueryInstance.cleanData : null; | ||
| const jQueryCleanNodeFn = options_default.jQuery ? options_default.jQuery.cleanData : null; | ||
| if (jQueryCleanNodeFn) { | ||
@@ -760,90 +877,8 @@ jQueryCleanNodeFn([node]); | ||
| // src/dom/event.ts | ||
| var knownEvents = {}; | ||
| var knownEventTypesByEventName = {}; | ||
| var keyEventTypeName = options_default.global.navigator && /Firefox\/2/i.test(options_default.global.navigator.userAgent) ? "KeyboardEvent" : "UIEvents"; | ||
| knownEvents[keyEventTypeName] = ["keyup", "keydown", "keypress"]; | ||
| knownEvents["MouseEvents"] = [ | ||
| "click", | ||
| "dblclick", | ||
| "mousedown", | ||
| "mouseup", | ||
| "mousemove", | ||
| "mouseover", | ||
| "mouseout", | ||
| "mouseenter", | ||
| "mouseleave" | ||
| ]; | ||
| objectForEach(knownEvents, function(eventType, knownEventsForType) { | ||
| if (knownEventsForType.length) { | ||
| for (var i = 0, j = knownEventsForType.length; i < j; i++) { | ||
| knownEventTypesByEventName[knownEventsForType[i]] = eventType; | ||
| } | ||
| } | ||
| }); | ||
| function isClickOnCheckableElement(element, eventType) { | ||
| if (tagNameLower(element) !== "input" || !element.type) | ||
| return false; | ||
| if (eventType.toLowerCase() != "click") | ||
| return false; | ||
| var inputType = element.type; | ||
| return inputType == "checkbox" || inputType == "radio"; | ||
| } | ||
| var eventsThatMustBeRegisteredUsingAttachEvent = { "propertychange": true }; | ||
| var jQueryEventAttachName; | ||
| function registerEventHandler(element, eventType, handler, eventOptions = false) { | ||
| const wrappedHandler = catchFunctionErrors(handler); | ||
| const mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType]; | ||
| const mustUseNative = Boolean(eventOptions); | ||
| if (!options_default.useOnlyNativeEvents && !mustUseAttachEvent && !mustUseNative && jQueryInstance) { | ||
| if (!jQueryEventAttachName) { | ||
| jQueryEventAttachName = typeof jQueryInstance(element).on === "function" ? "on" : "bind"; | ||
| } | ||
| jQueryInstance(element)[jQueryEventAttachName](eventType, wrappedHandler); | ||
| } else if (!mustUseAttachEvent && typeof element.addEventListener === "function") { | ||
| element.addEventListener(eventType, wrappedHandler, eventOptions); | ||
| } else if (typeof element.attachEvent !== "undefined") { | ||
| const attachEventHandler = function(event) { | ||
| wrappedHandler.call(element, event); | ||
| }; | ||
| const attachEventName = "on" + eventType; | ||
| element.attachEvent(attachEventName, attachEventHandler); | ||
| addDisposeCallback(element, function() { | ||
| element.detachEvent(attachEventName, attachEventHandler); | ||
| }); | ||
| } else { | ||
| throw new Error("Browser doesn't support addEventListener or attachEvent"); | ||
| } | ||
| } | ||
| function triggerEvent(element, eventType) { | ||
| if (!(element && element.nodeType)) { | ||
| throw new Error("element must be a DOM node when calling triggerEvent"); | ||
| } | ||
| var useClickWorkaround = isClickOnCheckableElement(element, eventType); | ||
| if (!options_default.useOnlyNativeEvents && jQueryInstance && !useClickWorkaround) { | ||
| jQueryInstance(element).trigger(eventType); | ||
| } else if (typeof document.createEvent === "function") { | ||
| if (typeof element.dispatchEvent === "function") { | ||
| var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents"; | ||
| var event = document.createEvent(eventCategory); | ||
| event.initEvent(eventType, true, true, options_default.global, 0, 0, 0, 0, 0, false, false, false, false, 0, element); | ||
| element.dispatchEvent(event); | ||
| } else { | ||
| throw new Error("The supplied element doesn't support dispatchEvent"); | ||
| } | ||
| } else if (useClickWorkaround && element.click) { | ||
| element.click(); | ||
| } else if (typeof element.fireEvent !== "undefined") { | ||
| element.fireEvent("on" + eventType); | ||
| } else { | ||
| throw new Error("Browser doesn't support triggering events"); | ||
| } | ||
| } | ||
| // src/dom/manipulation.ts | ||
| function moveCleanedNodesToContainerElement(nodes) { | ||
| var nodesArray = makeArray(nodes); | ||
| var templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document; | ||
| var container = templateDocument.createElement("div"); | ||
| for (var i = 0, j = nodesArray.length; i < j; i++) { | ||
| const nodesArray = makeArray(nodes); | ||
| const templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document; | ||
| const container = templateDocument.createElement("div"); | ||
| for (let i = 0, j = nodesArray.length; i < j; i++) { | ||
| container.appendChild(cleanNode(nodesArray[i])); | ||
@@ -854,4 +889,5 @@ } | ||
| function cloneNodes(nodesArray, shouldCleanNodes) { | ||
| for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) { | ||
| var clonedNode = nodesArray[i].cloneNode(true); | ||
| const newNodesArray = new Array(); | ||
| for (let i = 0; i < nodesArray.length; i++) { | ||
| const clonedNode = nodesArray[i].cloneNode(true); | ||
| newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode); | ||
@@ -864,3 +900,3 @@ } | ||
| if (childNodes2) { | ||
| for (var i = 0, j = childNodes2.length; i < j; i++) { | ||
| for (let i = 0; i < childNodes2.length; i++) { | ||
| domNode.appendChild(childNodes2[i]); | ||
@@ -871,10 +907,10 @@ } | ||
| function replaceDomNodes(nodeToReplaceOrNodeArray, newNodesArray) { | ||
| var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray; | ||
| const nodesToReplaceArray = Array.isArray(nodeToReplaceOrNodeArray) ? nodeToReplaceOrNodeArray : [nodeToReplaceOrNodeArray]; | ||
| if (nodesToReplaceArray.length > 0) { | ||
| var insertionPoint = nodesToReplaceArray[0]; | ||
| var parent = insertionPoint.parentNode; | ||
| for (var i = 0, j = newNodesArray.length; i < j; i++) { | ||
| parent.insertBefore(newNodesArray[i], insertionPoint); | ||
| const insertionPoint = nodesToReplaceArray[0]; | ||
| const parent = insertionPoint.parentNode; | ||
| for (let i = 0; i < newNodesArray.length; i++) { | ||
| parent == null ? void 0 : parent.insertBefore(newNodesArray[i], insertionPoint); | ||
| } | ||
| for (i = 0, j = nodesToReplaceArray.length; i < j; i++) { | ||
| for (let i = 0; i < nodesToReplaceArray.length; i++) { | ||
| removeNode(nodesToReplaceArray[i]); | ||
@@ -884,11 +920,2 @@ } | ||
| } | ||
| function setElementName(element, name) { | ||
| element.name = name; | ||
| if (ieVersion <= 7) { | ||
| try { | ||
| element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false); | ||
| } catch (e) { | ||
| } | ||
| } | ||
| } | ||
| function emptyDomNode(domNode) { | ||
@@ -903,3 +930,3 @@ while (domNode.firstChild) { | ||
| if (continuousNodeArray.length) { | ||
| parentNode = parentNode.nodeType === 8 && parentNode.parentNode || parentNode; | ||
| parentNode = parentNode.nodeType === Node.COMMENT_NODE && parentNode.parentNode || parentNode; | ||
| while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) { | ||
@@ -912,3 +939,3 @@ continuousNodeArray.splice(0, 1); | ||
| if (continuousNodeArray.length > 1) { | ||
| var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1]; | ||
| let current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1]; | ||
| continuousNodeArray.length = 0; | ||
@@ -925,23 +952,4 @@ while (current !== last) { | ||
| function setOptionNodeSelectionState(optionNode, isSelected) { | ||
| if (ieVersion < 7) { | ||
| optionNode.setAttribute("selected", isSelected); | ||
| } else { | ||
| optionNode.selected = isSelected; | ||
| } | ||
| optionNode.selected = isSelected; | ||
| } | ||
| function forceRefresh(node) { | ||
| if (ieVersion >= 9) { | ||
| var elem = node.nodeType == 1 ? node : node.parentNode; | ||
| if (elem.style) { | ||
| elem.style.zoom = elem.style.zoom; | ||
| } | ||
| } | ||
| } | ||
| function ensureSelectElementIsRenderedCorrectly(selectElement) { | ||
| if (ieVersion) { | ||
| var originalWidth = selectElement.style.width; | ||
| selectElement.style.width = 0; | ||
| selectElement.style.width = originalWidth; | ||
| } | ||
| } | ||
@@ -970,11 +978,10 @@ // src/dom/virtualElements.ts | ||
| }); | ||
| var commentNodesHaveTextProperty = options_default.document && options_default.document.createComment("test").text === "<!--test-->"; | ||
| var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+([\s\S]+))?\s*-->$/ : /^\s*ko(?:\s+([\s\S]+))?\s*$/; | ||
| var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/; | ||
| var htmlTagsWithOptionallyClosingChildren = { "ul": true, "ol": true }; | ||
| var startCommentRegex = /^\s*ko(?:\s+([\s\S]+))?\s*$/; | ||
| var endCommentRegex = /^\s*\/ko\s*$/; | ||
| var htmlTagsWithOptionallyClosingChildren = { ul: true, ol: true }; | ||
| function isStartComment(node) { | ||
| return node.nodeType == 8 && startCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue); | ||
| return node.nodeType === Node.COMMENT_NODE && startCommentRegex.test(node.nodeValue); | ||
| } | ||
| function isEndComment(node) { | ||
| return node.nodeType == 8 && endCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue); | ||
| return node.nodeType === Node.COMMENT_NODE && endCommentRegex.test(node.nodeValue); | ||
| } | ||
@@ -986,5 +993,5 @@ function isUnmatchedEndComment(node) { | ||
| function getVirtualChildren(startComment, allowUnbalanced) { | ||
| var currentNode = startComment; | ||
| var depth = 1; | ||
| var children = []; | ||
| let currentNode = startComment; | ||
| let depth = 1; | ||
| const children = new Array(); | ||
| while (currentNode = currentNode.nextSibling) { | ||
@@ -1009,3 +1016,3 @@ if (isEndComment(currentNode)) { | ||
| function getMatchingEndComment(startComment, allowUnbalanced) { | ||
| var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced); | ||
| const allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced); | ||
| if (allVirtualChildren) { | ||
@@ -1021,3 +1028,3 @@ if (allVirtualChildren.length > 0) { | ||
| function getUnbalancedChildTags(node) { | ||
| var childNode = node.firstChild, captureRemaining = null; | ||
| let childNode = node.firstChild, captureRemaining = null; | ||
| if (childNode) { | ||
@@ -1028,3 +1035,7 @@ do { | ||
| } else if (isStartComment(childNode)) { | ||
| var matchingEndComment = getMatchingEndComment(childNode, true); | ||
| const matchingEndComment = getMatchingEndComment( | ||
| childNode, | ||
| /* allowUnbalanced: */ | ||
| true | ||
| ); | ||
| if (matchingEndComment) { | ||
@@ -1042,3 +1053,3 @@ childNode = matchingEndComment; | ||
| } | ||
| var allowedBindings = {}; | ||
| var allowedBindings = /* @__PURE__ */ Object.create(null); | ||
| var hasBindingValue = isStartComment; | ||
@@ -1052,4 +1063,4 @@ function childNodes(node) { | ||
| } else { | ||
| var virtualChildren = childNodes(node); | ||
| for (var i = 0, j = virtualChildren.length; i < j; i++) { | ||
| const virtualChildren = childNodes(node); | ||
| for (let i = 0, j = virtualChildren.length; i < j; i++) { | ||
| removeNode(virtualChildren[i]); | ||
@@ -1065,5 +1076,7 @@ } | ||
| const endCommentNode = node.nextSibling; | ||
| const parentNode = endCommentNode.parentNode; | ||
| for (var i = 0, j = childNodes2.length; i < j; ++i) { | ||
| parentNode.insertBefore(childNodes2[i], endCommentNode); | ||
| if (endCommentNode && endCommentNode.parentNode) { | ||
| const parentNode = endCommentNode.parentNode; | ||
| for (let i = 0, j = childNodes2.length; i < j; ++i) { | ||
| parentNode.insertBefore(childNodes2[i], endCommentNode); | ||
| } | ||
| } | ||
@@ -1073,2 +1086,3 @@ } | ||
| function prepend(containerNode, nodeToPrepend) { | ||
| var _a; | ||
| if (!isStartComment(containerNode)) { | ||
@@ -1081,6 +1095,7 @@ if (containerNode.firstChild) { | ||
| } else { | ||
| containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling); | ||
| (_a = containerNode.parentNode) == null ? void 0 : _a.insertBefore(nodeToPrepend, containerNode.nextSibling); | ||
| } | ||
| } | ||
| function insertAfter(containerNode, nodeToInsert, insertAfterNode) { | ||
| var _a; | ||
| if (!insertAfterNode) { | ||
@@ -1095,3 +1110,3 @@ prepend(containerNode, nodeToInsert); | ||
| } else { | ||
| containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling); | ||
| (_a = containerNode.parentNode) == null ? void 0 : _a.insertBefore(nodeToInsert, insertAfterNode.nextSibling); | ||
| } | ||
@@ -1113,2 +1128,3 @@ } | ||
| let nextChild = firstChild(node); | ||
| if (!nextChild) return null; | ||
| let lastChildNode; | ||
@@ -1126,3 +1142,5 @@ do { | ||
| if (isUnmatchedEndComment(node.nextSibling)) { | ||
| throw Error("Found end comment without a matching opening comment, as next sibling of " + node.outerHTML); | ||
| throw Error( | ||
| "Found end comment without a matching opening comment, as next sibling of " + node.outerHTML | ||
| ); | ||
| } | ||
@@ -1135,5 +1153,5 @@ return null; | ||
| function previousSibling(node) { | ||
| var depth = 0; | ||
| let depth = 0; | ||
| do { | ||
| if (node.nodeType === 8) { | ||
| if (node.nodeType === Node.COMMENT_NODE) { | ||
| if (isStartComment(node)) { | ||
@@ -1154,3 +1172,3 @@ if (--depth === 0) { | ||
| function virtualNodeBindingValue(node) { | ||
| var regexMatch = (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex); | ||
| const regexMatch = node.nodeValue.match(startCommentRegex); | ||
| return regexMatch ? regexMatch[1] : null; | ||
@@ -1162,10 +1180,10 @@ } | ||
| } | ||
| var childNode = elementVerified.firstChild; | ||
| let childNode = elementVerified.firstChild; | ||
| if (childNode) { | ||
| do { | ||
| if (childNode.nodeType === 1) { | ||
| var unbalancedTags = getUnbalancedChildTags(childNode); | ||
| if (childNode.nodeType === Node.ELEMENT_NODE) { | ||
| const unbalancedTags = getUnbalancedChildTags(childNode); | ||
| if (unbalancedTags) { | ||
| var nodeToInsertBefore = childNode.nextSibling; | ||
| for (var i = 0; i < unbalancedTags.length; i++) { | ||
| const nodeToInsertBefore = childNode.nextSibling; | ||
| for (let i = 0; i < unbalancedTags.length; i++) { | ||
| if (nodeToInsertBefore) { | ||
@@ -1184,46 +1202,10 @@ elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore); | ||
| // src/dom/html.ts | ||
| var none = [0, "", ""]; | ||
| var table = [1, "<table>", "</table>"]; | ||
| var tbody = [2, "<table><tbody>", "</tbody></table>"]; | ||
| var colgroup = [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"]; | ||
| var tr = [3, "<table><tbody><tr>", "</tr></tbody></table>"]; | ||
| var select = [1, "<select multiple='multiple'>", "</select>"]; | ||
| var fieldset = [1, "<fieldset>", "</fieldset>"]; | ||
| var map = [1, "<map>", "</map>"]; | ||
| var object = [1, "<object>", "</object>"]; | ||
| var lookup = { | ||
| "area": map, | ||
| "col": colgroup, | ||
| "colgroup": table, | ||
| "caption": table, | ||
| "legend": fieldset, | ||
| "thead": table, | ||
| "tbody": table, | ||
| "tfoot": table, | ||
| "tr": tbody, | ||
| "td": tr, | ||
| "th": tr, | ||
| "option": select, | ||
| "optgroup": select, | ||
| "param": object | ||
| }; | ||
| var supportsTemplateTag = options_default.document && "content" in options_default.document.createElement("template"); | ||
| function getWrap(tags) { | ||
| const m = tags.match(/^(?:<!--.*?-->\s*?)*?<([a-z]+)[\s>]/); | ||
| return m && lookup[m[1]] || none; | ||
| } | ||
| var supportsTemplateTag = options_default.useTemplateTag && options_default.document && "content" in options_default.document.createElement("template"); | ||
| function simpleHtmlParse(html, documentContext) { | ||
| documentContext || (documentContext = document); | ||
| var windowContext = documentContext["parentWindow"] || documentContext["defaultView"] || window; | ||
| var tags = stringTrim(html).toLowerCase(), div = documentContext.createElement("div"), wrap = getWrap(tags), depth = wrap[0]; | ||
| var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>"; | ||
| if (typeof windowContext["innerShiv"] === "function") { | ||
| div.appendChild(windowContext["innerShiv"](markup)); | ||
| } else { | ||
| div.innerHTML = markup; | ||
| if (!documentContext) { | ||
| documentContext = document; | ||
| } | ||
| while (depth--) { | ||
| div = div.lastChild; | ||
| } | ||
| return makeArray(div.lastChild.childNodes); | ||
| const div = documentContext.createElement("div"); | ||
| div.innerHTML = html; | ||
| return makeArray(div.childNodes); | ||
| } | ||
@@ -1234,3 +1216,3 @@ function templateHtmlParse(html, documentContext) { | ||
| } | ||
| var template = documentContext.createElement("template"); | ||
| const template = documentContext.createElement("template"); | ||
| template.innerHTML = html; | ||
@@ -1240,21 +1222,27 @@ return makeArray(template.content.childNodes); | ||
| function jQueryHtmlParse(html, documentContext) { | ||
| if (jQueryInstance.parseHTML) { | ||
| return jQueryInstance.parseHTML(html, documentContext) || []; | ||
| } else { | ||
| var elems = jQueryInstance.clean([html], documentContext); | ||
| if (elems && elems[0]) { | ||
| var elem = elems[0]; | ||
| while (elem.parentNode && elem.parentNode.nodeType !== 11) { | ||
| elem = elem.parentNode; | ||
| } | ||
| if (elem.parentNode) { | ||
| elem.parentNode.removeChild(elem); | ||
| } | ||
| } | ||
| return elems; | ||
| const jQuery = options_default.jQuery; | ||
| if (jQuery) { | ||
| return jQuery.parseHTML(html, documentContext) || []; | ||
| } | ||
| return []; | ||
| } | ||
| function parseHtmlFragment(html, documentContext) { | ||
| return supportsTemplateTag ? templateHtmlParse(html, documentContext) : jQueryInstance ? jQueryHtmlParse(html, documentContext) : simpleHtmlParse(html, documentContext); | ||
| const saferHtml = validateHTMLInput(html); | ||
| if (supportsTemplateTag) return templateHtmlParse(saferHtml, documentContext); | ||
| if (options_default.jQuery) { | ||
| return jQueryHtmlParse(saferHtml, documentContext); | ||
| } | ||
| return simpleHtmlParse(saferHtml, documentContext); | ||
| } | ||
| var scriptTagPattern = /<script\b[^>]*>([\s\S]*?)<\/script[^>]*>/i; | ||
| function validateHTMLInput(html) { | ||
| if (!html) return ""; | ||
| if (options_default.templateSizeLimit > 0 && html.length > options_default.templateSizeLimit) { | ||
| throw new Error("Template is too long. Please configure the 'templateSizeLimit'"); | ||
| } | ||
| if (!options_default.allowScriptTagsInTemplates && scriptTagPattern.test(html)) { | ||
| throw new Error("Script-tag in template detected."); | ||
| } | ||
| return options_default.sanitizeHtmlTemplate(html); | ||
| } | ||
| function parseHtmlForTemplateNodes(html, documentContext) { | ||
@@ -1273,7 +1261,14 @@ const nodes = parseHtmlFragment(html, documentContext); | ||
| } | ||
| if (jQueryInstance && !supportsTemplateTag) { | ||
| jQueryInstance(node).html(html); | ||
| const jQuery = options_default.jQuery; | ||
| if (jQuery && !supportsTemplateTag) { | ||
| const saferHtml = validateHTMLInput(html); | ||
| jQuery(node).html(saferHtml); | ||
| } else { | ||
| var parsedNodes = parseHtmlFragment(html, node.ownerDocument); | ||
| if (node.nodeType === 8) { | ||
| let parsedNodes; | ||
| if (node.ownerDocument) { | ||
| parsedNodes = parseHtmlFragment(html, node.ownerDocument); | ||
| } else { | ||
| parsedNodes = parseHtmlFragment(html); | ||
| } | ||
| if (node.nodeType === Node.COMMENT_NODE) { | ||
| if (html === null) { | ||
@@ -1285,3 +1280,3 @@ emptyNode(node); | ||
| } else { | ||
| for (var i = 0; i < parsedNodes.length; i++) { | ||
| for (let i = 0; i < parsedNodes.length; i++) { | ||
| node.appendChild(parsedNodes[i]); | ||
@@ -1294,17 +1289,17 @@ } | ||
| function setTextContent(element, textContent) { | ||
| var value = typeof textContent === "function" ? textContent() : textContent; | ||
| let value = typeof textContent === "function" ? textContent() : textContent; | ||
| if (value === null || value === void 0) { | ||
| value = ""; | ||
| } | ||
| var innerTextNode = firstChild(element); | ||
| if (!innerTextNode || innerTextNode.nodeType != 3 || nextSibling(innerTextNode)) { | ||
| const innerTextNode = firstChild(element); | ||
| if (!innerTextNode || innerTextNode.nodeType !== Node.TEXT_NODE || nextSibling(innerTextNode)) { | ||
| setDomNodeChildren2(element, [element.ownerDocument.createTextNode(value)]); | ||
| } else { | ||
| ; | ||
| innerTextNode.data = value; | ||
| } | ||
| forceRefresh(element); | ||
| } | ||
| // src/dom/selectExtensions.ts | ||
| var hasDomDataExpandoProperty = Symbol("Knockout selectExtensions hasDomDataProperty"); | ||
| var hasDomDataExpandoProperty = /* @__PURE__ */ Symbol("Knockout selectExtensions hasDomDataProperty"); | ||
| var selectExtensions = { | ||
@@ -1314,3 +1309,3 @@ optionValueDomDataKey: nextKey(), | ||
| switch (tagNameLower(element)) { | ||
| case "option": | ||
| case "option": { | ||
| if (element[hasDomDataExpandoProperty] === true) { | ||
@@ -1320,4 +1315,7 @@ return get(element, selectExtensions.optionValueDomDataKey); | ||
| return element.value; | ||
| case "select": | ||
| return element.selectedIndex >= 0 ? selectExtensions.readValue(element.options[element.selectedIndex]) : void 0; | ||
| } | ||
| case "select": { | ||
| const selectElement = element; | ||
| return selectElement.selectedIndex >= 0 ? selectExtensions.readValue(selectElement.options[selectElement.selectedIndex]) : void 0; | ||
| } | ||
| default: | ||
@@ -1335,27 +1333,32 @@ return element.value; | ||
| } | ||
| ; | ||
| element.value = value; | ||
| } else { | ||
| const el = element; | ||
| set(element, selectExtensions.optionValueDomDataKey, value); | ||
| element[hasDomDataExpandoProperty] = true; | ||
| element.value = typeof value === "number" ? value : ""; | ||
| el[hasDomDataExpandoProperty] = true; | ||
| el.value = typeof value === "number" ? value : ""; | ||
| } | ||
| break; | ||
| case "select": | ||
| if (value === "" || value === null) { | ||
| value = void 0; | ||
| } | ||
| var selection = -1; | ||
| for (let i = 0, n = element.options.length, optionValue; i < n; ++i) { | ||
| optionValue = selectExtensions.readValue(element.options[i]); | ||
| const strictEqual = optionValue === value; | ||
| const blankEqual = optionValue === "" && value === void 0; | ||
| const numericEqual = typeof value === "number" && Number(optionValue) === value; | ||
| if (strictEqual || blankEqual || numericEqual) { | ||
| selection = i; | ||
| break; | ||
| { | ||
| if (value === "" || value === null) { | ||
| value = void 0; | ||
| } | ||
| let selection = -1; | ||
| const selectElement = element; | ||
| for (let i = 0, n = selectElement.options.length, optionValue; i < n; ++i) { | ||
| optionValue = selectExtensions.readValue(selectElement.options[i]); | ||
| const strictEqual = optionValue === value; | ||
| const blankEqual = optionValue === "" && value === void 0; | ||
| const numericEqual = typeof value === "number" && Number(optionValue) === value; | ||
| if (strictEqual || blankEqual || numericEqual) { | ||
| selection = i; | ||
| break; | ||
| } | ||
| } | ||
| if (allowUnset || selection >= 0 || value === void 0 && selectElement.size > 1) { | ||
| selectElement.selectedIndex = selection; | ||
| } | ||
| } | ||
| if (allowUnset || selection >= 0 || value === void 0 && element.size > 1) { | ||
| element.selectedIndex = selection; | ||
| } | ||
| break; | ||
@@ -1366,2 +1369,3 @@ default: | ||
| } | ||
| ; | ||
| element.value = value; | ||
@@ -1392,9 +1396,10 @@ break; | ||
| } | ||
| if (rootNode.nodeType == 8) { | ||
| var memoId = parseMemoText(rootNode.nodeValue); | ||
| if (rootNode.nodeType === Node.COMMENT_NODE) { | ||
| const comment = rootNode; | ||
| const memoId = parseMemoText(comment.nodeValue); | ||
| if (memoId != null) { | ||
| appendToArray.push({ domNode: rootNode, memoId }); | ||
| } | ||
| } else if (rootNode.nodeType == 1) { | ||
| for (var i = 0, childNodes2 = rootNode.childNodes, j = childNodes2.length; i < j; i++) { | ||
| } else if (rootNode.nodeType === Node.ELEMENT_NODE) { | ||
| for (let i = 0, childNodes2 = rootNode.childNodes, j = childNodes2.length; i < j; i++) { | ||
| findMemoNodes(childNodes2[i], appendToArray); | ||
@@ -1408,3 +1413,3 @@ } | ||
| } | ||
| var memoId = generateRandomId(); | ||
| const memoId = generateRandomId(); | ||
| memos[memoId] = callback; | ||
@@ -1414,3 +1419,3 @@ return "<!--[ko_memo:" + memoId + "]-->"; | ||
| function unmemoize(memoId, callbackParams) { | ||
| var callback = memos[memoId]; | ||
| const callback = memos[memoId]; | ||
| if (callback === void 0) { | ||
@@ -1427,7 +1432,7 @@ throw new Error("Couldn't find any memo with ID " + memoId + ". Perhaps it's already been unmemoized."); | ||
| function unmemoizeDomNodeAndDescendants(domNode, extraCallbackParamsArray) { | ||
| var memos2 = []; | ||
| const memos2 = new Array(); | ||
| findMemoNodes(domNode, memos2); | ||
| for (var i = 0, j = memos2.length; i < j; i++) { | ||
| var node = memos2[i].domNode; | ||
| var combinedParams = [node]; | ||
| for (let i = 0, j = memos2.length; i < j; i++) { | ||
| const node = memos2[i].domNode; | ||
| const combinedParams = [node]; | ||
| if (extraCallbackParamsArray) { | ||
@@ -1444,3 +1449,6 @@ arrayPushAll(combinedParams, extraCallbackParamsArray); | ||
| function parseMemoText(memoText) { | ||
| var match = memoText.match(/^\[ko_memo\:(.*?)\]$/); | ||
| if (!memoText) { | ||
| return null; | ||
| } | ||
| const match = memoText.match(/^\[ko_memo\:(.*?)\]$/); | ||
| return match ? match[1] : null; | ||
@@ -1457,3 +1465,3 @@ } | ||
| }); | ||
| var taskQueue = []; | ||
| var taskQueue = new Array(); | ||
| var taskQueueLength = 0; | ||
@@ -1464,4 +1472,4 @@ var nextHandle = 1; | ||
| if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) { | ||
| options_default.taskScheduler = function(callback) { | ||
| var div = w.document.createElement("div"); | ||
| options_default.taskScheduler = (function(callback) { | ||
| const div = w.document.createElement("div"); | ||
| new w.MutationObserver(callback).observe(div, { attributes: true }); | ||
@@ -1471,14 +1479,3 @@ return function() { | ||
| }; | ||
| }(scheduledProcess); | ||
| } else if (w && w.document && "onreadystatechange" in w.document.createElement("script")) { | ||
| options_default.taskScheduler = function(callback) { | ||
| var script = document.createElement("script"); | ||
| script.onreadystatechange = function() { | ||
| script.onreadystatechange = null; | ||
| document.documentElement.removeChild(script); | ||
| script = null; | ||
| callback(); | ||
| }; | ||
| document.documentElement.appendChild(script); | ||
| }; | ||
| })(scheduledProcess); | ||
| } else { | ||
@@ -1491,4 +1488,4 @@ options_default.taskScheduler = function(callback) { | ||
| if (taskQueueLength) { | ||
| var mark = taskQueueLength, countMarks = 0; | ||
| for (var task; nextIndexToProcess < taskQueueLength; ) { | ||
| let mark = taskQueueLength, countMarks = 0; | ||
| for (let task; nextIndexToProcess < taskQueueLength; ) { | ||
| if (task = taskQueue[nextIndexToProcess++]) { | ||
@@ -1527,3 +1524,3 @@ if (nextIndexToProcess > mark) { | ||
| function cancel(handle) { | ||
| var index = handle - (nextHandle - taskQueueLength); | ||
| const index = handle - (nextHandle - taskQueueLength); | ||
| if (index >= nextIndexToProcess && index < taskQueueLength) { | ||
@@ -1534,5 +1531,5 @@ taskQueue[index] = null; | ||
| function resetForTesting() { | ||
| var length = taskQueueLength - nextIndexToProcess; | ||
| const length = taskQueueLength - nextIndexToProcess; | ||
| nextIndexToProcess = taskQueueLength = taskQueue.length = 0; | ||
| return length; | ||
| } |
+2
-3
@@ -1,6 +0,6 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| export * from "./array"; | ||
| export * from "./async"; | ||
| export * from "./error"; | ||
| export * from "./ie"; | ||
| export * from "./object"; | ||
@@ -11,3 +11,2 @@ export * from "./function"; | ||
| export * from "./css"; | ||
| export { jQuerySetInstance } from "./jquery"; | ||
| export { default as options } from "./options"; | ||
@@ -14,0 +13,0 @@ export * from "./dom/event"; |
| { | ||
| "version": 3, | ||
| "sources": ["../src/index.ts"], | ||
| "sourcesContent": ["/*\n tko.util\n ===\n\n*/\n\nexport * from './array'\nexport * from './async'\nexport * from './error'\nexport * from './ie'\nexport * from './object'\nexport * from './function'\nexport * from './string'\nexport * from './symbol'\nexport * from './css'\nexport { jQuerySetInstance } from './jquery'\nexport { default as options } from './options'\n\n// DOM;\nexport * from './dom/event'\nexport * from './dom/info'\nexport * from './dom/manipulation'\nexport * from './dom/fixes'\nexport * from './dom/html'\nexport * from './dom/disposal'\nexport * from './dom/selectExtensions'\n\n// Sub-Modules;\nimport * as memoization from './memoization'\nimport * as tasks from './tasks'\nimport * as virtualElements from './dom/virtualElements'\nimport * as domData from './dom/data'\n\nexport {tasks, virtualElements, domData, memoization}\n"], | ||
| "mappings": ";AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AAEA;", | ||
| "sourcesContent": ["/*\n tko.util\n ===\n\n*/\n\nexport * from './array'\nexport * from './async'\nexport * from './error'\nexport * from './object'\nexport * from './function'\nexport * from './string'\nexport * from './symbol'\nexport * from './css'\nexport { default as options } from './options'\n\n// DOM;\nexport * from './dom/event'\nexport * from './dom/info'\nexport * from './dom/manipulation'\nexport * from './dom/fixes'\nexport * from './dom/html'\nexport * from './dom/disposal'\nexport * from './dom/selectExtensions'\n\n// Sub-Modules;\nimport * as memoization from './memoization'\nimport * as tasks from './tasks'\nimport * as virtualElements from './dom/virtualElements'\nimport * as domData from './dom/data'\n\nexport { tasks, virtualElements, domData, memoization }\n"], | ||
| "mappings": ";;AAMA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,WAAW,eAAe;AAGnC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,YAAY,iBAAiB;AAC7B,YAAY,WAAW;AACvB,YAAY,qBAAqB;AACjC,YAAY,aAAa;AAEzB,SAAS,OAAO,iBAAiB,SAAS;", | ||
| "names": [] | ||
| } |
+2
-3
@@ -1,6 +0,6 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 MJS | ||
| // @tko/utils 🥊 4.0.0 MJS | ||
| "use strict"; | ||
| export * from "./array"; | ||
| export * from "./async"; | ||
| export * from "./error"; | ||
| export * from "./ie"; | ||
| export * from "./object"; | ||
@@ -11,3 +11,2 @@ export * from "./function"; | ||
| export * from "./css"; | ||
| export { jQuerySetInstance } from "./jquery"; | ||
| export { default as options } from "./options"; | ||
@@ -14,0 +13,0 @@ export * from "./dom/event"; |
| { | ||
| "version": 3, | ||
| "sources": ["../src/index.ts"], | ||
| "sourcesContent": ["/*\n tko.util\n ===\n\n*/\n\nexport * from './array'\nexport * from './async'\nexport * from './error'\nexport * from './ie'\nexport * from './object'\nexport * from './function'\nexport * from './string'\nexport * from './symbol'\nexport * from './css'\nexport { jQuerySetInstance } from './jquery'\nexport { default as options } from './options'\n\n// DOM;\nexport * from './dom/event'\nexport * from './dom/info'\nexport * from './dom/manipulation'\nexport * from './dom/fixes'\nexport * from './dom/html'\nexport * from './dom/disposal'\nexport * from './dom/selectExtensions'\n\n// Sub-Modules;\nimport * as memoization from './memoization'\nimport * as tasks from './tasks'\nimport * as virtualElements from './dom/virtualElements'\nimport * as domData from './dom/data'\n\nexport {tasks, virtualElements, domData, memoization}\n"], | ||
| "mappings": ";AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AAEA;", | ||
| "sourcesContent": ["/*\n tko.util\n ===\n\n*/\n\nexport * from './array'\nexport * from './async'\nexport * from './error'\nexport * from './object'\nexport * from './function'\nexport * from './string'\nexport * from './symbol'\nexport * from './css'\nexport { default as options } from './options'\n\n// DOM;\nexport * from './dom/event'\nexport * from './dom/info'\nexport * from './dom/manipulation'\nexport * from './dom/fixes'\nexport * from './dom/html'\nexport * from './dom/disposal'\nexport * from './dom/selectExtensions'\n\n// Sub-Modules;\nimport * as memoization from './memoization'\nimport * as tasks from './tasks'\nimport * as virtualElements from './dom/virtualElements'\nimport * as domData from './dom/data'\n\nexport { tasks, virtualElements, domData, memoization }\n"], | ||
| "mappings": ";;AAMA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,WAAW,eAAe;AAGnC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,YAAY,iBAAiB;AAC7B,YAAY,WAAW;AACvB,YAAY,qBAAqB;AACjC,YAAY,aAAa;AAEzB,SAAS,OAAO,iBAAiB,SAAS;", | ||
| "names": [] | ||
| } |
+18
-13
@@ -1,4 +0,5 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { arrayPushAll } from "./array"; | ||
| var memos = {}; | ||
| const memos = {}; | ||
| function randomMax8HexChars() { | ||
@@ -14,9 +15,10 @@ return ((1 + Math.random()) * 4294967296 | 0).toString(16).substring(1); | ||
| } | ||
| if (rootNode.nodeType == 8) { | ||
| var memoId = parseMemoText(rootNode.nodeValue); | ||
| if (rootNode.nodeType === Node.COMMENT_NODE) { | ||
| const comment = rootNode; | ||
| const memoId = parseMemoText(comment.nodeValue); | ||
| if (memoId != null) { | ||
| appendToArray.push({ domNode: rootNode, memoId }); | ||
| } | ||
| } else if (rootNode.nodeType == 1) { | ||
| for (var i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++) { | ||
| } else if (rootNode.nodeType === Node.ELEMENT_NODE) { | ||
| for (let i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++) { | ||
| findMemoNodes(childNodes[i], appendToArray); | ||
@@ -30,3 +32,3 @@ } | ||
| } | ||
| var memoId = generateRandomId(); | ||
| const memoId = generateRandomId(); | ||
| memos[memoId] = callback; | ||
@@ -36,3 +38,3 @@ return "<!--[ko_memo:" + memoId + "]-->"; | ||
| export function unmemoize(memoId, callbackParams) { | ||
| var callback = memos[memoId]; | ||
| const callback = memos[memoId]; | ||
| if (callback === void 0) { | ||
@@ -49,7 +51,7 @@ throw new Error("Couldn't find any memo with ID " + memoId + ". Perhaps it's already been unmemoized."); | ||
| export function unmemoizeDomNodeAndDescendants(domNode, extraCallbackParamsArray) { | ||
| var memos2 = []; | ||
| const memos2 = new Array(); | ||
| findMemoNodes(domNode, memos2); | ||
| for (var i = 0, j = memos2.length; i < j; i++) { | ||
| var node = memos2[i].domNode; | ||
| var combinedParams = [node]; | ||
| for (let i = 0, j = memos2.length; i < j; i++) { | ||
| const node = memos2[i].domNode; | ||
| const combinedParams = [node]; | ||
| if (extraCallbackParamsArray) { | ||
@@ -66,4 +68,7 @@ arrayPushAll(combinedParams, extraCallbackParamsArray); | ||
| export function parseMemoText(memoText) { | ||
| var match = memoText.match(/^\[ko_memo\:(.*?)\]$/); | ||
| if (!memoText) { | ||
| return null; | ||
| } | ||
| const match = memoText.match(/^\[ko_memo\:(.*?)\]$/); | ||
| return match ? match[1] : null; | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../src/memoization.ts"], | ||
| "sourcesContent": ["//\n// Memoization\n//\nimport { arrayPushAll } from './array'\n\nvar memos = {}\n\nfunction randomMax8HexChars () {\n return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1)\n}\n\nfunction generateRandomId () {\n return randomMax8HexChars() + randomMax8HexChars()\n}\n\nfunction findMemoNodes (rootNode, appendToArray) {\n if (!rootNode) { return }\n if (rootNode.nodeType == 8) {\n var memoId = parseMemoText(rootNode.nodeValue)\n if (memoId != null) { appendToArray.push({ domNode: rootNode, memoId: memoId }) }\n } else if (rootNode.nodeType == 1) {\n for (var i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++) { findMemoNodes(childNodes[i], appendToArray) }\n }\n}\n\nexport function memoize (callback) {\n if (typeof callback !== 'function') { throw new Error('You can only pass a function to memoization.memoize()') }\n var memoId = generateRandomId()\n memos[memoId] = callback\n return '<!--[ko_memo:' + memoId + ']-->'\n}\n\nexport function unmemoize (memoId, callbackParams) {\n var callback = memos[memoId]\n if (callback === undefined) { throw new Error(\"Couldn't find any memo with ID \" + memoId + \". Perhaps it's already been unmemoized.\") }\n try {\n callback.apply(null, callbackParams || [])\n return true\n } finally { delete memos[memoId] }\n}\n\nexport function unmemoizeDomNodeAndDescendants (domNode, extraCallbackParamsArray) {\n var memos = []\n findMemoNodes(domNode, memos)\n for (var i = 0, j = memos.length; i < j; i++) {\n var node = memos[i].domNode\n var combinedParams = [node]\n if (extraCallbackParamsArray) { arrayPushAll(combinedParams, extraCallbackParamsArray) }\n unmemoize(memos[i].memoId, combinedParams)\n node.nodeValue = '' // Neuter this node so we don't try to unmemoize it again\n if (node.parentNode) { node.parentNode.removeChild(node) } // If possible, erase it totally (not always possible - someone else might just hold a reference to it then call unmemoizeDomNodeAndDescendants again)\n }\n}\n\nexport function parseMemoText (memoText) {\n var match = memoText.match(/^\\[ko_memo\\:(.*?)\\]$/)\n return match ? match[1] : null\n}\n"], | ||
| "mappings": ";AAGA;AAEA,IAAI,QAAQ,CAAC;AAEb,8BAA+B;AAC7B,SAAU,MAAI,KAAK,OAAO,KAAK,aAAe,GAAG,SAAS,EAAE,EAAE,UAAU,CAAC;AAC3E;AAEA,4BAA6B;AAC3B,SAAO,mBAAmB,IAAI,mBAAmB;AACnD;AAEA,uBAAwB,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8BAAwB,UAAU;AACvC,MAAI,QAAQ,SAAS,MAAM,sBAAsB;AACjD,SAAO,QAAQ,MAAM,KAAK;AAC5B;", | ||
| "names": [] | ||
| "sourcesContent": ["//\n// Memoization\n//\nimport { arrayPushAll } from './array'\n\nconst memos = {}\n\nfunction randomMax8HexChars() {\n return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1)\n}\n\nfunction generateRandomId() {\n return randomMax8HexChars() + randomMax8HexChars()\n}\n\nfunction findMemoNodes(rootNode: Node, appendToArray: any[]) {\n if (!rootNode) {\n return\n }\n if (rootNode.nodeType === Node.COMMENT_NODE) {\n const comment = rootNode as Comment\n const memoId = parseMemoText(comment.nodeValue)\n if (memoId != null) {\n appendToArray.push({ domNode: rootNode, memoId: memoId })\n }\n } else if (rootNode.nodeType === Node.ELEMENT_NODE) {\n for (let i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++) {\n findMemoNodes(childNodes[i], appendToArray)\n }\n }\n}\n\nexport function memoize(callback: (val: any) => void): string {\n if (typeof callback !== 'function') {\n throw new Error('You can only pass a function to memoization.memoize()')\n }\n const memoId = generateRandomId()\n memos[memoId] = callback\n return '<!--[ko_memo:' + memoId + ']-->'\n}\n\nexport function unmemoize(memoId: string, callbackParams: any[]) {\n const callback = memos[memoId]\n if (callback === undefined) {\n throw new Error(\"Couldn't find any memo with ID \" + memoId + \". Perhaps it's already been unmemoized.\")\n }\n try {\n callback.apply(null, callbackParams || [])\n return true\n } finally {\n delete memos[memoId]\n }\n}\n\nexport function unmemoizeDomNodeAndDescendants(domNode: Node, extraCallbackParamsArray: any[]) {\n const memos = new Array()\n findMemoNodes(domNode, memos)\n for (let i = 0, j = memos.length; i < j; i++) {\n const node = memos[i].domNode\n const combinedParams = [node]\n if (extraCallbackParamsArray) {\n arrayPushAll(combinedParams, extraCallbackParamsArray)\n }\n unmemoize(memos[i].memoId, combinedParams)\n node.nodeValue = '' // Neuter this node so we don't try to unmemoize it again\n if (node.parentNode) {\n node.parentNode.removeChild(node)\n } // If possible, erase it totally (not always possible - someone else might just hold a reference to it then call unmemoizeDomNodeAndDescendants again)\n }\n}\n\nexport function parseMemoText(memoText: string | null): string | null {\n if (!memoText) {\n return null\n }\n\n const match = memoText.match(/^\\[ko_memo\\:(.*?)\\]$/)\n return match ? match[1] : null\n}\n"], | ||
| "mappings": ";;AAGA,SAAS,oBAAoB;AAE7B,MAAM,QAAQ,CAAC;AAEf,SAAS,qBAAqB;AAC5B,WAAU,IAAI,KAAK,OAAO,KAAK,aAAe,GAAG,SAAS,EAAE,EAAE,UAAU,CAAC;AAC3E;AAEA,SAAS,mBAAmB;AAC1B,SAAO,mBAAmB,IAAI,mBAAmB;AACnD;AAEA,SAAS,cAAc,UAAgB,eAAsB;AAC3D,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AACA,MAAI,SAAS,aAAa,KAAK,cAAc;AAC3C,UAAM,UAAU;AAChB,UAAM,SAAS,cAAc,QAAQ,SAAS;AAC9C,QAAI,UAAU,MAAM;AAClB,oBAAc,KAAK,EAAE,SAAS,UAAU,OAAe,CAAC;AAAA,IAC1D;AAAA,EACF,WAAW,SAAS,aAAa,KAAK,cAAc;AAClD,aAAS,IAAI,GAAG,aAAa,SAAS,YAAY,IAAI,WAAW,QAAQ,IAAI,GAAG,KAAK;AACnF,oBAAc,WAAW,CAAC,GAAG,aAAa;AAAA,IAC5C;AAAA,EACF;AACF;AAEO,gBAAS,QAAQ,UAAsC;AAC5D,MAAI,OAAO,aAAa,YAAY;AAClC,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,QAAM,SAAS,iBAAiB;AAChC,QAAM,MAAM,IAAI;AAChB,SAAO,kBAAkB,SAAS;AACpC;AAEO,gBAAS,UAAU,QAAgB,gBAAuB;AAC/D,QAAM,WAAW,MAAM,MAAM;AAC7B,MAAI,aAAa,QAAW;AAC1B,UAAM,IAAI,MAAM,oCAAoC,SAAS,yCAAyC;AAAA,EACxG;AACA,MAAI;AACF,aAAS,MAAM,MAAM,kBAAkB,CAAC,CAAC;AACzC,WAAO;AAAA,EACT,UAAE;AACA,WAAO,MAAM,MAAM;AAAA,EACrB;AACF;AAEO,gBAAS,+BAA+B,SAAe,0BAAiC;AAC7F,QAAMA,SAAQ,IAAI,MAAM;AACxB,gBAAc,SAASA,MAAK;AAC5B,WAAS,IAAI,GAAG,IAAIA,OAAM,QAAQ,IAAI,GAAG,KAAK;AAC5C,UAAM,OAAOA,OAAM,CAAC,EAAE;AACtB,UAAM,iBAAiB,CAAC,IAAI;AAC5B,QAAI,0BAA0B;AAC5B,mBAAa,gBAAgB,wBAAwB;AAAA,IACvD;AACA,cAAUA,OAAM,CAAC,EAAE,QAAQ,cAAc;AACzC,SAAK,YAAY;AACjB,QAAI,KAAK,YAAY;AACnB,WAAK,WAAW,YAAY,IAAI;AAAA,IAClC;AAAA,EACF;AACF;AAEO,gBAAS,cAAc,UAAwC;AACpE,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,SAAS,MAAM,sBAAsB;AACnD,SAAO,QAAQ,MAAM,CAAC,IAAI;AAC5B;", | ||
| "names": ["memos"] | ||
| } |
+10
-8
@@ -1,2 +0,3 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| export function hasOwnProperty(obj, propName) { | ||
@@ -13,4 +14,5 @@ return Object.prototype.hasOwnProperty.call(obj, propName); | ||
| if (source) { | ||
| for (var prop in source) { | ||
| for (const prop of Object.keys(source)) { | ||
| if (hasOwnProperty(source, prop)) { | ||
| ; | ||
| target[prop] = source[prop]; | ||
@@ -23,3 +25,3 @@ } | ||
| export function objectForEach(obj, action) { | ||
| for (var prop in obj) { | ||
| for (const prop in obj) { | ||
| if (hasOwnProperty(obj, prop)) { | ||
@@ -37,4 +39,4 @@ action(prop, obj[prop]); | ||
| } | ||
| var target = {}; | ||
| for (var prop in source) { | ||
| const target = {}; | ||
| for (const prop in source) { | ||
| if (hasOwnProperty(source, prop)) { | ||
@@ -51,3 +53,3 @@ target[prop] = mapping(source[prop], prop, source); | ||
| if (!seen) { | ||
| seen = []; | ||
| seen = new Array(); | ||
| } | ||
@@ -58,4 +60,4 @@ if (!obj || typeof obj !== "object" || obj.constructor !== Object || seen.indexOf(obj) !== -1) { | ||
| seen.push(obj); | ||
| var result = {}; | ||
| for (var prop in obj) { | ||
| const result = {}; | ||
| for (const prop in obj) { | ||
| if (hasOwnProperty(obj, prop)) { | ||
@@ -62,0 +64,0 @@ result[prop] = clonePlainObjectDeep(obj[prop], seen); |
| { | ||
| "version": 3, | ||
| "sources": ["../src/object.ts"], | ||
| "sourcesContent": ["//\n// Object functions\n//\n\nexport function hasOwnProperty(obj, propName) {\n return Object.prototype.hasOwnProperty.call(obj, propName)\n}\n\n/**\n * True when obj is a non-null object, or a function.\n * @param obj \n * @returns \n */\nexport function isObjectLike(obj) {\n if (obj === null) { return false }\n return typeof obj === 'object' || typeof obj === 'function'\n}\n\nexport function extend (target, source) {\n if (source) {\n for (var prop in source) {\n if (hasOwnProperty(source, prop)) {\n target[prop] = source[prop]\n }\n }\n }\n return target\n}\n\nexport function objectForEach (obj, action) {\n for (var prop in obj) {\n if (hasOwnProperty(obj, prop)) {\n action(prop, obj[prop])\n }\n }\n}\n\nexport function objectMap (source, mapping, thisArg) {\n if (!source) { return source }\n if (arguments.length > 2) { mapping = mapping.bind(thisArg) }\n var target = {}\n for (var prop in source) {\n if (hasOwnProperty(source, prop)) {\n target[prop] = mapping(source[prop], prop, source)\n }\n }\n return target\n}\nexport function getObjectOwnProperty (obj, propName) {\n return hasOwnProperty(obj, propName) ? obj[propName] : undefined\n}\n\nexport function clonePlainObjectDeep (obj, seen) {\n if (!seen) { seen = [] }\n\n if (!obj || typeof obj !== 'object' ||\n obj.constructor !== Object ||\n seen.indexOf(obj) !== -1) {\n return obj\n }\n\n // Anything that makes it below is a plain object that has not yet\n // been seen/cloned.\n seen.push(obj)\n\n var result = {}\n for (var prop in obj) {\n if (hasOwnProperty(obj, prop)) {\n result[prop] = clonePlainObjectDeep(obj[prop], seen)\n }\n }\n return result\n}\n\n/**\n * JSON.stringify, but inserts `...` for objects that are referenced\n * multiple times, preventing infinite recursion.\n */\nexport function safeStringify (value) {\n const seen = new Set()\n return JSON.stringify(value, (k, v) => {\n if (seen.has(v)) { return '...' }\n if (typeof v === 'object') { seen.add(v) }\n return v\n })\n}\n\n\n/**\n * Promises/A+ compliant isThenable (per section 1.2)\n */\nexport function isThenable (object: any) {\n return isObjectLike(object) && typeof object.then === 'function'\n}\n"], | ||
| "mappings": ";AAIO,+BAAwB,KAAK,UAAU;AAC5C,SAAO,OAAO,UAAU,eAAe,KAAK,KAAK,QAAQ;AAC3D;AAOO,6BAAsB,KAAK;AAChC,MAAI,QAAQ,MAAM;AAAE,WAAO;AAAA,EAAM;AACjC,SAAO,OAAO,QAAQ,YAAY,OAAO,QAAQ;AACnD;AAEO,uBAAiB,QAAQ,QAAQ;AACtC,MAAI,QAAQ;AACV,aAAS,QAAQ,QAAQ;AACvB,UAAI,eAAe,QAAQ,IAAI,GAAG;AAChC,eAAO,QAAQ,OAAO;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,8BAAwB,KAAK,QAAQ;AAC1C,WAAS,QAAQ,KAAK;AACpB,QAAI,eAAe,KAAK,IAAI,GAAG;AAC7B,aAAO,MAAM,IAAI,KAAK;AAAA,IACxB;AAAA,EACF;AACF;AAEO,0BAAoB,QAAQ,SAAS,SAAS;AACnD,MAAI,CAAC,QAAQ;AAAE,WAAO;AAAA,EAAO;AAC7B,MAAI,UAAU,SAAS,GAAG;AAAE,cAAU,QAAQ,KAAK,OAAO;AAAA,EAAE;AAC5D,MAAI,SAAS,CAAC;AACd,WAAS,QAAQ,QAAQ;AACvB,QAAI,eAAe,QAAQ,IAAI,GAAG;AAChC,aAAO,QAAQ,QAAQ,OAAO,OAAO,MAAM,MAAM;AAAA,IACnD;AAAA,EACF;AACA,SAAO;AACT;AACO,qCAA+B,KAAK,UAAU;AACnD,SAAO,eAAe,KAAK,QAAQ,IAAI,IAAI,YAAY;AACzD;AAEO,qCAA+B,KAAK,MAAM;AAC/C,MAAI,CAAC,MAAM;AAAE,WAAO,CAAC;AAAA,EAAE;AAEvB,MAAI,CAAC,OAAO,OAAO,QAAQ,YACrB,IAAI,gBAAgB,UACpB,KAAK,QAAQ,GAAG,MAAM,IAAI;AAC9B,WAAO;AAAA,EACT;AAIA,OAAK,KAAK,GAAG;AAEb,MAAI,SAAS,CAAC;AACd,WAAS,QAAQ,KAAK;AACpB,QAAI,eAAe,KAAK,IAAI,GAAG;AAC7B,aAAO,QAAQ,qBAAqB,IAAI,OAAO,IAAI;AAAA,IACrD;AAAA,EACF;AACA,SAAO;AACT;AAMO,8BAAwB,OAAO;AACpC,QAAM,OAAO,oBAAI,IAAI;AACrB,SAAO,KAAK,UAAU,OAAO,CAAC,GAAG,MAAM;AACrC,QAAI,KAAK,IAAI,CAAC,GAAG;AAAE,aAAO;AAAA,IAAM;AAChC,QAAI,OAAO,MAAM,UAAU;AAAE,WAAK,IAAI,CAAC;AAAA,IAAE;AACzC,WAAO;AAAA,EACT,CAAC;AACH;AAMO,2BAAqB,QAAa;AACvC,SAAO,aAAa,MAAM,KAAK,OAAO,OAAO,SAAS;AACxD;", | ||
| "sourcesContent": ["//\n// Object functions\n//\n\nexport function hasOwnProperty<T = any>(obj: T, propName: keyof T | any): boolean {\n return Object.prototype.hasOwnProperty.call(obj, propName)\n}\n\n/**\n * True when obj is a non-null object, or a function.\n * @param obj\n * @returns\n */\nexport function isObjectLike(obj) {\n if (obj === null) {\n return false\n }\n return typeof obj === 'object' || typeof obj === 'function'\n}\n\nexport function extend<T, U>(target: T, source: U): T & U {\n if (source) {\n for (const prop of Object.keys(source) as Array<keyof U>) {\n if (hasOwnProperty(source, prop)) {\n ;(target as T & U)[prop] = source[prop] as any\n }\n }\n }\n return target as T & U\n}\n\nexport function objectForEach<T = any>(obj: { [key: string]: T }, action: (key: string, value: T) => void): void {\n for (const prop in obj) {\n if (hasOwnProperty(obj, prop)) {\n action(prop, obj[prop])\n }\n }\n}\n\nexport function objectMap(source, mapping, thisArg?: any) {\n if (!source) {\n return source\n }\n if (arguments.length > 2) {\n mapping = mapping.bind(thisArg)\n }\n const target = {}\n for (const prop in source) {\n if (hasOwnProperty(source, prop)) {\n target[prop] = mapping(source[prop], prop, source)\n }\n }\n return target\n}\nexport function getObjectOwnProperty(obj, propName: string) {\n return hasOwnProperty(obj, propName) ? obj[propName] : undefined\n}\n\n/**\n * @deprecated Function is unused\n * */\nexport function clonePlainObjectDeep(obj, seen?: any[]) {\n if (!seen) {\n seen = new Array()\n }\n\n if (!obj || typeof obj !== 'object' || obj.constructor !== Object || seen.indexOf(obj) !== -1) {\n return obj\n }\n\n // Anything that makes it below is a plain object that has not yet\n // been seen/cloned.\n seen.push(obj)\n\n const result = {}\n for (const prop in obj) {\n if (hasOwnProperty(obj, prop)) {\n result[prop] = clonePlainObjectDeep(obj[prop], seen)\n }\n }\n return result\n}\n\n/**\n * JSON.stringify, but inserts `...` for objects that are referenced\n * multiple times, preventing infinite recursion.\n */\nexport function safeStringify(value) {\n const seen = new Set()\n return JSON.stringify(value, (k, v) => {\n if (seen.has(v)) {\n return '...'\n }\n if (typeof v === 'object') {\n seen.add(v)\n }\n return v\n })\n}\n\n/**\n * Promises/A+ compliant isThenable (per section 1.2)\n */\nexport function isThenable(object: any) {\n return isObjectLike(object) && typeof object.then === 'function'\n}\n"], | ||
| "mappings": ";;AAIO,gBAAS,eAAwB,KAAQ,UAAkC;AAChF,SAAO,OAAO,UAAU,eAAe,KAAK,KAAK,QAAQ;AAC3D;AAOO,gBAAS,aAAa,KAAK;AAChC,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AACA,SAAO,OAAO,QAAQ,YAAY,OAAO,QAAQ;AACnD;AAEO,gBAAS,OAAa,QAAW,QAAkB;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,cAAc,OAAO;AACnC,QAAM,OAAO,oBAAI,IAAI;AACrB,SAAO,KAAK,UAAU,OAAO,CAAC,GAAG,MAAM;AACrC,QAAI,KAAK,IAAI,CAAC,GAAG;AACf,aAAO;AAAA,IACT;AACA,QAAI,OAAO,MAAM,UAAU;AACzB,WAAK,IAAI,CAAC;AAAA,IACZ;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAKO,gBAAS,WAAW,QAAa;AACtC,SAAO,aAAa,MAAM,KAAK,OAAO,OAAO,SAAS;AACxD;", | ||
| "names": [] | ||
| } |
+95
-33
@@ -1,36 +0,98 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| const options = { | ||
| deferUpdates: false, | ||
| useOnlyNativeEvents: false, | ||
| protoProperty: "__ko_proto__", | ||
| defaultBindingAttribute: "data-bind", | ||
| allowVirtualElements: true, | ||
| bindingGlobals: /* @__PURE__ */ Object.create(null), | ||
| bindingProviderInstance: null, | ||
| createChildContextWithAs: false, | ||
| jQuery: globalThis.jQuery, | ||
| Promise: globalThis.Promise, | ||
| taskScheduler: null, | ||
| debug: false, | ||
| global: globalThis, | ||
| document: globalThis.document, | ||
| filters: {}, | ||
| includeDestroyed: false, | ||
| foreachHidesDestroyed: false, | ||
| onError: function(e) { | ||
| throw e; | ||
| }, | ||
| set: function(name, value) { | ||
| options[name] = value; | ||
| }, | ||
| getBindingHandler() { | ||
| }, | ||
| cleanExternalData() { | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| export class Options { | ||
| constructor() { | ||
| // The following options can be set on ko.options to make a function rewriting or something similar. | ||
| this.bindingStringPreparsers = []; | ||
| // Reference to the own knockout instance | ||
| this.knockoutInstance = null; | ||
| this.deferUpdates = false; | ||
| // Don't set this false, with jquery 3.7+ | ||
| this.useOnlyNativeEvents = true; | ||
| // Use HTML5 <template> tags if is supported | ||
| this.useTemplateTag = true; | ||
| this.protoProperty = "__ko_proto__"; | ||
| // Modify the default attribute from `data-bind`. | ||
| this.defaultBindingAttribute = "data-bind"; | ||
| // Enable/disable <!-- ko binding: ... -> style bindings | ||
| this.allowVirtualElements = true; | ||
| // Global variables that can be accessed from bindings. | ||
| this.bindingGlobals = /* @__PURE__ */ Object.create(null); | ||
| // Whether the `with` binding creates a child context when used with `as`. | ||
| this.createChildContextWithAs = false; | ||
| // jQuery will be automatically set to globalThis.jQuery in applyBindings | ||
| // if it is (strictly equal to) undefined. Set it to true to | ||
| // disable automatically setting jQuery. | ||
| this.disableJQueryUsage = false; | ||
| this.Promise = globalThis.Promise; | ||
| this.taskScheduler = null; | ||
| this.debug = false; | ||
| /** | ||
| * The maximum size of template to parse. | ||
| * Set to 0 to disable the limit. | ||
| */ | ||
| this.templateSizeLimit = 4096; | ||
| /** | ||
| * Whether or not to allow script tags in templates. | ||
| * If false, an error will be thrown if a script tag is detected in the template. | ||
| * It is not recommended to set this to true. | ||
| */ | ||
| this.allowScriptTagsInTemplates = false; | ||
| this._sanitizeWarningLogged = false; | ||
| this.global = globalThis; | ||
| this.document = globalThis.document; | ||
| // Filters for bindings | ||
| // data-bind="expression | filter_1 | filter_2" | ||
| this.filters = {}; | ||
| // Used by the template binding. | ||
| this.includeDestroyed = false; | ||
| this.foreachHidesDestroyed = false; | ||
| } | ||
| }; | ||
| Object.defineProperty(options, "$", { | ||
| get: function() { | ||
| return options.jQuery; | ||
| get jQuery() { | ||
| if (this.disableJQueryUsage) return; | ||
| return this._jQuery ?? globalThis.jQuery; | ||
| } | ||
| }); | ||
| /** | ||
| * Set jQuery manuall to be used by TKO. | ||
| * @param jQuery If jQuery set to undefined, TKO will not use jQuery and this.disableJQueryUsage to true. | ||
| */ | ||
| set jQuery(jQuery) { | ||
| if (!jQuery) { | ||
| this.disableJQueryUsage = true; | ||
| this._jQuery = void 0; | ||
| } else { | ||
| this._jQuery = jQuery; | ||
| this.disableJQueryUsage = false; | ||
| } | ||
| } | ||
| /** | ||
| * Sanitize HTML templates before parsing them. Default is a no-op. | ||
| * Please configure something like DOMPurify or validator.js for your environment. | ||
| * @param html HTML string to be sanitized | ||
| * @returns Sanitized HTML string | ||
| */ | ||
| sanitizeHtmlTemplate(html) { | ||
| if (!this._sanitizeWarningLogged) { | ||
| console.warn( | ||
| "WARNING -- You don't have a HTML sanitizer configured. Please configure options.sanitizeHtmlTemplate to avoid XSS vulnerabilities." | ||
| ); | ||
| this._sanitizeWarningLogged = true; | ||
| } | ||
| return html; | ||
| } | ||
| onError(e, throws = true) { | ||
| if (throws) throw e; | ||
| return e; | ||
| } | ||
| set(name, value) { | ||
| this[name] = value; | ||
| } | ||
| // Overload getBindingHandler to have a custom lookup function. | ||
| getBindingHandler(key) { | ||
| return null; | ||
| } | ||
| cleanExternalData(node, callback) { | ||
| } | ||
| } | ||
| const options = new Options(); | ||
| export default options; |
| { | ||
| "version": 3, | ||
| "sources": ["../src/options.ts"], | ||
| "sourcesContent": ["//\n// This becomes ko.options\n// --\n//\n// This is the root 'options', which must be extended by others.\n\nconst options = {\n deferUpdates: false,\n\n useOnlyNativeEvents: false,\n\n protoProperty: '__ko_proto__',\n\n // Modify the default attribute from `data-bind`.\n defaultBindingAttribute: 'data-bind',\n\n // Enable/disable <!-- ko binding: ... -> style bindings\n allowVirtualElements: true,\n\n // Global variables that can be accessed from bindings.\n bindingGlobals: Object.create(null),\n\n // An instance of the binding provider.\n bindingProviderInstance: null,\n\n // Whether the `with` binding creates a child context when used with `as`.\n createChildContextWithAs: false,\n\n // jQuery will be automatically set to globalThis.jQuery in applyBindings\n // if it is (strictly equal to) undefined. Set it to false or null to\n // disable automatically setting jQuery.\n jQuery: globalThis.jQuery,\n\n Promise: globalThis.Promise,\n\n taskScheduler: null,\n\n debug: false,\n\n global: globalThis,\n document: globalThis.document,\n\n // Filters for bindings\n // data-bind=\"expression | filter_1 | filter_2\"\n filters: {},\n\n // Used by the template binding.\n includeDestroyed: false,\n foreachHidesDestroyed: false,\n\n onError: function (e) { throw e },\n\n set: function (name, value) {\n options[name] = value\n },\n\n // Overload getBindingHandler to have a custom lookup function.\n getBindingHandler (/* key */) {},\n cleanExternalData (/* node, callback */) {}\n}\n\nObject.defineProperty(options, '$', {\n get: function () { return options.jQuery }\n})\n\nexport default options\n"], | ||
| "mappings": ";AAMA,MAAM,UAAU;AAAA,EACd,cAAc;AAAA,EAEd,qBAAqB;AAAA,EAErB,eAAe;AAAA,EAGf,yBAAyB;AAAA,EAGzB,sBAAsB;AAAA,EAGtB,gBAAgB,uBAAO,OAAO,IAAI;AAAA,EAGlC,yBAAyB;AAAA,EAGzB,0BAA0B;AAAA,EAK1B,QAAQ,WAAW;AAAA,EAEnB,SAAS,WAAW;AAAA,EAEpB,eAAe;AAAA,EAEf,OAAO;AAAA,EAEP,QAAQ;AAAA,EACR,UAAU,WAAW;AAAA,EAIrB,SAAS,CAAC;AAAA,EAGV,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EAEvB,SAAS,SAAU,GAAG;AAAE,UAAM;AAAA,EAAE;AAAA,EAEhC,KAAK,SAAU,MAAM,OAAO;AAC1B,YAAQ,QAAQ;AAAA,EAClB;AAAA,EAGA,oBAA8B;AAAA,EAAC;AAAA,EAC/B,oBAAyC;AAAA,EAAC;AAC5C;AAEA,OAAO,eAAe,SAAS,KAAK;AAAA,EAClC,KAAK,WAAY;AAAE,WAAO,QAAQ;AAAA,EAAO;AAC3C,CAAC;AAED,eAAe;", | ||
| "sourcesContent": ["import { Provider } from '@tko/provider'\nimport type { KnockoutInstance } from '@tko/builder'\n\nexport interface CustomBindingGlobalProperties {\n [customBindingName: string]: any\n}\n\nexport type BindingStringPreparsersFunction = (bindingString: string) => string\n\n//\n// This becomes ko.options\n// --\n//\n// This is the root 'options', which must be extended by others.\nexport class Options {\n // The following options can be set on ko.options to make a function rewriting or something similar.\n bindingStringPreparsers: BindingStringPreparsersFunction[] = []\n\n // Reference to the own knockout instance\n knockoutInstance: KnockoutInstance | null = null\n\n deferUpdates: boolean = false\n\n // Don't set this false, with jquery 3.7+\n useOnlyNativeEvents: boolean = true\n\n // Use HTML5 <template> tags if is supported\n useTemplateTag: boolean = true\n\n protoProperty: string = '__ko_proto__'\n\n // Modify the default attribute from `data-bind`.\n defaultBindingAttribute: string = 'data-bind'\n\n // Enable/disable <!-- ko binding: ... -> style bindings\n allowVirtualElements: boolean = true\n\n // Global variables that can be accessed from bindings.\n bindingGlobals: object & CustomBindingGlobalProperties = Object.create(null)\n\n // An instance of the binding provider.\n bindingProviderInstance: Provider\n\n // Whether the `with` binding creates a child context when used with `as`.\n createChildContextWithAs: boolean = false\n\n // jQuery will be automatically set to globalThis.jQuery in applyBindings\n // if it is (strictly equal to) undefined. Set it to true to\n // disable automatically setting jQuery.\n disableJQueryUsage: boolean = false\n\n get jQuery(): JQueryStatic | undefined {\n if (this.disableJQueryUsage) return\n return this._jQuery ?? (globalThis as any).jQuery\n }\n\n private _jQuery: JQueryStatic | undefined\n /**\n * Set jQuery manuall to be used by TKO.\n * @param jQuery If jQuery set to undefined, TKO will not use jQuery and this.disableJQueryUsage to true.\n */\n set jQuery(jQuery: JQueryStatic | undefined) {\n if (!jQuery) {\n this.disableJQueryUsage = true\n this._jQuery = undefined\n } else {\n this._jQuery = jQuery\n this.disableJQueryUsage = false\n }\n }\n\n Promise: PromiseConstructor = globalThis.Promise\n\n taskScheduler: any = null\n\n debug: boolean = false\n /**\n * The maximum size of template to parse.\n * Set to 0 to disable the limit.\n */\n templateSizeLimit: number = 4096\n\n /**\n * Whether or not to allow script tags in templates.\n * If false, an error will be thrown if a script tag is detected in the template.\n * It is not recommended to set this to true.\n */\n allowScriptTagsInTemplates: boolean = false\n\n private _sanitizeWarningLogged: boolean = false\n /**\n * Sanitize HTML templates before parsing them. Default is a no-op.\n * Please configure something like DOMPurify or validator.js for your environment.\n * @param html HTML string to be sanitized\n * @returns Sanitized HTML string\n */\n sanitizeHtmlTemplate(html: string): string {\n if (!this._sanitizeWarningLogged) {\n console.warn(\n \"WARNING -- You don't have a HTML sanitizer configured. Please configure options.sanitizeHtmlTemplate to avoid XSS vulnerabilities.\"\n )\n this._sanitizeWarningLogged = true\n }\n return html\n }\n\n global: any = globalThis\n\n document: Document = globalThis.document\n\n // Filters for bindings\n // data-bind=\"expression | filter_1 | filter_2\"\n filters: any = {}\n\n // Used by the template binding.\n includeDestroyed: boolean = false\n\n foreachHidesDestroyed: boolean = false\n\n onError(e: any, throws: boolean = true): typeof e {\n if (throws) throw e\n return e\n }\n\n set(name: string, value: any): void {\n this[name] = value\n }\n\n // Overload getBindingHandler to have a custom lookup function.\n getBindingHandler(key: string): any {\n return null\n }\n cleanExternalData(node: Node, callback?: Function) {}\n}\n\nconst options = new Options()\n\nexport default options\n"], | ||
| "mappings": ";;AAcO,aAAM,QAAQ;AAAA,EAAd;AAEL;AAAA,mCAA6D,CAAC;AAG9D;AAAA,4BAA4C;AAE5C,wBAAwB;AAGxB;AAAA,+BAA+B;AAG/B;AAAA,0BAA0B;AAE1B,yBAAwB;AAGxB;AAAA,mCAAkC;AAGlC;AAAA,gCAAgC;AAGhC;AAAA,0BAAyD,uBAAO,OAAO,IAAI;AAM3E;AAAA,oCAAoC;AAKpC;AAAA;AAAA;AAAA,8BAA8B;AAsB9B,mBAA8B,WAAW;AAEzC,yBAAqB;AAErB,iBAAiB;AAKjB;AAAA;AAAA;AAAA;AAAA,6BAA4B;AAO5B;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAsC;AAEtC,SAAQ,yBAAkC;AAiB1C,kBAAc;AAEd,oBAAqB,WAAW;AAIhC;AAAA;AAAA,mBAAe,CAAC;AAGhB;AAAA,4BAA4B;AAE5B,iCAAiC;AAAA;AAAA,EAlEjC,IAAI,SAAmC;AACrC,QAAI,KAAK,mBAAoB;AAC7B,WAAO,KAAK,WAAY,WAAmB;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAO,QAAkC;AAC3C,QAAI,CAAC,QAAQ;AACX,WAAK,qBAAqB;AAC1B,WAAK,UAAU;AAAA,IACjB,OAAO;AACL,WAAK,UAAU;AACf,WAAK,qBAAqB;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BA,qBAAqB,MAAsB;AACzC,QAAI,CAAC,KAAK,wBAAwB;AAChC,cAAQ;AAAA,QACN;AAAA,MACF;AACA,WAAK,yBAAyB;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAAA,EAeA,QAAQ,GAAQ,SAAkB,MAAgB;AAChD,QAAI,OAAQ,OAAM;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,MAAc,OAAkB;AAClC,SAAK,IAAI,IAAI;AAAA,EACf;AAAA;AAAA,EAGA,kBAAkB,KAAkB;AAClC,WAAO;AAAA,EACT;AAAA,EACA,kBAAkB,MAAY,UAAqB;AAAA,EAAC;AACtD;AAEA,MAAM,UAAU,IAAI,QAAQ;AAE5B,eAAe;", | ||
| "names": [] | ||
| } |
+3
-5
@@ -1,2 +0,3 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| export function stringTrim(string) { | ||
@@ -16,6 +17,3 @@ return string === null || string === void 0 ? "" : string.trim ? string.trim() : string.toString().replace(/^[\s\xa0]+|[\s\xa0]+$/g, ""); | ||
| if (jsonString) { | ||
| if (JSON && JSON.parse) { | ||
| return JSON.parse(jsonString); | ||
| } | ||
| return new Function("return " + jsonString)(); | ||
| return JSON.parse(jsonString); | ||
| } | ||
@@ -22,0 +20,0 @@ } |
| { | ||
| "version": 3, | ||
| "sources": ["../src/string.ts"], | ||
| "sourcesContent": ["//\n// String (and JSON)\n//\n\nexport function stringTrim (string) {\n return string === null || string === undefined ? ''\n : string.trim\n ? string.trim()\n : string.toString().replace(/^[\\s\\xa0]+|[\\s\\xa0]+$/g, '')\n}\n\nexport function stringStartsWith (string, startsWith) {\n string = string || ''\n if (startsWith.length > string.length) { return false }\n return string.substring(0, startsWith.length) === startsWith\n}\n\nexport function parseJson (jsonString) {\n if (typeof jsonString === 'string') {\n jsonString = stringTrim(jsonString)\n if (jsonString) {\n if (JSON && JSON.parse) // Use native parsing where available\n { return JSON.parse(jsonString) }\n return (new Function('return ' + jsonString))() // Fallback on less safe parsing for older browsers\n }\n }\n return null\n}\n"], | ||
| "mappings": ";AAIO,2BAAqB,QAAQ;AAClC,SAAO,WAAW,QAAQ,WAAW,SAAY,KACzC,OAAO,OACH,OAAO,KAAK,IACZ,OAAO,SAAS,EAAE,QAAQ,0BAA0B,EAAE;AACpE;AAEO,iCAA2B,QAAQ,YAAY;AACpD,WAAS,UAAU;AACnB,MAAI,WAAW,SAAS,OAAO,QAAQ;AAAE,WAAO;AAAA,EAAM;AACtD,SAAO,OAAO,UAAU,GAAG,WAAW,MAAM,MAAM;AACpD;AAEO,0BAAoB,YAAY;AACrC,MAAI,OAAO,eAAe,UAAU;AAClC,iBAAa,WAAW,UAAU;AAClC,QAAI,YAAY;AACd,UAAI,QAAQ,KAAK,OACX;AAAE,eAAO,KAAK,MAAM,UAAU;AAAA,MAAE;AACtC,aAAQ,IAAI,SAAS,YAAY,UAAU,EAAG;AAAA,IAChD;AAAA,EACF;AACA,SAAO;AACT;", | ||
| "sourcesContent": ["//\n// String (and JSON)\n//\n\nexport function stringTrim(string) {\n return string === null || string === undefined\n ? ''\n : string.trim\n ? string.trim()\n : string.toString().replace(/^[\\s\\xa0]+|[\\s\\xa0]+$/g, '')\n}\n\nexport function stringStartsWith(string, startsWith) {\n string = string || ''\n if (startsWith.length > string.length) {\n return false\n }\n return string.substring(0, startsWith.length) === startsWith\n}\n\nexport function parseJson<T = any>(jsonString: string): T | null {\n if (typeof jsonString === 'string') {\n jsonString = stringTrim(jsonString)\n if (jsonString) {\n return JSON.parse(jsonString) as T\n }\n }\n return null\n}\n"], | ||
| "mappings": ";;AAIO,gBAAS,WAAW,QAAQ;AACjC,SAAO,WAAW,QAAQ,WAAW,SACjC,KACA,OAAO,OACL,OAAO,KAAK,IACZ,OAAO,SAAS,EAAE,QAAQ,0BAA0B,EAAE;AAC9D;AAEO,gBAAS,iBAAiB,QAAQ,YAAY;AACnD,WAAS,UAAU;AACnB,MAAI,WAAW,SAAS,OAAO,QAAQ;AACrC,WAAO;AAAA,EACT;AACA,SAAO,OAAO,UAAU,GAAG,WAAW,MAAM,MAAM;AACpD;AAEO,gBAAS,UAAmB,YAA8B;AAC/D,MAAI,OAAO,eAAe,UAAU;AAClC,iBAAa,WAAW,UAAU;AAClC,QAAI,YAAY;AACd,aAAO,KAAK,MAAM,UAAU;AAAA,IAC9B;AAAA,EACF;AACA,SAAO;AACT;", | ||
| "names": [] | ||
| } |
+3
-2
@@ -1,5 +0,6 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| export var useSymbols = typeof Symbol === "function"; | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| export const useSymbols = typeof Symbol === "function"; | ||
| export function createSymbolOrString(identifier) { | ||
| return useSymbols ? Symbol(identifier) : identifier; | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../src/symbol.ts"], | ||
| "sourcesContent": ["//\n// ES6 Symbols\n//\n\nexport var useSymbols = typeof Symbol === 'function'\n\nexport function createSymbolOrString (identifier) {\n return useSymbols ? Symbol(identifier) : identifier\n}\n"], | ||
| "mappings": ";AAIO,WAAI,aAAa,OAAO,WAAW;AAEnC,qCAA+B,YAAY;AAChD,SAAO,aAAa,OAAO,UAAU,IAAI;AAC3C;", | ||
| "sourcesContent": ["//\n// ES6 Symbols\n//\n\nexport const useSymbols = typeof Symbol === 'function'\n\nexport function createSymbolOrString(identifier) {\n return useSymbols ? Symbol(identifier) : identifier\n}\n"], | ||
| "mappings": ";;AAIO,aAAM,aAAa,OAAO,WAAW;AAErC,gBAAS,qBAAqB,YAAY;AAC/C,SAAO,aAAa,OAAO,UAAU,IAAI;AAC3C;", | ||
| "names": [] | ||
| } |
+10
-20
@@ -1,8 +0,9 @@ | ||
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import options from "./options"; | ||
| import { deferError } from "./error"; | ||
| var taskQueue = [], taskQueueLength = 0, nextHandle = 1, nextIndexToProcess = 0, w = options.global; | ||
| let taskQueue = new Array(), taskQueueLength = 0, nextHandle = 1, nextIndexToProcess = 0, w = options.global; | ||
| if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) { | ||
| options.taskScheduler = function(callback) { | ||
| var div = w.document.createElement("div"); | ||
| options.taskScheduler = (function(callback) { | ||
| const div = w.document.createElement("div"); | ||
| new w.MutationObserver(callback).observe(div, { attributes: true }); | ||
@@ -12,14 +13,3 @@ return function() { | ||
| }; | ||
| }(scheduledProcess); | ||
| } else if (w && w.document && "onreadystatechange" in w.document.createElement("script")) { | ||
| options.taskScheduler = function(callback) { | ||
| var script = document.createElement("script"); | ||
| script.onreadystatechange = function() { | ||
| script.onreadystatechange = null; | ||
| document.documentElement.removeChild(script); | ||
| script = null; | ||
| callback(); | ||
| }; | ||
| document.documentElement.appendChild(script); | ||
| }; | ||
| })(scheduledProcess); | ||
| } else { | ||
@@ -32,4 +22,4 @@ options.taskScheduler = function(callback) { | ||
| if (taskQueueLength) { | ||
| var mark = taskQueueLength, countMarks = 0; | ||
| for (var task; nextIndexToProcess < taskQueueLength; ) { | ||
| let mark = taskQueueLength, countMarks = 0; | ||
| for (let task; nextIndexToProcess < taskQueueLength; ) { | ||
| if (task = taskQueue[nextIndexToProcess++]) { | ||
@@ -68,3 +58,3 @@ if (nextIndexToProcess > mark) { | ||
| export function cancel(handle) { | ||
| var index = handle - (nextHandle - taskQueueLength); | ||
| const index = handle - (nextHandle - taskQueueLength); | ||
| if (index >= nextIndexToProcess && index < taskQueueLength) { | ||
@@ -75,3 +65,3 @@ taskQueue[index] = null; | ||
| export function resetForTesting() { | ||
| var length = taskQueueLength - nextIndexToProcess; | ||
| const length = taskQueueLength - nextIndexToProcess; | ||
| nextIndexToProcess = taskQueueLength = taskQueue.length = 0; | ||
@@ -78,0 +68,0 @@ return length; |
| { | ||
| "version": 3, | ||
| "sources": ["../src/tasks.ts"], | ||
| "sourcesContent": ["//\n// Tasks Micro-scheduler\n// ===\n//\n/* eslint no-cond-assign: 0 */\nimport options from './options'\nimport { deferError } from './error'\n\nvar taskQueue = [],\n taskQueueLength = 0,\n nextHandle = 1,\n nextIndexToProcess = 0,\n w = options.global\n\nif (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {\n // Chrome 27+, Firefox 14+, IE 11+, Opera 15+, Safari 6.1+, node\n // From https://github.com/petkaantonov/bluebird * Copyright (c) 2014 Petka Antonov * License: MIT\n options.taskScheduler = (function (callback) {\n var div = w.document.createElement('div')\n new w.MutationObserver(callback).observe(div, {attributes: true})\n return function () { div.classList.toggle('foo') }\n })(scheduledProcess)\n} else if (w && w.document && 'onreadystatechange' in w.document.createElement('script')) {\n // IE 6-10\n // From https://github.com/YuzuJS/setImmediate * Copyright (c) 2012 Barnesandnoble.com, llc, Donavon West, and Domenic Denicola * License: MIT\n options.taskScheduler = function (callback) {\n var script = document.createElement('script')\n script.onreadystatechange = function () {\n script.onreadystatechange = null\n document.documentElement.removeChild(script)\n script = null\n callback()\n }\n document.documentElement.appendChild(script)\n }\n} else {\n options.taskScheduler = function (callback) {\n setTimeout(callback, 0)\n }\n}\n\nfunction processTasks () {\n if (taskQueueLength) {\n // Each mark represents the end of a logical group of tasks and the number of these groups is\n // limited to prevent unchecked recursion.\n var mark = taskQueueLength, countMarks = 0\n\n // nextIndexToProcess keeps track of where we are in the queue; processTasks can be called recursively without issue\n for (var task; nextIndexToProcess < taskQueueLength;) {\n if (task = taskQueue[nextIndexToProcess++]) {\n if (nextIndexToProcess > mark) {\n if (++countMarks >= 5000) {\n nextIndexToProcess = taskQueueLength // skip all tasks remaining in the queue since any of them could be causing the recursion\n deferError(Error(\"'Too much recursion' after processing \" + countMarks + ' task groups.'))\n break\n }\n mark = taskQueueLength\n }\n try {\n task()\n } catch (ex) {\n deferError(ex)\n }\n }\n }\n }\n}\n\nfunction scheduledProcess () {\n processTasks()\n\n // Reset the queue\n nextIndexToProcess = taskQueueLength = taskQueue.length = 0\n}\n\nfunction scheduleTaskProcessing () {\n options.taskScheduler(scheduledProcess)\n}\n\nexport function schedule (func) {\n if (!taskQueueLength) {\n scheduleTaskProcessing()\n }\n\n taskQueue[taskQueueLength++] = func\n return nextHandle++\n}\n\nexport function cancel (handle) {\n var index = handle - (nextHandle - taskQueueLength)\n if (index >= nextIndexToProcess && index < taskQueueLength) {\n taskQueue[index] = null\n }\n}\n\n// For testing only: reset the queue and return the previous queue length\nexport function resetForTesting () {\n var length = taskQueueLength - nextIndexToProcess\n nextIndexToProcess = taskQueueLength = taskQueue.length = 0\n return length\n}\n\nexport {processTasks as runEarly}\n"], | ||
| "mappings": ";AAKA;AACA;AAEA,IAAI,YAAY,CAAC,GACf,kBAAkB,GAClB,aAAa,GACb,qBAAqB,GACrB,IAAI,QAAQ;AAEd,IAAI,KAAK,EAAE,oBAAoB,CAAE,GAAE,aAAa,EAAE,UAAU,aAAa;AAGvE,UAAQ,gBAAiB,SAAU,UAAU;AAC3C,QAAI,MAAM,EAAE,SAAS,cAAc,KAAK;AACxC,QAAI,EAAE,iBAAiB,QAAQ,EAAE,QAAQ,KAAK,EAAC,YAAY,KAAI,CAAC;AAChE,WAAO,WAAY;AAAE,UAAI,UAAU,OAAO,KAAK;AAAA,IAAE;AAAA,EACnD,EAAG,gBAAgB;AACrB,WAAW,KAAK,EAAE,YAAY,wBAAwB,EAAE,SAAS,cAAc,QAAQ,GAAG;AAGxF,UAAQ,gBAAgB,SAAU,UAAU;AAC1C,QAAI,SAAS,SAAS,cAAc,QAAQ;AAC5C,WAAO,qBAAqB,WAAY;AACtC,aAAO,qBAAqB;AAC5B,eAAS,gBAAgB,YAAY,MAAM;AAC3C,eAAS;AACT,eAAS;AAAA,IACX;AACA,aAAS,gBAAgB,YAAY,MAAM;AAAA,EAC7C;AACF,OAAO;AACL,UAAQ,gBAAgB,SAAU,UAAU;AAC1C,eAAW,UAAU,CAAC;AAAA,EACxB;AACF;AAEA,wBAAyB;AACvB,MAAI,iBAAiB;AAGnB,QAAI,OAAO,iBAAiB,aAAa;AAGzC,aAAS,MAAM,qBAAqB,mBAAkB;AACpD,UAAI,OAAO,UAAU,uBAAuB;AAC1C,YAAI,qBAAqB,MAAM;AAC7B,cAAI,EAAE,cAAc,KAAM;AACxB,iCAAqB;AACrB,uBAAW,MAAM,2CAA2C,aAAa,eAAe,CAAC;AACzF;AAAA,UACF;AACA,iBAAO;AAAA,QACT;AACA,YAAI;AACF,eAAK;AAAA,QACP,SAAS,IAAP;AACA,qBAAW,EAAE;AAAA,QACf;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,4BAA6B;AAC3B,eAAa;AAGb,uBAAqB,kBAAkB,UAAU,SAAS;AAC5D;AAEA,kCAAmC;AACjC,UAAQ,cAAc,gBAAgB;AACxC;AAEO,yBAAmB,MAAM;AAC9B,MAAI,CAAC,iBAAiB;AACpB,2BAAuB;AAAA,EACzB;AAEA,YAAU,qBAAqB;AAC/B,SAAO;AACT;AAEO,uBAAiB,QAAQ;AAC9B,MAAI,QAAQ,SAAU,cAAa;AACnC,MAAI,SAAS,sBAAsB,QAAQ,iBAAiB;AAC1D,cAAU,SAAS;AAAA,EACrB;AACF;AAGO,kCAA4B;AACjC,MAAI,SAAS,kBAAkB;AAC/B,uBAAqB,kBAAkB,UAAU,SAAS;AAC1D,SAAO;AACT;AAEA;", | ||
| "sourcesContent": ["//\n// Tasks Micro-scheduler\n// ===\n//\n/* eslint no-cond-assign: 0 */\nimport options from './options'\nimport { deferError } from './error'\n\nlet taskQueue = new Array(),\n taskQueueLength = 0,\n nextHandle = 1,\n nextIndexToProcess = 0,\n w = options.global\n\nif (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {\n // Chrome 27+, Firefox 14+, IE 11+, Opera 15+, Safari 6.1+, node\n // From https://github.com/petkaantonov/bluebird * Copyright (c) 2014 Petka Antonov * License: MIT\n options.taskScheduler = (function (callback) {\n const div = w.document.createElement('div')\n new w.MutationObserver(callback).observe(div, { attributes: true })\n return function () {\n div.classList.toggle('foo')\n }\n })(scheduledProcess)\n} else {\n options.taskScheduler = function (callback) {\n setTimeout(callback, 0)\n }\n}\n\nfunction processTasks() {\n if (taskQueueLength) {\n // Each mark represents the end of a logical group of tasks and the number of these groups is\n // limited to prevent unchecked recursion.\n let mark = taskQueueLength,\n countMarks = 0\n\n // nextIndexToProcess keeps track of where we are in the queue; processTasks can be called recursively without issue\n for (let task; nextIndexToProcess < taskQueueLength; ) {\n if ((task = taskQueue[nextIndexToProcess++])) {\n if (nextIndexToProcess > mark) {\n if (++countMarks >= 5000) {\n nextIndexToProcess = taskQueueLength // skip all tasks remaining in the queue since any of them could be causing the recursion\n deferError(Error(\"'Too much recursion' after processing \" + countMarks + ' task groups.'))\n break\n }\n mark = taskQueueLength\n }\n try {\n task()\n } catch (ex) {\n deferError(ex)\n }\n }\n }\n }\n}\n\nfunction scheduledProcess() {\n processTasks()\n\n // Reset the queue\n nextIndexToProcess = taskQueueLength = taskQueue.length = 0\n}\n\nfunction scheduleTaskProcessing() {\n options.taskScheduler(scheduledProcess)\n}\n\nexport function schedule(func: () => any): number {\n if (!taskQueueLength) {\n scheduleTaskProcessing()\n }\n\n taskQueue[taskQueueLength++] = func\n return nextHandle++\n}\n\nexport function cancel(handle: number) {\n const index = handle - (nextHandle - taskQueueLength)\n if (index >= nextIndexToProcess && index < taskQueueLength) {\n taskQueue[index] = null\n }\n}\n\n// For testing only: reset the queue and return the previous queue length\nexport function resetForTesting() {\n const length = taskQueueLength - nextIndexToProcess\n nextIndexToProcess = taskQueueLength = taskQueue.length = 0\n return length\n}\n\nexport { processTasks as runEarly }\n"], | ||
| "mappings": ";;AAKA,OAAO,aAAa;AACpB,SAAS,kBAAkB;AAE3B,IAAI,YAAY,IAAI,MAAM,GACxB,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AAK,IAAI;AAAA,EACrB;AACF;AAGO,gBAAS,kBAAkB;AAChC,QAAM,SAAS,kBAAkB;AACjC,uBAAqB,kBAAkB,UAAU,SAAS;AAC1D,SAAO;AACT;AAEA,SAAS,gBAAgB;", | ||
| "names": [] | ||
| } |
+196
-145
@@ -0,71 +1,87 @@ | ||
| /// <reference types="jasmine" /> | ||
| import jQuery from 'jquery' | ||
| window.jQuery = jQuery | ||
| /* | ||
| * Configure the Jasmine testing framework. | ||
| */ | ||
| /* globals runs, waitsFor, jasmine */ | ||
| /* globals runs, waitsFor, jasmine */ | ||
| import { | ||
| arrayMap, arrayFilter, ieVersion, selectExtensions, hasOwnProperty | ||
| } from '../dist/' | ||
| import { arrayMap, arrayFilter, selectExtensions, hasOwnProperty, options } from '../dist/' | ||
| window.DEBUG = true | ||
| window.amdRequire = window.require | ||
| window.DEBUG = true; | ||
| window.amdRequire = window.require; | ||
| jasmine.updateInterval = 500 | ||
| // Use a different variable name (not 'jQuery') to avoid overwriting | ||
| // window.jQuery with 'undefined' on IE < 9 | ||
| window.jQueryInstance = window.jQuery; | ||
| // export var testNode; | ||
| jasmine.updateInterval = 500; | ||
| /* | ||
| Some helper functions for jasmine on the browser | ||
| */ | ||
| jasmine.resolve = function (promise) { | ||
| jasmine.resolve = function (promise: Promise<boolean>) { | ||
| let complete = false | ||
| runs(() => promise.then((result) => { complete = result || true })) | ||
| runs(() => | ||
| promise.then(result => { | ||
| complete = result || true | ||
| }) | ||
| ) | ||
| waitsFor(() => complete) | ||
| } | ||
| jasmine.prepareTestNode = function() { | ||
| // The bindings specs make frequent use of this utility function to set up | ||
| // a clean new DOM node they can execute code against | ||
| var existingNode = document.getElementById("testNode"); | ||
| if (existingNode !== null) | ||
| existingNode.parentNode.removeChild(existingNode); | ||
| window.testNode = document.createElement("div"); | ||
| window.testNode.id = "testNode"; | ||
| document.body.appendChild(window.testNode); | ||
| }; | ||
| jasmine.prepareTestNode = function (): HTMLElement { | ||
| // The bindings specs make frequent use of this utility function to set up | ||
| // a clean new DOM node they can execute code against | ||
| const existingNode = document.getElementById('testNode') | ||
| if (existingNode !== null && existingNode.parentNode) existingNode.parentNode.removeChild(existingNode) | ||
| const testNode = document.createElement('div') | ||
| testNode.id = 'testNode' | ||
| document.body.appendChild(testNode) | ||
| return testNode | ||
| } | ||
| jasmine.Clock.mockScheduler = function (callback) { | ||
| setTimeout(callback, 0); | ||
| }; | ||
| setTimeout(callback, 0) | ||
| } | ||
| export function useMockForTasks(options) { | ||
| jasmine.Clock.useMock(); | ||
| jasmine.Clock.useMock() | ||
| // Make sure tasks is using setTimeout so that it uses the mock clock | ||
| if (options.taskScheduler != jasmine.Clock.mockScheduler) { | ||
| jasmine.getEnv().currentSpec.restoreAfter(options, 'taskScheduler'); | ||
| options.taskScheduler = jasmine.Clock.mockScheduler; | ||
| } | ||
| // Make sure tasks is using setTimeout so that it uses the mock clock | ||
| if (options.taskScheduler != jasmine.Clock.mockScheduler) { | ||
| jasmine.getEnv().currentSpec.restoreAfter(options, 'taskScheduler') | ||
| options.taskScheduler = jasmine.Clock.mockScheduler | ||
| } | ||
| } | ||
| jasmine.Spec.prototype.restoreAfter = function(object, propertyName) { | ||
| var originalValue = object[propertyName]; | ||
| this.after(function() { | ||
| object[propertyName] = originalValue; | ||
| }); | ||
| }; | ||
| jasmine.Spec.prototype.restoreAfter = function (object, propertyName) { | ||
| const originalValue = object[propertyName] | ||
| this.after(function () { | ||
| object[propertyName] = originalValue | ||
| }) | ||
| } | ||
| jasmine.nodeText = function(node) { | ||
| return node.nodeType == 3 ? node.data : 'textContent' in node ? node.textContent : node.innerText; | ||
| }; | ||
| jasmine.nodeText = function (node) { | ||
| return node.nodeType === Node.TEXT_NODE ? node.data : 'textContent' in node ? node.textContent : node.innerText | ||
| } | ||
| jasmine.browserSupportsProtoAssignment = { __proto__: [] } instanceof Array; | ||
| jasmine.browserSupportsProtoAssignment = { __proto__: [] } instanceof Array | ||
| jasmine.setNodeText = function (node, text: string) { | ||
| if ('textContent' in node) { | ||
| node.textContent = text | ||
| } else { | ||
| node.innerText = text | ||
| } | ||
| } | ||
| jasmine.ieVersion = ieVersion; | ||
| function cleanedHtml(node) { | ||
| let cleanedHtml = node.innerHTML.toLowerCase().replace(/\r\n/g, '') | ||
| // IE < 9 strips whitespace immediately following comment nodes. Normalize by doing the same on all browsers. | ||
| cleanedHtml = cleanedHtml.replace(/(<!--.*?-->)\s*/g, '$1') | ||
| // Also remove __ko__ expando properties (for DOM data) - most browsers hide these anyway but IE < 9 includes them in innerHTML | ||
| cleanedHtml = cleanedHtml.replace(/ __ko__\d+=\"(ko\d+|null)\"/g, '') | ||
| return cleanedHtml | ||
| } | ||
| /* | ||
@@ -75,90 +91,110 @@ Custom Matchers | ||
| */ | ||
| var matchers = { | ||
| const matchers = { | ||
| toHaveNodeTypes(expectedTypes) { | ||
| const values = arrayMap(this.actual, function (node) { | ||
| return node.nodeType | ||
| }) | ||
| this.actual = values // Fix explanatory message | ||
| return this.env.equals_(values, expectedTypes) | ||
| }, | ||
| toContainText (expectedText, ignoreSpaces) { | ||
| if (ignoreSpaces) { | ||
| expectedText = expectedText.replace(/\s/g, ""); | ||
| } | ||
| toContainHtmlElementsAndText(expectedHtml) { | ||
| this.actual = cleanedHtml(this.actual).replace(/<!--.+?-->/g, '') // remove comments | ||
| return this.actual === expectedHtml | ||
| }, | ||
| var actualText = jasmine.nodeText(this.actual); | ||
| var cleanedActualText = actualText.replace(/\r\n/g, "\n"); | ||
| if (ignoreSpaces) { | ||
| cleanedActualText = cleanedActualText.replace(/\s/g, ""); | ||
| } | ||
| toContainText(expectedText, ignoreSpaces) { | ||
| if (ignoreSpaces) { | ||
| expectedText = expectedText.replace(/\s/g, '') | ||
| } | ||
| this.actual = cleanedActualText; // Fix explanatory message | ||
| return cleanedActualText === expectedText; | ||
| const actualText = jasmine.nodeText(this.actual) | ||
| let cleanedActualText = actualText.replace(/\r\n/g, '\n') | ||
| if (ignoreSpaces) { | ||
| cleanedActualText = cleanedActualText.replace(/\s/g, '') | ||
| } | ||
| this.actual = cleanedActualText // Fix explanatory message | ||
| return cleanedActualText === expectedText | ||
| }, | ||
| toHaveOwnProperties (expectedProperties) { | ||
| var ownProperties = []; | ||
| for (var prop in this.actual) { | ||
| if (hasOwnProperty(this.actual, prop)) { | ||
| ownProperties.push(prop); | ||
| } | ||
| toHaveOwnProperties(expectedProperties) { | ||
| const ownProperties = new Array() | ||
| for (const prop in this.actual) { | ||
| if (hasOwnProperty(this.actual, prop)) { | ||
| ownProperties.push(prop) | ||
| } | ||
| return this.env.equals_(ownProperties, expectedProperties); | ||
| } | ||
| return this.env.equals_(ownProperties, expectedProperties) | ||
| }, | ||
| toHaveTexts (expectedTexts) { | ||
| var texts = arrayMap(this.actual.childNodes, jasmine.nodeText); | ||
| this.actual = texts; // Fix explanatory message | ||
| return this.env.equals_(texts, expectedTexts); | ||
| toHaveTexts(expectedTexts) { | ||
| const texts = arrayMap(this.actual.childNodes, jasmine.nodeText) | ||
| this.actual = texts // Fix explanatory message | ||
| return this.env.equals_(texts, expectedTexts) | ||
| }, | ||
| toHaveValues (expectedValues) { | ||
| var values = arrayFilter( | ||
| arrayMap(this.actual.childNodes, node => node.value), | ||
| value => value !== undefined) | ||
| this.actual = values // Fix explanatory message | ||
| return this.env.equals_(values, expectedValues) | ||
| toHaveValues(expectedValues) { | ||
| const values = arrayFilter( | ||
| arrayMap(this.actual.childNodes, node => node.value), | ||
| value => value !== undefined | ||
| ) | ||
| this.actual = values // Fix explanatory message | ||
| return this.env.equals_(values, expectedValues) | ||
| }, | ||
| toHaveCheckedStates (expectedValues) { | ||
| const values = arrayMap(this.actual.childNodes, (node) => node.checked) | ||
| this.actual = values; // Fix explanatory message | ||
| return this.env.equals_(values, expectedValues) | ||
| toHaveCheckedStates(expectedValues) { | ||
| const values = arrayMap(this.actual.childNodes, node => node.checked) | ||
| this.actual = values // Fix explanatory message | ||
| return this.env.equals_(values, expectedValues) | ||
| }, | ||
| toThrowContaining(expected) { | ||
| var exception; | ||
| try { | ||
| this.actual(); | ||
| } catch (e) { | ||
| exception = e; | ||
| } | ||
| var exceptionMessage = exception && (exception.message || exception); | ||
| let exception | ||
| try { | ||
| this.actual() | ||
| } catch (e) { | ||
| exception = e | ||
| } | ||
| const exceptionMessage = exception && (exception.message || exception) | ||
| this.message = function () { | ||
| var notText = this.isNot ? " not" : ""; | ||
| var expectation = "Expected " + this.actual.toString() + notText + " to throw exception containing '" + expected + "'"; | ||
| var result = exception ? (", but it threw '" + exceptionMessage + "'") : ", but it did not throw anything"; | ||
| return expectation + result; | ||
| }; | ||
| this.message = function () { | ||
| const notText = this.isNot ? ' not' : '' | ||
| const expectation = | ||
| 'Expected ' + this.actual.toString() + notText + " to throw exception containing '" + expected + "'" | ||
| const result = exception ? ", but it threw '" + exceptionMessage + "'" : ', but it did not throw anything' | ||
| return expectation + result | ||
| } | ||
| return exception ? this.env.contains_(exceptionMessage, expected) : false; | ||
| return exception ? this.env.contains_(exceptionMessage, expected) : false | ||
| }, | ||
| toEqualOneOf (expectedPossibilities) { | ||
| for (var i = 0; i < expectedPossibilities.length; i++) { | ||
| if (this.env.equals_(this.actual, expectedPossibilities[i])) { | ||
| return true; | ||
| } | ||
| toEqualOneOf(expectedPossibilities) { | ||
| for (let i = 0; i < expectedPossibilities.length; i++) { | ||
| if (this.env.equals_(this.actual, expectedPossibilities[i])) { | ||
| return true | ||
| } | ||
| return false; | ||
| } | ||
| return false | ||
| }, | ||
| toContainHtml (expectedHtml, postProcessCleanedHtml) { | ||
| var cleanedHtml = this.actual.innerHTML.toLowerCase().replace(/\r\n/g, ""); | ||
| // IE < 9 strips whitespace immediately following comment nodes. Normalize by doing the same on all browsers. | ||
| cleanedHtml = cleanedHtml.replace(/(<!--.*?-->)\s*/g, "$1"); | ||
| expectedHtml = expectedHtml.replace(/(<!--.*?-->)\s*/g, "$1"); | ||
| // Also remove __ko__ expando properties (for DOM data) - most browsers hide these anyway but IE < 9 includes them in innerHTML | ||
| cleanedHtml = cleanedHtml.replace(/ __ko__\d+=\"(ko\d+|null)\"/g, ""); | ||
| if (postProcessCleanedHtml) { | ||
| cleanedHtml = postProcessCleanedHtml(cleanedHtml); | ||
| } | ||
| this.actual = cleanedHtml; // Fix explanatory message | ||
| return cleanedHtml === expectedHtml; | ||
| toContainHtml(expectedHtml, postProcessCleanedHtml) { | ||
| let cleanedHtml = this.actual.innerHTML.toLowerCase().replace(/\r\n/g, '') | ||
| // IE < 9 strips whitespace immediately following comment nodes. Normalize by doing the same on all browsers. | ||
| cleanedHtml = cleanedHtml.replace(/(<!--.*?-->)\s*/g, '$1') | ||
| expectedHtml = expectedHtml.replace(/(<!--.*?-->)\s*/g, '$1') | ||
| // Also remove __ko__ expando properties (for DOM data) - most browsers hide these anyway but IE < 9 includes them in innerHTML | ||
| cleanedHtml = cleanedHtml.replace(/ __ko__\d+=\"(ko\d+|null)\"/g, '') | ||
| if (postProcessCleanedHtml) { | ||
| cleanedHtml = postProcessCleanedHtml(cleanedHtml) | ||
| } | ||
| this.actual = cleanedHtml // Fix explanatory message | ||
| return cleanedHtml === expectedHtml | ||
| }, | ||
| toHaveSelectedValues(expectedValues) { | ||
| const selectedNodes = arrayFilter(this.actual.childNodes, node => node.selected) | ||
| const selectedValues = arrayMap(selectedNodes, node => selectExtensions.readValue(node)) | ||
| this.actual = selectedValues // Fix explanatory message | ||
| return this.env.equals_(selectedValues, expectedValues) | ||
| } | ||
@@ -170,40 +206,55 @@ } | ||
| // | ||
| jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { | ||
| var scheduledFunc; | ||
| var funcsToRun = []; | ||
| for (var timeoutKey in this.scheduledFunctions) { | ||
| scheduledFunc = this.scheduledFunctions[timeoutKey]; | ||
| if (scheduledFunc != jasmine.undefined && | ||
| scheduledFunc.runAtMillis >= oldMillis && | ||
| scheduledFunc.runAtMillis <= nowMillis) { | ||
| funcsToRun.push(scheduledFunc); | ||
| this.scheduledFunctions[timeoutKey] = jasmine.undefined; | ||
| } | ||
| jasmine.FakeTimer.prototype.runFunctionsWithinRange = function (oldMillis, nowMillis) { | ||
| let scheduledFunc | ||
| const funcsToRun = new Array() | ||
| for (const timeoutKey in this.scheduledFunctions) { | ||
| scheduledFunc = this.scheduledFunctions[timeoutKey] | ||
| if ( | ||
| scheduledFunc != jasmine.undefined | ||
| && scheduledFunc.runAtMillis >= oldMillis | ||
| && scheduledFunc.runAtMillis <= nowMillis | ||
| ) { | ||
| funcsToRun.push(scheduledFunc) | ||
| this.scheduledFunctions[timeoutKey] = jasmine.undefined | ||
| } | ||
| } | ||
| if (funcsToRun.length > 0) { | ||
| funcsToRun.sort(function(a, b) { | ||
| return a.runAtMillis - b.runAtMillis; | ||
| }); | ||
| if (funcsToRun.length > 0) { | ||
| funcsToRun.sort(function (a: any, b: any) { | ||
| return a.runAtMillis - b.runAtMillis | ||
| }) | ||
| for (var i = 0; i < funcsToRun.length; ++i) { | ||
| //try { // mbest: Removed so we can catch errors in asynchronous functions | ||
| var funcToRun = funcsToRun[i]; | ||
| this.nowMillis = funcToRun.runAtMillis; | ||
| funcToRun.funcToCall(); | ||
| if (funcToRun.recurring) { | ||
| this.scheduleFunction(funcToRun.timeoutKey, | ||
| funcToRun.funcToCall, | ||
| funcToRun.millis, | ||
| true); | ||
| } | ||
| //} catch(e) { | ||
| //} | ||
| } | ||
| this.runFunctionsWithinRange(oldMillis, nowMillis); | ||
| for (let i = 0; i < funcsToRun.length; ++i) { | ||
| //try { // mbest: Removed so we can catch errors in asynchronous functions | ||
| const funcToRun = funcsToRun[i] | ||
| this.nowMillis = funcToRun.runAtMillis | ||
| funcToRun.funcToCall() | ||
| if (funcToRun.recurring) { | ||
| this.scheduleFunction(funcToRun.timeoutKey, funcToRun.funcToCall, funcToRun.millis, true) | ||
| } | ||
| //} catch(e) { | ||
| //} | ||
| } | ||
| }; | ||
| this.runFunctionsWithinRange(oldMillis, nowMillis) | ||
| } | ||
| } | ||
| beforeEach(function() { | ||
| this.addMatchers(matchers); | ||
| }); | ||
| beforeEach(function () { | ||
| this.addMatchers(matchers) | ||
| switchJQueryState() | ||
| }) | ||
| afterEach(function () { | ||
| expect(disableJQueryUsage).toEqual(options.disableJQueryUsage) | ||
| }) | ||
| const KARMA_STRING = '__karma__' | ||
| let disableJQueryUsage = true | ||
| function switchJQueryState() { | ||
| if (window[KARMA_STRING] && window[KARMA_STRING].config.args.includes('--noJQuery')) { | ||
| options.disableJQueryUsage = disableJQueryUsage = true | ||
| } else { | ||
| options.disableJQueryUsage = disableJQueryUsage = false | ||
| } | ||
| } |
+2
-3
| { | ||
| "version": "4.0.0-beta1.3", | ||
| "version": "4.0.0", | ||
| "name": "@tko/utils", | ||
@@ -45,4 +45,3 @@ "description": "TKO Utilities", | ||
| "./helpers/*": "./helpers/*" | ||
| }, | ||
| "gitHead": "a8843acb8ae085915115e53a4e057b30731c635e" | ||
| } | ||
| } |
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| if (!Function.prototype["bind"]) { | ||
| Function.prototype["bind"] = function(object) { | ||
| var originalFunction = this; | ||
| if (arguments.length === 1) { | ||
| return function() { | ||
| return originalFunction.apply(object, arguments); | ||
| }; | ||
| } else { | ||
| var partialArgs = Array.prototype.slice.call(arguments, 1); | ||
| return function() { | ||
| var args = partialArgs.slice(0); | ||
| args.push.apply(args, arguments); | ||
| return originalFunction.apply(object, args); | ||
| }; | ||
| } | ||
| }; | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../src/bind-shim.ts"], | ||
| "sourcesContent": ["\nif (!Function.prototype['bind']) {\n // Shim/polyfill JavaScript Function.bind.\n // This implementation is based on the one in prototype.js\n Function.prototype['bind'] = function (object) {\n var originalFunction = this\n if (arguments.length === 1) {\n return function () {\n return originalFunction.apply(object, arguments)\n }\n } else {\n var partialArgs = Array.prototype.slice.call(arguments, 1)\n return function () {\n var args = partialArgs.slice(0)\n args.push.apply(args, arguments)\n return originalFunction.apply(object, args)\n }\n }\n }\n}\n"], | ||
| "mappings": ";AACA,IAAI,CAAC,SAAS,UAAU,SAAS;AAG/B,WAAS,UAAU,UAAU,SAAU,QAAQ;AAC7C,QAAI,mBAAmB;AACvB,QAAI,UAAU,WAAW,GAAG;AAC1B,aAAO,WAAY;AACjB,eAAO,iBAAiB,MAAM,QAAQ,SAAS;AAAA,MACjD;AAAA,IACF,OAAO;AACL,UAAI,cAAc,MAAM,UAAU,MAAM,KAAK,WAAW,CAAC;AACzD,aAAO,WAAY;AACjB,YAAI,OAAO,YAAY,MAAM,CAAC;AAC9B,aAAK,KAAK,MAAM,MAAM,SAAS;AAC/B,eAAO,iBAAiB,MAAM,QAAQ,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,EACF;AACF;", | ||
| "names": [] | ||
| } |
-15
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| import options from "./options"; | ||
| const ieVersion = options.document && function() { | ||
| var version = 3, div = options.document.createElement("div"), iElems = div.getElementsByTagName("i"); | ||
| while (div.innerHTML = "<!--[if gt IE " + ++version + "]><i></i><![endif]-->", iElems[0]) { | ||
| } | ||
| if (!version) { | ||
| const userAgent = window.navigator.userAgent; | ||
| return ua.match(/MSIE ([^ ]+)/) || ua.match(/rv:([^ )]+)/); | ||
| } | ||
| return version > 4 ? version : void 0; | ||
| }(); | ||
| const isIe6 = ieVersion === 6; | ||
| const isIe7 = ieVersion === 7; | ||
| export { ieVersion, isIe6, isIe7 }; |
| { | ||
| "version": 3, | ||
| "sources": ["../src/ie.ts"], | ||
| "sourcesContent": ["//\n// Detection and Workarounds for Internet Explorer\n//\nimport options from './options'\n\nconst ieVersion = options.document && (function () {\n var version = 3, div = options.document.createElement('div'), iElems = div.getElementsByTagName('i')\n\n // Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment\n while (\n div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->',\n iElems[0]\n ) {}\n\n if (!version) {\n const userAgent = window.navigator.userAgent\n // Detect IE 10/11\n return ua.match(/MSIE ([^ ]+)/) || ua.match(/rv:([^ )]+)/)\n }\n return version > 4 ? version : undefined\n}())\n\nconst isIe6 = ieVersion === 6\nconst isIe7 = ieVersion === 7\n\nexport { ieVersion, isIe6, isIe7 }\n"], | ||
| "mappings": ";AAGA;AAEA,MAAM,YAAY,QAAQ,YAAa,WAAY;AACjD,MAAI,UAAU,GAAG,MAAM,QAAQ,SAAS,cAAc,KAAK,GAAG,SAAS,IAAI,qBAAqB,GAAG;AAGnG,SACM,IAAI,YAAY,mBAAoB,EAAE,UAAW,yBACjD,OAAO,IACT;AAAA,EAAC;AAEL,MAAI,CAAC,SAAS;AACZ,UAAM,YAAY,OAAO,UAAU;AAEnC,WAAO,GAAG,MAAM,cAAc,KAAK,GAAG,MAAM,aAAa;AAAA,EAC3D;AACA,SAAO,UAAU,IAAI,UAAU;AACjC,EAAE;AAEF,MAAM,QAAQ,cAAc;AAC5B,MAAM,QAAQ,cAAc;AAE5B;", | ||
| "names": [] | ||
| } |
| // @tko/utils 🥊 4.0.0-beta1.3 ESM | ||
| import options from "./options"; | ||
| export var jQueryInstance = options.global && options.global.jQuery; | ||
| export function jQuerySetInstance(jquery) { | ||
| options.jQuery = jQueryInstance = jquery; | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../src/jquery.ts"], | ||
| "sourcesContent": ["//\n// jQuery\n//\n// TODO: deprecate in favour of options.$\n\nimport options from './options'\n\nexport var jQueryInstance = options.global && options.global.jQuery\n\nexport function jQuerySetInstance (jquery) {\n options.jQuery = jQueryInstance = jquery\n}\n"], | ||
| "mappings": ";AAKA;AAEO,WAAI,iBAAiB,QAAQ,UAAU,QAAQ,OAAO;AAEtD,kCAA4B,QAAQ;AACzC,UAAQ,SAAS,iBAAiB;AACpC;", | ||
| "names": [] | ||
| } |
-22
| The MIT License (MIT) - http://www.opensource.org/licenses/mit-license.php | ||
| Copyright (c) Steven Sanderson, the Knockout.js team, and other contributors | ||
| http://knockoutjs.com/ | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3022
1.41%0
-100%0
-100%280118
-2.59%48
-12.73%8
100%