@tko/utils 4.0.0-alpha7.4 → 4.0.0-beta1.3
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.
- package/LICENSE +22 -0
- package/dist/array.js +156 -0
- package/dist/array.js.map +7 -0
- package/dist/async.js +20 -0
- package/dist/async.js.map +7 -0
- package/dist/bind-shim.js +18 -0
- package/dist/bind-shim.js.map +7 -0
- package/dist/css.js +27 -0
- package/dist/css.js.map +7 -0
- package/dist/dom/data.js +63 -0
- package/dist/dom/data.js.map +7 -0
- package/dist/dom/disposal.js +98 -0
- package/dist/dom/disposal.js.map +7 -0
- package/dist/dom/event.js +87 -0
- package/dist/dom/event.js.map +7 -0
- package/dist/dom/fixes.js +45 -0
- package/dist/dom/fixes.js.map +7 -0
- package/dist/dom/html.js +115 -0
- package/dist/dom/html.js.map +7 -0
- package/dist/dom/info.js +43 -0
- package/dist/dom/info.js.map +7 -0
- package/dist/dom/manipulation.js +55 -0
- package/dist/dom/manipulation.js.map +7 -0
- package/dist/dom/selectExtensions.js +62 -0
- package/dist/dom/selectExtensions.js.map +7 -0
- package/dist/dom/virtualElements.js +202 -0
- package/dist/dom/virtualElements.js.map +7 -0
- package/dist/error.js +22 -0
- package/dist/error.js.map +7 -0
- package/dist/function.js +16 -0
- package/dist/function.js.map +7 -0
- package/dist/ie.js +15 -0
- package/dist/ie.js.map +7 -0
- package/dist/index.cjs +1448 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +7 -0
- package/dist/jquery.js +6 -0
- package/dist/jquery.js.map +7 -0
- package/dist/memoization.js +64 -0
- package/dist/memoization.js.map +7 -0
- package/dist/object.js +76 -0
- package/dist/object.js.map +7 -0
- package/dist/options.js +36 -0
- package/dist/options.js.map +7 -0
- package/dist/string.js +23 -0
- package/dist/string.js.map +7 -0
- package/dist/symbol.js +5 -0
- package/dist/symbol.js.map +7 -0
- package/dist/tasks.js +76 -0
- package/dist/tasks.js.map +7 -0
- package/helpers/jasmine-13-helper.ts +207 -0
- package/package.json +18 -26
- package/dist/utils.es6.js +0 -1628
- package/dist/utils.es6.js.map +0 -1
- package/dist/utils.js +0 -1645
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @tko/utils 🥊 4.0.0-beta1.3 ESM
|
|
2
|
+
import { ieVersion } from "../ie";
|
|
3
|
+
export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
|
|
4
|
+
if (continuousNodeArray.length) {
|
|
5
|
+
parentNode = parentNode.nodeType === 8 && parentNode.parentNode || parentNode;
|
|
6
|
+
while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) {
|
|
7
|
+
continuousNodeArray.splice(0, 1);
|
|
8
|
+
}
|
|
9
|
+
while (continuousNodeArray.length > 1 && continuousNodeArray[continuousNodeArray.length - 1].parentNode !== parentNode) {
|
|
10
|
+
continuousNodeArray.length--;
|
|
11
|
+
}
|
|
12
|
+
if (continuousNodeArray.length > 1) {
|
|
13
|
+
var current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1];
|
|
14
|
+
continuousNodeArray.length = 0;
|
|
15
|
+
while (current !== last) {
|
|
16
|
+
continuousNodeArray.push(current);
|
|
17
|
+
current = current.nextSibling;
|
|
18
|
+
}
|
|
19
|
+
continuousNodeArray.push(last);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return continuousNodeArray;
|
|
23
|
+
}
|
|
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
|
+
}
|
|
45
|
+
}
|
|
@@ -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
|
+
}
|
package/dist/dom/html.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @tko/utils 🥊 4.0.0-beta1.3 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": ";AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAI,OAAO,CAAC,GAAG,IAAI,EAAE,GAC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E5D,UAAI,KAAK,aAAa,GAAG;AACvB,YAAI,SAAS,MAAM;AACjB,0BAAgB,UAAU,IAAI;AAAA,QAChC,OAAO;AACL,0BAAgB,mBAAmB,MAAM,WAAW;AAAA,QACtD;AAAA,MACF,OAAO;AACL,iBAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/dom/info.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @tko/utils 🥊 4.0.0-beta1.3 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.3 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,I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"./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.3 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
|
+
}
|