@tko/utils 4.0.0-beta1.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/array.js +39 -35
  2. package/dist/array.js.map +2 -2
  3. package/dist/async.js +4 -3
  4. package/dist/async.js.map +2 -2
  5. package/dist/css.js +5 -4
  6. package/dist/css.js.map +2 -2
  7. package/dist/dom/data.js +36 -46
  8. package/dist/dom/data.js.map +2 -2
  9. package/dist/dom/disposal.js +23 -16
  10. package/dist/dom/disposal.js.map +2 -2
  11. package/dist/dom/event.js +39 -41
  12. package/dist/dom/event.js.map +2 -2
  13. package/dist/dom/fixes.js +5 -24
  14. package/dist/dom/fixes.js.map +2 -2
  15. package/dist/dom/html.js +46 -61
  16. package/dist/dom/html.js.map +2 -2
  17. package/dist/dom/info.js +10 -8
  18. package/dist/dom/info.js.map +2 -2
  19. package/dist/dom/manipulation.js +16 -24
  20. package/dist/dom/manipulation.js.map +2 -2
  21. package/dist/dom/selectExtensions.js +33 -23
  22. package/dist/dom/selectExtensions.js.map +2 -2
  23. package/dist/dom/virtualElements.js +40 -32
  24. package/dist/dom/virtualElements.js.map +3 -3
  25. package/dist/error.js +2 -1
  26. package/dist/error.js.map +2 -2
  27. package/dist/function.js +2 -1
  28. package/dist/function.js.map +2 -2
  29. package/dist/index.cjs +446 -449
  30. package/dist/index.cjs.map +4 -4
  31. package/dist/index.js +2 -3
  32. package/dist/index.js.map +2 -2
  33. package/dist/index.mjs +2 -3
  34. package/dist/index.mjs.map +2 -2
  35. package/dist/memoization.js +18 -13
  36. package/dist/memoization.js.map +3 -3
  37. package/dist/object.js +10 -8
  38. package/dist/object.js.map +2 -2
  39. package/dist/options.js +97 -35
  40. package/dist/options.js.map +2 -2
  41. package/dist/string.js +3 -5
  42. package/dist/string.js.map +2 -2
  43. package/dist/symbol.js +3 -2
  44. package/dist/symbol.js.map +2 -2
  45. package/dist/tasks.js +10 -20
  46. package/dist/tasks.js.map +2 -2
  47. package/helpers/jasmine-13-helper.ts +198 -147
  48. package/package.json +2 -3
  49. package/LICENSE +0 -22
  50. package/dist/bind-shim.js +0 -18
  51. package/dist/bind-shim.js.map +0 -7
  52. package/dist/ie.js +0 -15
  53. package/dist/ie.js.map +0 -7
  54. package/dist/jquery.js +0 -6
  55. package/dist/jquery.js.map +0 -7
package/dist/dom/event.js CHANGED
@@ -1,14 +1,11 @@
1
- // @tko/utils 🥊 4.0.0-beta1.3 ESM
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
2
3
  import { objectForEach } from "../object";
3
- import { jQueryInstance } from "../jquery";
4
- import { ieVersion } from "../ie";
5
4
  import { catchFunctionErrors } from "../error";
6
5
  import { tagNameLower } from "./info";
7
- import { addDisposeCallback } from "./disposal";
8
6
  import options from "../options";
9
- var knownEvents = {}, knownEventTypesByEventName = {};
10
- var keyEventTypeName = options.global.navigator && /Firefox\/2/i.test(options.global.navigator.userAgent) ? "KeyboardEvent" : "UIEvents";
11
- knownEvents[keyEventTypeName] = ["keyup", "keydown", "keypress"];
7
+ const knownEvents = {}, knownEventTypesByEventName = {};
8
+ knownEvents["UIEvents"] = ["keyup", "keydown", "keypress"];
12
9
  knownEvents["MouseEvents"] = [
13
10
  "click",
14
11
  "dblclick",
@@ -22,65 +19,66 @@ knownEvents["MouseEvents"] = [
22
19
  ];
23
20
  objectForEach(knownEvents, function(eventType, knownEventsForType) {
24
21
  if (knownEventsForType.length) {
25
- for (var i = 0, j = knownEventsForType.length; i < j; i++) {
22
+ for (let i = 0, j = knownEventsForType.length; i < j; i++) {
26
23
  knownEventTypesByEventName[knownEventsForType[i]] = eventType;
27
24
  }
28
25
  }
29
26
  });
30
27
  function isClickOnCheckableElement(element, eventType) {
31
- if (tagNameLower(element) !== "input" || !element.type)
32
- return false;
33
- if (eventType.toLowerCase() != "click")
34
- return false;
35
- var inputType = element.type;
28
+ if (tagNameLower(element) !== "input" || !element.type) return false;
29
+ if (eventType.toLowerCase() != "click") return false;
30
+ const inputType = element.type;
36
31
  return inputType == "checkbox" || inputType == "radio";
37
32
  }
38
- var eventsThatMustBeRegisteredUsingAttachEvent = { "propertychange": true };
39
- let jQueryEventAttachName;
40
33
  export function registerEventHandler(element, eventType, handler, eventOptions = false) {
41
34
  const wrappedHandler = catchFunctionErrors(handler);
42
- const mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];
43
35
  const mustUseNative = Boolean(eventOptions);
44
- if (!options.useOnlyNativeEvents && !mustUseAttachEvent && !mustUseNative && jQueryInstance) {
45
- if (!jQueryEventAttachName) {
46
- jQueryEventAttachName = typeof jQueryInstance(element).on === "function" ? "on" : "bind";
47
- }
48
- jQueryInstance(element)[jQueryEventAttachName](eventType, wrappedHandler);
49
- } else if (!mustUseAttachEvent && typeof element.addEventListener === "function") {
36
+ const jQuery = options.jQuery;
37
+ if (!options.useOnlyNativeEvents && !mustUseNative && jQuery) {
38
+ jQuery(element).on(eventType, wrappedHandler);
39
+ } else if (typeof element.addEventListener === "function") {
50
40
  element.addEventListener(eventType, wrappedHandler, eventOptions);
51
- } else if (typeof element.attachEvent !== "undefined") {
52
- const attachEventHandler = function(event) {
53
- wrappedHandler.call(element, event);
54
- };
55
- const attachEventName = "on" + eventType;
56
- element.attachEvent(attachEventName, attachEventHandler);
57
- addDisposeCallback(element, function() {
58
- element.detachEvent(attachEventName, attachEventHandler);
59
- });
60
41
  } else {
61
- throw new Error("Browser doesn't support addEventListener or attachEvent");
42
+ throw new Error("Browser doesn't support addEventListener");
62
43
  }
63
44
  }
45
+ function hasClick(element) {
46
+ return typeof element.click === "function";
47
+ }
64
48
  export function triggerEvent(element, eventType) {
65
49
  if (!(element && element.nodeType)) {
66
50
  throw new Error("element must be a DOM node when calling triggerEvent");
67
51
  }
68
- var useClickWorkaround = isClickOnCheckableElement(element, eventType);
69
- if (!options.useOnlyNativeEvents && jQueryInstance && !useClickWorkaround) {
70
- jQueryInstance(element).trigger(eventType);
52
+ const useClickWorkaround = isClickOnCheckableElement(element, eventType);
53
+ if (!options.useOnlyNativeEvents && options.jQuery && !useClickWorkaround) {
54
+ options.jQuery(element).trigger(eventType);
71
55
  } else if (typeof document.createEvent === "function") {
72
56
  if (typeof element.dispatchEvent === "function") {
73
- var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";
74
- var event = document.createEvent(eventCategory);
75
- event.initEvent(eventType, true, true, options.global, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
57
+ const eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";
58
+ const event = document.createEvent(eventCategory);
59
+ event.initEvent(
60
+ eventType,
61
+ true,
62
+ true,
63
+ options.global,
64
+ 0,
65
+ 0,
66
+ 0,
67
+ 0,
68
+ 0,
69
+ false,
70
+ false,
71
+ false,
72
+ false,
73
+ 0,
74
+ element
75
+ );
76
76
  element.dispatchEvent(event);
77
77
  } else {
78
78
  throw new Error("The supplied element doesn't support dispatchEvent");
79
79
  }
80
- } else if (useClickWorkaround && element.click) {
80
+ } else if (useClickWorkaround && hasClick(element)) {
81
81
  element.click();
82
- } else if (typeof element.fireEvent !== "undefined") {
83
- element.fireEvent("on" + eventType);
84
82
  } else {
85
83
  throw new Error("Browser doesn't support triggering events");
86
84
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/event.ts"],
4
- "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"],
5
- "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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C,QAAQ,uBAAuB,kBAAkB,CAAC,oBAAoB;AACzE,mBAAe,OAAO,EAAE,QAAQ,SAAS;AAAA,EAC3C,WAAW,OAAO,SAAS,gBAAgB,YAAY;AACrD,QAAI,OAAO,QAAQ,kBAAkB,YAAY;AAC/C,UAAI,gBAAgB,2BAA2B,cAAc;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;",
4
+ "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"],
5
+ "mappings": ";;AAIA,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAE7B,OAAO,aAAa;AAGpB,MAAM,cAAc,CAAC,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AI,CAAC,QAAQ,uBAAuB,QAAQ,UAAU,CAAC,oBAAoB;AACzE,YAAQ,OAAO,OAAO,EAAE,QAAQ,SAAS;AAAA,EAC3C,WAAW,OAAO,SAAS,gBAAgB,YAAY;AACrD,QAAI,OAAO,QAAQ,kBAAkB,YAAY;AAC/C,YAAM,gBAAgB,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;",
6
6
  "names": []
7
7
  }
package/dist/dom/fixes.js CHANGED
@@ -1,8 +1,8 @@
1
- // @tko/utils 🥊 4.0.0-beta1.3 ESM
2
- import { ieVersion } from "../ie";
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
3
3
  export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
4
4
  if (continuousNodeArray.length) {
5
- parentNode = parentNode.nodeType === 8 && parentNode.parentNode || parentNode;
5
+ parentNode = parentNode.nodeType === Node.COMMENT_NODE && parentNode.parentNode || parentNode;
6
6
  while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) {
7
7
  continuousNodeArray.splice(0, 1);
8
8
  }
@@ -10,7 +10,7 @@ export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
10
10
  continuousNodeArray.length--;
11
11
  }
12
12
  if (continuousNodeArray.length > 1) {
13
- var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1];
13
+ let current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1];
14
14
  continuousNodeArray.length = 0;
15
15
  while (current !== last) {
16
16
  continuousNodeArray.push(current);
@@ -22,24 +22,5 @@ export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
22
22
  return continuousNodeArray;
23
23
  }
24
24
  export function setOptionNodeSelectionState(optionNode, isSelected) {
25
- if (ieVersion < 7) {
26
- optionNode.setAttribute("selected", isSelected);
27
- } else {
28
- optionNode.selected = isSelected;
29
- }
30
- }
31
- export function forceRefresh(node) {
32
- if (ieVersion >= 9) {
33
- var elem = node.nodeType == 1 ? node : node.parentNode;
34
- if (elem.style) {
35
- elem.style.zoom = elem.style.zoom;
36
- }
37
- }
38
- }
39
- export function ensureSelectElementIsRenderedCorrectly(selectElement) {
40
- if (ieVersion) {
41
- var originalWidth = selectElement.style.width;
42
- selectElement.style.width = 0;
43
- selectElement.style.width = originalWidth;
44
- }
25
+ optionNode.selected = isSelected;
45
26
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/fixes.ts"],
4
- "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"],
5
- "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;",
4
+ "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"],
5
+ "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;",
6
6
  "names": []
7
7
  }
package/dist/dom/html.js CHANGED
@@ -1,73 +1,51 @@
1
- // @tko/utils 🥊 4.0.0-beta1.3 ESM
2
- import { stringTrim } from "../string";
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
3
3
  import { makeArray } from "../array";
4
4
  import { emptyDomNode, moveCleanedNodesToContainerElement } from "./manipulation";
5
- import { jQueryInstance } from "../jquery";
6
- import { forceRefresh } from "./fixes";
7
5
  import * as virtualElements from "./virtualElements";
8
6
  import options from "../options";
9
- 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 = {
10
- "area": map,
11
- "col": colgroup,
12
- "colgroup": table,
13
- "caption": table,
14
- "legend": fieldset,
15
- "thead": table,
16
- "tbody": table,
17
- "tfoot": table,
18
- "tr": tbody,
19
- "td": tr,
20
- "th": tr,
21
- "option": select,
22
- "optgroup": select,
23
- "param": object
24
- }, supportsTemplateTag = options.document && "content" in options.document.createElement("template");
25
- function getWrap(tags) {
26
- const m = tags.match(/^(?:<!--.*?-->\s*?)*?<([a-z]+)[\s>]/);
27
- return m && lookup[m[1]] || none;
28
- }
7
+ const supportsTemplateTag = options.useTemplateTag && options.document && "content" in options.document.createElement("template");
29
8
  function simpleHtmlParse(html, documentContext) {
30
- documentContext || (documentContext = document);
31
- var windowContext = documentContext["parentWindow"] || documentContext["defaultView"] || window;
32
- var tags = stringTrim(html).toLowerCase(), div = documentContext.createElement("div"), wrap = getWrap(tags), depth = wrap[0];
33
- var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
34
- if (typeof windowContext["innerShiv"] === "function") {
35
- div.appendChild(windowContext["innerShiv"](markup));
36
- } else {
37
- div.innerHTML = markup;
38
- }
39
- while (depth--) {
40
- div = div.lastChild;
9
+ if (!documentContext) {
10
+ documentContext = document;
41
11
  }
42
- return makeArray(div.lastChild.childNodes);
12
+ const div = documentContext.createElement("div");
13
+ div.innerHTML = html;
14
+ return makeArray(div.childNodes);
43
15
  }
44
16
  function templateHtmlParse(html, documentContext) {
45
17
  if (!documentContext) {
46
18
  documentContext = document;
47
19
  }
48
- var template = documentContext.createElement("template");
20
+ const template = documentContext.createElement("template");
49
21
  template.innerHTML = html;
50
22
  return makeArray(template.content.childNodes);
51
23
  }
52
24
  function jQueryHtmlParse(html, documentContext) {
53
- if (jQueryInstance.parseHTML) {
54
- return jQueryInstance.parseHTML(html, documentContext) || [];
55
- } else {
56
- var elems = jQueryInstance.clean([html], documentContext);
57
- if (elems && elems[0]) {
58
- var elem = elems[0];
59
- while (elem.parentNode && elem.parentNode.nodeType !== 11) {
60
- elem = elem.parentNode;
61
- }
62
- if (elem.parentNode) {
63
- elem.parentNode.removeChild(elem);
64
- }
65
- }
66
- return elems;
25
+ const jQuery = options.jQuery;
26
+ if (jQuery) {
27
+ return jQuery.parseHTML(html, documentContext) || [];
67
28
  }
29
+ return [];
68
30
  }
69
31
  export function parseHtmlFragment(html, documentContext) {
70
- return supportsTemplateTag ? templateHtmlParse(html, documentContext) : jQueryInstance ? jQueryHtmlParse(html, documentContext) : simpleHtmlParse(html, documentContext);
32
+ const saferHtml = validateHTMLInput(html);
33
+ if (supportsTemplateTag) return templateHtmlParse(saferHtml, documentContext);
34
+ if (options.jQuery) {
35
+ return jQueryHtmlParse(saferHtml, documentContext);
36
+ }
37
+ return simpleHtmlParse(saferHtml, documentContext);
38
+ }
39
+ const scriptTagPattern = /<script\b[^>]*>([\s\S]*?)<\/script[^>]*>/i;
40
+ function validateHTMLInput(html) {
41
+ if (!html) return "";
42
+ if (options.templateSizeLimit > 0 && html.length > options.templateSizeLimit) {
43
+ throw new Error("Template is too long. Please configure the 'templateSizeLimit'");
44
+ }
45
+ if (!options.allowScriptTagsInTemplates && scriptTagPattern.test(html)) {
46
+ throw new Error("Script-tag in template detected.");
47
+ }
48
+ return options.sanitizeHtmlTemplate(html);
71
49
  }
72
50
  export function parseHtmlForTemplateNodes(html, documentContext) {
73
51
  const nodes = parseHtmlFragment(html, documentContext);
@@ -82,18 +60,25 @@ export function setHtml(node, html) {
82
60
  if (typeof html !== "string") {
83
61
  html = html.toString();
84
62
  }
85
- if (jQueryInstance && !supportsTemplateTag) {
86
- jQueryInstance(node).html(html);
63
+ const jQuery = options.jQuery;
64
+ if (jQuery && !supportsTemplateTag) {
65
+ const saferHtml = validateHTMLInput(html);
66
+ jQuery(node).html(saferHtml);
87
67
  } else {
88
- var parsedNodes = parseHtmlFragment(html, node.ownerDocument);
89
- if (node.nodeType === 8) {
68
+ let parsedNodes;
69
+ if (node.ownerDocument) {
70
+ parsedNodes = parseHtmlFragment(html, node.ownerDocument);
71
+ } else {
72
+ parsedNodes = parseHtmlFragment(html);
73
+ }
74
+ if (node.nodeType === Node.COMMENT_NODE) {
90
75
  if (html === null) {
91
76
  virtualElements.emptyNode(node);
92
77
  } else {
93
78
  virtualElements.setDomNodeChildren(node, parsedNodes);
94
79
  }
95
80
  } else {
96
- for (var i = 0; i < parsedNodes.length; i++) {
81
+ for (let i = 0; i < parsedNodes.length; i++) {
97
82
  node.appendChild(parsedNodes[i]);
98
83
  }
99
84
  }
@@ -101,15 +86,15 @@ export function setHtml(node, html) {
101
86
  }
102
87
  }
103
88
  export function setTextContent(element, textContent) {
104
- var value = typeof textContent === "function" ? textContent() : textContent;
89
+ let value = typeof textContent === "function" ? textContent() : textContent;
105
90
  if (value === null || value === void 0) {
106
91
  value = "";
107
92
  }
108
- var innerTextNode = virtualElements.firstChild(element);
109
- if (!innerTextNode || innerTextNode.nodeType != 3 || virtualElements.nextSibling(innerTextNode)) {
93
+ const innerTextNode = virtualElements.firstChild(element);
94
+ if (!innerTextNode || innerTextNode.nodeType !== Node.TEXT_NODE || virtualElements.nextSibling(innerTextNode)) {
110
95
  virtualElements.setDomNodeChildren(element, [element.ownerDocument.createTextNode(value)]);
111
96
  } else {
97
+ ;
112
98
  innerTextNode.data = value;
113
99
  }
114
- forceRefresh(element);
115
100
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/html.ts"],
4
- "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"],
5
- "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,S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BAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;AAAE,eAAK,YAAY,YAAY,EAAE;AAAA,QAAE;AAAA,MAClF;AAAA,IACF;AAAA,EACF;AACF;AAGO,+BAAyB,SAAS,aAAa;AACpD,MAAI,QAAQ,OAAO,gBAAgB,aAAa,YAAY,IAAI;AAChE,MAAK,UAAU,QAAU,UAAU,QAAY;AAAE,YAAQ;AAAA,EAAG;AAK5D,MAAI,gBAAgB,gBAAgB,WAAW,OAAO;AACtD,MAAI,CAAC,iBAAiB,cAAc,YAAY,KAAK,gBAAgB,YAAY,aAAa,GAAG;AAC/F,oBAAgB,mBAAmB,SAAS,CAAC,QAAQ,cAAc,eAAe,KAAK,CAAC,CAAC;AAAA,EAC3F,OAAO;AACL,kBAAc,OAAO;AAAA,EACvB;AAEA,eAAa,OAAO;AACtB;",
4
+ "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"],
5
+ "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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names": []
7
7
  }
package/dist/dom/info.js CHANGED
@@ -1,22 +1,24 @@
1
- // @tko/utils 🥊 4.0.0-beta1.3 ESM
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
2
3
  import { arrayFirst } from "../array";
3
4
  export function domNodeIsContainedBy(node, containedByNode) {
4
5
  if (node === containedByNode) {
5
6
  return true;
6
7
  }
7
- if (node.nodeType === 11) {
8
+ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
8
9
  return false;
9
10
  }
10
11
  if (containedByNode.contains) {
11
- return containedByNode.contains(node.nodeType !== 1 ? node.parentNode : node);
12
+ return containedByNode.contains(node.nodeType !== Node.ELEMENT_NODE ? node.parentNode : node);
12
13
  }
13
14
  if (containedByNode.compareDocumentPosition) {
14
15
  return (containedByNode.compareDocumentPosition(node) & 16) == 16;
15
16
  }
16
- while (node && node != containedByNode) {
17
- node = node.parentNode;
17
+ let parentNode = node;
18
+ while (parentNode && parentNode != containedByNode) {
19
+ parentNode = parentNode.parentNode;
18
20
  }
19
- return !!node;
21
+ return !!parentNode;
20
22
  }
21
23
  export function domNodeIsAttachedToDocument(node) {
22
24
  return domNodeIsContainedBy(node, node.ownerDocument.documentElement);
@@ -31,13 +33,13 @@ export function isDomElement(obj) {
31
33
  if (window.HTMLElement) {
32
34
  return obj instanceof HTMLElement;
33
35
  } else {
34
- return obj && obj.tagName && obj.nodeType === 1;
36
+ return obj && obj.tagName && obj.nodeType === Node.ELEMENT_NODE;
35
37
  }
36
38
  }
37
39
  export function isDocumentFragment(obj) {
38
40
  if (window.DocumentFragment) {
39
41
  return obj instanceof DocumentFragment;
40
42
  } else {
41
- return obj && obj.nodeType === 11;
43
+ return obj && obj.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
42
44
  }
43
45
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/info.ts"],
4
- "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"],
5
- "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;",
4
+ "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"],
5
+ "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;",
6
6
  "names": []
7
7
  }
@@ -1,19 +1,20 @@
1
- // @tko/utils 🥊 4.0.0-beta1.3 ESM
1
+ // @tko/utils 🥊 4.0.0 ESM
2
+ "use strict";
2
3
  import { makeArray } from "../array";
3
- import { ieVersion } from "../ie";
4
4
  import { cleanNode, removeNode } from "./disposal";
5
5
  export function moveCleanedNodesToContainerElement(nodes) {
6
- var nodesArray = makeArray(nodes);
7
- var templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document;
8
- var container = templateDocument.createElement("div");
9
- for (var i = 0, j = nodesArray.length; i < j; i++) {
6
+ const nodesArray = makeArray(nodes);
7
+ const templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document;
8
+ const container = templateDocument.createElement("div");
9
+ for (let i = 0, j = nodesArray.length; i < j; i++) {
10
10
  container.appendChild(cleanNode(nodesArray[i]));
11
11
  }
12
12
  return container;
13
13
  }
14
14
  export function cloneNodes(nodesArray, shouldCleanNodes) {
15
- for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) {
16
- var clonedNode = nodesArray[i].cloneNode(true);
15
+ const newNodesArray = new Array();
16
+ for (let i = 0; i < nodesArray.length; i++) {
17
+ const clonedNode = nodesArray[i].cloneNode(true);
17
18
  newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode);
18
19
  }
19
20
  return newNodesArray;
@@ -21,33 +22,24 @@ export function cloneNodes(nodesArray, shouldCleanNodes) {
21
22
  export function setDomNodeChildren(domNode, childNodes) {
22
23
  emptyDomNode(domNode);
23
24
  if (childNodes) {
24
- for (var i = 0, j = childNodes.length; i < j; i++) {
25
+ for (let i = 0; i < childNodes.length; i++) {
25
26
  domNode.appendChild(childNodes[i]);
26
27
  }
27
28
  }
28
29
  }
29
30
  export function replaceDomNodes(nodeToReplaceOrNodeArray, newNodesArray) {
30
- var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;
31
+ const nodesToReplaceArray = Array.isArray(nodeToReplaceOrNodeArray) ? nodeToReplaceOrNodeArray : [nodeToReplaceOrNodeArray];
31
32
  if (nodesToReplaceArray.length > 0) {
32
- var insertionPoint = nodesToReplaceArray[0];
33
- var parent = insertionPoint.parentNode;
34
- for (var i = 0, j = newNodesArray.length; i < j; i++) {
35
- parent.insertBefore(newNodesArray[i], insertionPoint);
33
+ const insertionPoint = nodesToReplaceArray[0];
34
+ const parent = insertionPoint.parentNode;
35
+ for (let i = 0; i < newNodesArray.length; i++) {
36
+ parent?.insertBefore(newNodesArray[i], insertionPoint);
36
37
  }
37
- for (i = 0, j = nodesToReplaceArray.length; i < j; i++) {
38
+ for (let i = 0; i < nodesToReplaceArray.length; i++) {
38
39
  removeNode(nodesToReplaceArray[i]);
39
40
  }
40
41
  }
41
42
  }
42
- export function setElementName(element, name) {
43
- element.name = name;
44
- if (ieVersion <= 7) {
45
- try {
46
- element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false);
47
- } catch (e) {
48
- }
49
- }
50
- }
51
43
  export function emptyDomNode(domNode) {
52
44
  while (domNode.firstChild) {
53
45
  removeNode(domNode.firstChild);