@tko/utils 4.0.0-alpha8.0 → 4.0.0-beta1.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 (58) hide show
  1. package/dist/array.js +156 -0
  2. package/dist/array.js.map +7 -0
  3. package/dist/async.js +20 -0
  4. package/dist/async.js.map +7 -0
  5. package/dist/bind-shim.js +18 -0
  6. package/dist/bind-shim.js.map +7 -0
  7. package/dist/css.js +27 -0
  8. package/dist/css.js.map +7 -0
  9. package/dist/dom/data.js +63 -0
  10. package/dist/dom/data.js.map +7 -0
  11. package/dist/dom/disposal.js +98 -0
  12. package/dist/dom/disposal.js.map +7 -0
  13. package/dist/dom/event.js +87 -0
  14. package/dist/dom/event.js.map +7 -0
  15. package/dist/dom/fixes.js +45 -0
  16. package/dist/dom/fixes.js.map +7 -0
  17. package/dist/dom/html.js +115 -0
  18. package/dist/dom/html.js.map +7 -0
  19. package/dist/dom/info.js +43 -0
  20. package/dist/dom/info.js.map +7 -0
  21. package/dist/dom/manipulation.js +55 -0
  22. package/dist/dom/manipulation.js.map +7 -0
  23. package/dist/dom/selectExtensions.js +62 -0
  24. package/dist/dom/selectExtensions.js.map +7 -0
  25. package/dist/dom/virtualElements.js +202 -0
  26. package/dist/dom/virtualElements.js.map +7 -0
  27. package/dist/error.js +22 -0
  28. package/dist/error.js.map +7 -0
  29. package/dist/function.js +16 -0
  30. package/dist/function.js.map +7 -0
  31. package/dist/ie.js +15 -0
  32. package/dist/ie.js.map +7 -0
  33. package/dist/index.cjs +1448 -0
  34. package/dist/index.cjs.map +7 -0
  35. package/dist/index.js +24 -0
  36. package/dist/index.js.map +7 -0
  37. package/dist/index.mjs +24 -0
  38. package/dist/index.mjs.map +7 -0
  39. package/dist/jquery.js +6 -0
  40. package/dist/jquery.js.map +7 -0
  41. package/dist/memoization.js +64 -0
  42. package/dist/memoization.js.map +7 -0
  43. package/dist/object.js +76 -0
  44. package/dist/object.js.map +7 -0
  45. package/dist/options.js +36 -0
  46. package/dist/options.js.map +7 -0
  47. package/dist/string.js +23 -0
  48. package/dist/string.js.map +7 -0
  49. package/dist/symbol.js +5 -0
  50. package/dist/symbol.js.map +7 -0
  51. package/dist/tasks.js +76 -0
  52. package/dist/tasks.js.map +7 -0
  53. package/helpers/{jasmine-13-helper.js → jasmine-13-helper.ts} +1 -1
  54. package/package.json +15 -25
  55. package/dist/utils.es6.js +0 -1628
  56. package/dist/utils.es6.js.map +0 -1
  57. package/dist/utils.js +0 -1645
  58. package/dist/utils.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,115 @@
1
+ // @tko/utils 🥊 4.0.0-beta1.0 ESM
2
+ import { stringTrim } from "../string";
3
+ import { makeArray } from "../array";
4
+ import { emptyDomNode, moveCleanedNodesToContainerElement } from "./manipulation";
5
+ import { jQueryInstance } from "../jquery";
6
+ import { forceRefresh } from "./fixes";
7
+ import * as virtualElements from "./virtualElements";
8
+ 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
+ }
29
+ 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;
41
+ }
42
+ return makeArray(div.lastChild.childNodes);
43
+ }
44
+ function templateHtmlParse(html, documentContext) {
45
+ if (!documentContext) {
46
+ documentContext = document;
47
+ }
48
+ var template = documentContext.createElement("template");
49
+ template.innerHTML = html;
50
+ return makeArray(template.content.childNodes);
51
+ }
52
+ 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;
67
+ }
68
+ }
69
+ export function parseHtmlFragment(html, documentContext) {
70
+ return supportsTemplateTag ? templateHtmlParse(html, documentContext) : jQueryInstance ? jQueryHtmlParse(html, documentContext) : simpleHtmlParse(html, documentContext);
71
+ }
72
+ export function parseHtmlForTemplateNodes(html, documentContext) {
73
+ const nodes = parseHtmlFragment(html, documentContext);
74
+ return nodes.length && nodes[0].parentElement || moveCleanedNodesToContainerElement(nodes);
75
+ }
76
+ export function setHtml(node, html) {
77
+ emptyDomNode(node);
78
+ if (typeof html === "function") {
79
+ html = html();
80
+ }
81
+ if (html !== null && html !== void 0) {
82
+ if (typeof html !== "string") {
83
+ html = html.toString();
84
+ }
85
+ if (jQueryInstance && !supportsTemplateTag) {
86
+ jQueryInstance(node).html(html);
87
+ } else {
88
+ var parsedNodes = parseHtmlFragment(html, node.ownerDocument);
89
+ if (node.nodeType === 8) {
90
+ if (html === null) {
91
+ virtualElements.emptyNode(node);
92
+ } else {
93
+ virtualElements.setDomNodeChildren(node, parsedNodes);
94
+ }
95
+ } else {
96
+ for (var i = 0; i < parsedNodes.length; i++) {
97
+ node.appendChild(parsedNodes[i]);
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ export function setTextContent(element, textContent) {
104
+ var value = typeof textContent === "function" ? textContent() : textContent;
105
+ if (value === null || value === void 0) {
106
+ value = "";
107
+ }
108
+ var innerTextNode = virtualElements.firstChild(element);
109
+ if (!innerTextNode || innerTextNode.nodeType != 3 || virtualElements.nextSibling(innerTextNode)) {
110
+ virtualElements.setDomNodeChildren(element, [element.ownerDocument.createTextNode(value)]);
111
+ } else {
112
+ innerTextNode.data = value;
113
+ }
114
+ forceRefresh(element);
115
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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": "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",
6
+ "names": []
7
+ }
@@ -0,0 +1,43 @@
1
+ // @tko/utils 🥊 4.0.0-beta1.0 ESM
2
+ import { arrayFirst } from "../array";
3
+ export function domNodeIsContainedBy(node, containedByNode) {
4
+ if (node === containedByNode) {
5
+ return true;
6
+ }
7
+ if (node.nodeType === 11) {
8
+ return false;
9
+ }
10
+ if (containedByNode.contains) {
11
+ return containedByNode.contains(node.nodeType !== 1 ? node.parentNode : node);
12
+ }
13
+ if (containedByNode.compareDocumentPosition) {
14
+ return (containedByNode.compareDocumentPosition(node) & 16) == 16;
15
+ }
16
+ while (node && node != containedByNode) {
17
+ node = node.parentNode;
18
+ }
19
+ return !!node;
20
+ }
21
+ export function domNodeIsAttachedToDocument(node) {
22
+ return domNodeIsContainedBy(node, node.ownerDocument.documentElement);
23
+ }
24
+ export function anyDomNodeIsAttachedToDocument(nodes) {
25
+ return !!arrayFirst(nodes, domNodeIsAttachedToDocument);
26
+ }
27
+ export function tagNameLower(element) {
28
+ return element && element.tagName && element.tagName.toLowerCase();
29
+ }
30
+ export function isDomElement(obj) {
31
+ if (window.HTMLElement) {
32
+ return obj instanceof HTMLElement;
33
+ } else {
34
+ return obj && obj.tagName && obj.nodeType === 1;
35
+ }
36
+ }
37
+ export function isDocumentFragment(obj) {
38
+ if (window.DocumentFragment) {
39
+ return obj instanceof DocumentFragment;
40
+ } else {
41
+ return obj && obj.nodeType === 11;
42
+ }
43
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,55 @@
1
+ // @tko/utils 🥊 4.0.0-beta1.0 ESM
2
+ import { makeArray } from "../array";
3
+ import { ieVersion } from "../ie";
4
+ import { cleanNode, removeNode } from "./disposal";
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++) {
10
+ container.appendChild(cleanNode(nodesArray[i]));
11
+ }
12
+ return container;
13
+ }
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);
17
+ newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode);
18
+ }
19
+ return newNodesArray;
20
+ }
21
+ export function setDomNodeChildren(domNode, childNodes) {
22
+ emptyDomNode(domNode);
23
+ if (childNodes) {
24
+ for (var i = 0, j = childNodes.length; i < j; i++) {
25
+ domNode.appendChild(childNodes[i]);
26
+ }
27
+ }
28
+ }
29
+ export function replaceDomNodes(nodeToReplaceOrNodeArray, newNodesArray) {
30
+ var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;
31
+ 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);
36
+ }
37
+ for (i = 0, j = nodesToReplaceArray.length; i < j; i++) {
38
+ removeNode(nodesToReplaceArray[i]);
39
+ }
40
+ }
41
+ }
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
+ export function emptyDomNode(domNode) {
52
+ while (domNode.firstChild) {
53
+ removeNode(domNode.firstChild);
54
+ }
55
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/dom/manipulation.ts"],
4
+ "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\"\n }\n}\n\nexport function emptyDomNode (domNode) {\n while (domNode.firstChild) {\n removeNode(domNode.firstChild)\n }\n}\n"],
5
+ "mappings": ";AAIA;AACA;AACA;AAEO,mDAA6C,OAAO;AAGzD,MAAI,aAAa,UAAU,KAAK;AAChC,MAAI,mBAAoB,WAAW,MAAM,WAAW,GAAG,iBAAkB;AAEzE,MAAI,YAAY,iBAAiB,cAAc,KAAK;AACpD,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,IAAI,GAAG,KAAK;AACjD,cAAU,YAAY,UAAU,WAAW,EAAE,CAAC;AAAA,EAChD;AACA,SAAO;AACT;AAEO,2BAAqB,YAAY,kBAAkB;AACxD,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,gBAAgB,CAAC,GAAG,IAAI,GAAG,KAAK;AACrE,QAAI,aAAa,WAAW,GAAG,UAAU,IAAI;AAC7C,kBAAc,KAAK,mBAAmB,UAAU,UAAU,IAAI,UAAU;AAAA,EAC1E;AACA,SAAO;AACT;AAEO,mCAA6B,SAAS,YAAY;AACvD,eAAa,OAAO;AACpB,MAAI,YAAY;AACd,aAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,IAAI,GAAG,KAAK;AAAE,cAAQ,YAAY,WAAW,EAAE;AAAA,IAAE;AAAA,EAC1F;AACF;AAEO,gCAA0B,0BAA0B,eAAe;AACxE,MAAI,sBAAsB,yBAAyB,WAAW,CAAC,wBAAwB,IAAI;AAC3F,MAAI,oBAAoB,SAAS,GAAG;AAClC,QAAI,iBAAiB,oBAAoB;AACzC,QAAI,SAAS,eAAe;AAC5B,aAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,IAAI,GAAG,KAAK;AAAE,aAAO,aAAa,cAAc,IAAI,cAAc;AAAA,IAAE;AAC9G,SAAK,IAAI,GAAG,IAAI,oBAAoB,QAAQ,IAAI,GAAG,KAAK;AACtD,iBAAW,oBAAoB,EAAE;AAAA,IACnC;AAAA,EACF;AACF;AAEO,+BAAyB,SAAS,MAAM;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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,62 @@
1
+ // @tko/utils 🥊 4.0.0-beta1.0 ESM
2
+ import { tagNameLower } from "./info";
3
+ import * as domData from "./data";
4
+ var hasDomDataExpandoProperty = Symbol("Knockout selectExtensions hasDomDataProperty");
5
+ export var selectExtensions = {
6
+ optionValueDomDataKey: domData.nextKey(),
7
+ readValue: function(element) {
8
+ switch (tagNameLower(element)) {
9
+ case "option":
10
+ if (element[hasDomDataExpandoProperty] === true) {
11
+ return domData.get(element, selectExtensions.optionValueDomDataKey);
12
+ }
13
+ return element.value;
14
+ case "select":
15
+ return element.selectedIndex >= 0 ? selectExtensions.readValue(element.options[element.selectedIndex]) : void 0;
16
+ default:
17
+ return element.value;
18
+ }
19
+ },
20
+ writeValue: function(element, value, allowUnset) {
21
+ switch (tagNameLower(element)) {
22
+ case "option":
23
+ if (typeof value === "string") {
24
+ domData.set(element, selectExtensions.optionValueDomDataKey, void 0);
25
+ if (hasDomDataExpandoProperty in element) {
26
+ delete element[hasDomDataExpandoProperty];
27
+ }
28
+ element.value = value;
29
+ } else {
30
+ domData.set(element, selectExtensions.optionValueDomDataKey, value);
31
+ element[hasDomDataExpandoProperty] = true;
32
+ element.value = typeof value === "number" ? value : "";
33
+ }
34
+ break;
35
+ case "select":
36
+ if (value === "" || value === null) {
37
+ value = void 0;
38
+ }
39
+ var selection = -1;
40
+ for (let i = 0, n = element.options.length, optionValue; i < n; ++i) {
41
+ optionValue = selectExtensions.readValue(element.options[i]);
42
+ const strictEqual = optionValue === value;
43
+ const blankEqual = optionValue === "" && value === void 0;
44
+ const numericEqual = typeof value === "number" && Number(optionValue) === value;
45
+ if (strictEqual || blankEqual || numericEqual) {
46
+ selection = i;
47
+ break;
48
+ }
49
+ }
50
+ if (allowUnset || selection >= 0 || value === void 0 && element.size > 1) {
51
+ element.selectedIndex = selection;
52
+ }
53
+ break;
54
+ default:
55
+ if (value === null || value === void 0) {
56
+ value = "";
57
+ }
58
+ element.value = value;
59
+ break;
60
+ }
61
+ }
62
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/dom/selectExtensions.ts"],
4
+ "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"],
5
+ "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;AACH,YAAI,QAAQ,+BAA+B,MAAM;AAAE,iBAAO,QAAQ,IAAI,SAAS,iBAAiB,qBAAqB;AAAA,QAAE;AACvH,eAAO,QAAQ;AAAA,WACZ;AACH,eAAO,QAAQ,iBAAiB,IAAI,iBAAiB,UAAU,QAAQ,QAAQ,QAAQ,cAAc,IAAI;AAAA;AAEzG,eAAO,QAAQ;AAAA;AAAA,EAErB;AAAA,EAEA,YAAY,SAAU,SAAS,OAAO,YAAY;AAChD,YAAQ,aAAa,OAAO;AAAA,WACrB;AACH,YAAI,OAAO,UAAU,UAAU;AAC7B,kBAAQ,IAAI,SAAS,iBAAiB,uBAAuB,MAAS;AACtE,cAAI,6BAA6B,SAAS;AACxC,mBAAO,QAAQ;AAAA,UACjB;AACA,kBAAQ,QAAQ;AAAA,QAClB,OAAO;AAEL,kBAAQ,IAAI,SAAS,iBAAiB,uBAAuB,KAAK;AAClE,kBAAQ,6BAA6B;AAErC,kBAAQ,QAAQ,OAAO,UAAU,WAAW,QAAQ;AAAA,QACtD;AAEA;AAAA,WACG;AACH,YAAI,UAAU,MAAM,UAAU,MAAM;AAElC,kBAAQ;AAAA,QACV;AACA,YAAI,YAAY;AAChB,iBAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,QAAQ,aAAa,IAAI,GAAG,EAAE,GAAG;AACnE,wBAAc,iBAAiB,UAAU,QAAQ,QAAQ,EAAE;AAG3D,gBAAM,cAAc,gBAAgB;AACpC,gBAAM,aAAa,gBAAgB,MAAM,UAAU;AACnD,gBAAM,eAAe,OAAO,UAAU,YAAY,OAAO,WAAW,MAAM;AAC1E,cAAI,eAAe,cAAc,cAAc;AAC7C,wBAAY;AACZ;AAAA,UACF;AAAA,QACF;AACA,YAAI,cAAc,aAAa,KAAM,UAAU,UAAa,QAAQ,OAAO,GAAI;AAC7E,kBAAQ,gBAAgB;AAAA,QAC1B;AACA;AAAA;AAEA,YAAK,UAAU,QAAU,UAAU,QAAY;AAAE,kBAAQ;AAAA,QAAG;AAC5D,gBAAQ,QAAQ;AAChB;AAAA;AAAA,EAEN;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,202 @@
1
+ // @tko/utils 🥊 4.0.0-beta1.0 ESM
2
+ import { emptyDomNode, setDomNodeChildren as setRegularDomNodeChildren } from "./manipulation";
3
+ import { removeNode } from "./disposal";
4
+ import { tagNameLower } from "./info";
5
+ import * as domData from "./data";
6
+ import options from "../options";
7
+ var commentNodesHaveTextProperty = options.document && options.document.createComment("test").text === "<!--test-->";
8
+ export var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+([\s\S]+))?\s*-->$/ : /^\s*ko(?:\s+([\s\S]+))?\s*$/;
9
+ export var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/;
10
+ var htmlTagsWithOptionallyClosingChildren = { "ul": true, "ol": true };
11
+ export function isStartComment(node) {
12
+ return node.nodeType == 8 && startCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue);
13
+ }
14
+ export function isEndComment(node) {
15
+ return node.nodeType == 8 && endCommentRegex.test(commentNodesHaveTextProperty ? node.text : node.nodeValue);
16
+ }
17
+ function isUnmatchedEndComment(node) {
18
+ return isEndComment(node) && !domData.get(node, matchedEndCommentDataKey);
19
+ }
20
+ const matchedEndCommentDataKey = "__ko_matchedEndComment__";
21
+ export function getVirtualChildren(startComment, allowUnbalanced) {
22
+ var currentNode = startComment;
23
+ var depth = 1;
24
+ var children = [];
25
+ while (currentNode = currentNode.nextSibling) {
26
+ if (isEndComment(currentNode)) {
27
+ domData.set(currentNode, matchedEndCommentDataKey, true);
28
+ depth--;
29
+ if (depth === 0) {
30
+ return children;
31
+ }
32
+ }
33
+ children.push(currentNode);
34
+ if (isStartComment(currentNode)) {
35
+ depth++;
36
+ }
37
+ }
38
+ if (!allowUnbalanced) {
39
+ throw new Error("Cannot find closing comment tag to match: " + startComment.nodeValue);
40
+ }
41
+ return null;
42
+ }
43
+ function getMatchingEndComment(startComment, allowUnbalanced) {
44
+ var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced);
45
+ if (allVirtualChildren) {
46
+ if (allVirtualChildren.length > 0) {
47
+ return allVirtualChildren[allVirtualChildren.length - 1].nextSibling;
48
+ }
49
+ return startComment.nextSibling;
50
+ } else {
51
+ return null;
52
+ }
53
+ }
54
+ function getUnbalancedChildTags(node) {
55
+ var childNode = node.firstChild, captureRemaining = null;
56
+ if (childNode) {
57
+ do {
58
+ if (captureRemaining) {
59
+ captureRemaining.push(childNode);
60
+ } else if (isStartComment(childNode)) {
61
+ var matchingEndComment = getMatchingEndComment(childNode, true);
62
+ if (matchingEndComment) {
63
+ childNode = matchingEndComment;
64
+ } else {
65
+ captureRemaining = [childNode];
66
+ }
67
+ } else if (isEndComment(childNode)) {
68
+ captureRemaining = [childNode];
69
+ }
70
+ } while (childNode = childNode.nextSibling);
71
+ }
72
+ return captureRemaining;
73
+ }
74
+ export var allowedBindings = {};
75
+ export var hasBindingValue = isStartComment;
76
+ export function childNodes(node) {
77
+ return isStartComment(node) ? getVirtualChildren(node) : node.childNodes;
78
+ }
79
+ export function emptyNode(node) {
80
+ if (!isStartComment(node)) {
81
+ emptyDomNode(node);
82
+ } else {
83
+ var virtualChildren = childNodes(node);
84
+ for (var i = 0, j = virtualChildren.length; i < j; i++) {
85
+ removeNode(virtualChildren[i]);
86
+ }
87
+ }
88
+ }
89
+ export function setDomNodeChildren(node, childNodes2) {
90
+ if (!isStartComment(node)) {
91
+ setRegularDomNodeChildren(node, childNodes2);
92
+ } else {
93
+ emptyNode(node);
94
+ const endCommentNode = node.nextSibling;
95
+ const parentNode = endCommentNode.parentNode;
96
+ for (var i = 0, j = childNodes2.length; i < j; ++i) {
97
+ parentNode.insertBefore(childNodes2[i], endCommentNode);
98
+ }
99
+ }
100
+ }
101
+ export function prepend(containerNode, nodeToPrepend) {
102
+ if (!isStartComment(containerNode)) {
103
+ if (containerNode.firstChild) {
104
+ containerNode.insertBefore(nodeToPrepend, containerNode.firstChild);
105
+ } else {
106
+ containerNode.appendChild(nodeToPrepend);
107
+ }
108
+ } else {
109
+ containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling);
110
+ }
111
+ }
112
+ export function insertAfter(containerNode, nodeToInsert, insertAfterNode) {
113
+ if (!insertAfterNode) {
114
+ prepend(containerNode, nodeToInsert);
115
+ } else if (!isStartComment(containerNode)) {
116
+ if (insertAfterNode.nextSibling) {
117
+ containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
118
+ } else {
119
+ containerNode.appendChild(nodeToInsert);
120
+ }
121
+ } else {
122
+ containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
123
+ }
124
+ }
125
+ export function firstChild(node) {
126
+ if (!isStartComment(node)) {
127
+ if (node.firstChild && isEndComment(node.firstChild)) {
128
+ throw new Error("Found invalid end comment, as the first child of " + node.outerHTML);
129
+ }
130
+ return node.firstChild;
131
+ }
132
+ if (!node.nextSibling || isEndComment(node.nextSibling)) {
133
+ return null;
134
+ }
135
+ return node.nextSibling;
136
+ }
137
+ export function lastChild(node) {
138
+ let nextChild = firstChild(node);
139
+ let lastChildNode;
140
+ do {
141
+ lastChildNode = nextChild;
142
+ } while (nextChild = nextSibling(nextChild));
143
+ return lastChildNode;
144
+ }
145
+ export function nextSibling(node) {
146
+ if (isStartComment(node)) {
147
+ node = getMatchingEndComment(node);
148
+ }
149
+ if (node.nextSibling && isEndComment(node.nextSibling)) {
150
+ if (isUnmatchedEndComment(node.nextSibling)) {
151
+ throw Error("Found end comment without a matching opening comment, as next sibling of " + node.outerHTML);
152
+ }
153
+ return null;
154
+ } else {
155
+ return node.nextSibling;
156
+ }
157
+ }
158
+ export function previousSibling(node) {
159
+ var depth = 0;
160
+ do {
161
+ if (node.nodeType === 8) {
162
+ if (isStartComment(node)) {
163
+ if (--depth === 0) {
164
+ return node;
165
+ }
166
+ } else if (isEndComment(node)) {
167
+ depth++;
168
+ }
169
+ } else {
170
+ if (depth === 0) {
171
+ return node;
172
+ }
173
+ }
174
+ } while (node = node.previousSibling);
175
+ }
176
+ export function virtualNodeBindingValue(node) {
177
+ var regexMatch = (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex);
178
+ return regexMatch ? regexMatch[1] : null;
179
+ }
180
+ export function normaliseVirtualElementDomStructure(elementVerified) {
181
+ if (!htmlTagsWithOptionallyClosingChildren[tagNameLower(elementVerified)]) {
182
+ return;
183
+ }
184
+ var childNode = elementVerified.firstChild;
185
+ if (childNode) {
186
+ do {
187
+ if (childNode.nodeType === 1) {
188
+ var unbalancedTags = getUnbalancedChildTags(childNode);
189
+ if (unbalancedTags) {
190
+ var nodeToInsertBefore = childNode.nextSibling;
191
+ for (var i = 0; i < unbalancedTags.length; i++) {
192
+ if (nodeToInsertBefore) {
193
+ elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore);
194
+ } else {
195
+ elementVerified.appendChild(unbalancedTags[i]);
196
+ }
197
+ }
198
+ }
199
+ }
200
+ } while (childNode = childNode.nextSibling);
201
+ }
202
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/dom/virtualElements.ts"],
4
+ "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"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
package/dist/error.js ADDED
@@ -0,0 +1,22 @@
1
+ // @tko/utils 🥊 4.0.0-beta1.0 ESM
2
+ import options from "./options";
3
+ export function catchFunctionErrors(delegate) {
4
+ if (!options.onError) {
5
+ return delegate;
6
+ }
7
+ return (...args) => {
8
+ try {
9
+ return delegate(...args);
10
+ } catch (err) {
11
+ options.onError(err);
12
+ }
13
+ };
14
+ }
15
+ export function deferError(error) {
16
+ safeSetTimeout(function() {
17
+ throw error;
18
+ }, 0);
19
+ }
20
+ export function safeSetTimeout(handler, timeout) {
21
+ return setTimeout(catchFunctionErrors(handler), timeout);
22
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/error.ts"],
4
+ "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"],
5
+ "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;",
6
+ "names": []
7
+ }