@domql/render 2.5.190 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/append.js +23 -7
- package/dist/cjs/append.js +22 -5
- package/dist/cjs/cache.js +11 -22
- package/dist/cjs/index.js +5 -5
- package/dist/esm/append.js +22 -5
- package/dist/esm/cache.js +11 -22
- package/package.json +5 -5
package/append.js
CHANGED
|
@@ -5,23 +5,33 @@
|
|
|
5
5
|
* and assigns them into real DOM tree
|
|
6
6
|
*/
|
|
7
7
|
export const appendNode = (node, parentNode) => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
try {
|
|
9
|
+
parentNode.appendChild(node)
|
|
10
|
+
return node
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.error('Does not support to append', parentNode, node)
|
|
13
|
+
}
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
export const insertNodeAfter = (node, siblingNode, parentNode) => {
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
if (!node) {
|
|
18
|
+
throw new Error('Node is required')
|
|
19
|
+
}
|
|
20
|
+
const parent = parentNode || siblingNode?.parentNode
|
|
21
|
+
if (siblingNode?.nextSibling) {
|
|
15
22
|
parent && parent.insertBefore(node, siblingNode.nextSibling)
|
|
16
23
|
} else if (siblingNode?.insertAdjacentElement) {
|
|
17
24
|
siblingNode.insertAdjacentElement('afterend', node)
|
|
18
25
|
} else {
|
|
19
|
-
parent.insertBefore(node, siblingNode)
|
|
26
|
+
parent && parent.insertBefore(node, siblingNode)
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
export const insertNodeBefore = (node, siblingNode, parentNode) => {
|
|
24
|
-
|
|
31
|
+
if (!node) {
|
|
32
|
+
throw new Error('Node is required')
|
|
33
|
+
}
|
|
34
|
+
const parent = parentNode || siblingNode.parentNode
|
|
25
35
|
parent && parent.insertBefore(node, siblingNode)
|
|
26
36
|
}
|
|
27
37
|
|
|
@@ -30,10 +40,16 @@ export const insertNodeBefore = (node, siblingNode, parentNode) => {
|
|
|
30
40
|
* parameter as a child of the second one
|
|
31
41
|
*/
|
|
32
42
|
export const assignNode = (element, parent, key, attachOptions) => {
|
|
43
|
+
if (!element) {
|
|
44
|
+
throw new Error('Element is required')
|
|
45
|
+
}
|
|
46
|
+
if (!parent) {
|
|
47
|
+
throw new Error('Parent is required')
|
|
48
|
+
}
|
|
33
49
|
parent[key || element.key] = element
|
|
34
50
|
if (element.tag !== 'shadow') {
|
|
35
51
|
if (attachOptions && attachOptions.position) {
|
|
36
|
-
(attachOptions.position === 'before'
|
|
52
|
+
;(attachOptions.position === 'before'
|
|
37
53
|
? insertNodeBefore
|
|
38
54
|
: insertNodeAfter)(element.node, attachOptions.node || parent.node)
|
|
39
55
|
} else {
|
package/dist/cjs/append.js
CHANGED
|
@@ -25,27 +25,44 @@ __export(append_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(append_exports);
|
|
27
27
|
const appendNode = (node, parentNode) => {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
try {
|
|
29
|
+
parentNode.appendChild(node);
|
|
30
|
+
return node;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error("Does not support to append", parentNode, node);
|
|
33
|
+
}
|
|
30
34
|
};
|
|
31
35
|
const insertNodeAfter = (node, siblingNode, parentNode) => {
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
if (!node) {
|
|
37
|
+
throw new Error("Node is required");
|
|
38
|
+
}
|
|
39
|
+
const parent = parentNode || (siblingNode == null ? void 0 : siblingNode.parentNode);
|
|
40
|
+
if (siblingNode == null ? void 0 : siblingNode.nextSibling) {
|
|
34
41
|
parent && parent.insertBefore(node, siblingNode.nextSibling);
|
|
35
42
|
} else if (siblingNode == null ? void 0 : siblingNode.insertAdjacentElement) {
|
|
36
43
|
siblingNode.insertAdjacentElement("afterend", node);
|
|
37
44
|
} else {
|
|
38
|
-
parent.insertBefore(node, siblingNode);
|
|
45
|
+
parent && parent.insertBefore(node, siblingNode);
|
|
39
46
|
}
|
|
40
47
|
};
|
|
41
48
|
const insertNodeBefore = (node, siblingNode, parentNode) => {
|
|
49
|
+
if (!node) {
|
|
50
|
+
throw new Error("Node is required");
|
|
51
|
+
}
|
|
42
52
|
const parent = parentNode || siblingNode.parentNode;
|
|
43
53
|
parent && parent.insertBefore(node, siblingNode);
|
|
44
54
|
};
|
|
45
55
|
const assignNode = (element, parent, key, attachOptions) => {
|
|
56
|
+
if (!element) {
|
|
57
|
+
throw new Error("Element is required");
|
|
58
|
+
}
|
|
59
|
+
if (!parent) {
|
|
60
|
+
throw new Error("Parent is required");
|
|
61
|
+
}
|
|
46
62
|
parent[key || element.key] = element;
|
|
47
63
|
if (element.tag !== "shadow") {
|
|
48
64
|
if (attachOptions && attachOptions.position) {
|
|
65
|
+
;
|
|
49
66
|
(attachOptions.position === "before" ? insertNodeBefore : insertNodeAfter)(element.node, attachOptions.node || parent.node);
|
|
50
67
|
} else {
|
|
51
68
|
appendNode(element.node, parent.node);
|
package/dist/cjs/cache.js
CHANGED
|
@@ -30,14 +30,12 @@ const createHTMLNode = (element) => {
|
|
|
30
30
|
const { tag, context } = element;
|
|
31
31
|
const doc = context.document || import_utils.document;
|
|
32
32
|
if (tag) {
|
|
33
|
-
if (tag === "string")
|
|
34
|
-
return doc.createTextNode(element.text);
|
|
33
|
+
if (tag === "string") return doc.createTextNode(element.text);
|
|
35
34
|
else if (tag === "fragment") {
|
|
36
35
|
return doc.createDocumentFragment();
|
|
37
36
|
} else if (tag === "svg" || tag === "path") {
|
|
38
37
|
return doc.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
39
|
-
} else
|
|
40
|
-
return doc.createElement(tag);
|
|
38
|
+
} else return doc.createElement(tag);
|
|
41
39
|
} else {
|
|
42
40
|
return doc.createElement("div");
|
|
43
41
|
}
|
|
@@ -45,24 +43,18 @@ const createHTMLNode = (element) => {
|
|
|
45
43
|
const detectTag = (element) => {
|
|
46
44
|
let { tag, key, props } = element;
|
|
47
45
|
tag = (0, import_utils.exec)(tag, element);
|
|
48
|
-
if (tag === true)
|
|
49
|
-
tag = key;
|
|
46
|
+
if (tag === true) tag = key;
|
|
50
47
|
if ((0, import_utils.isObject)(props) && (0, import_utils.isString)(props.tag)) {
|
|
51
48
|
const tagExists = (0, import_utils.isValidHtmlTag)(props.tag);
|
|
52
|
-
if (tagExists)
|
|
53
|
-
return props.tag;
|
|
49
|
+
if (tagExists) return props.tag;
|
|
54
50
|
}
|
|
55
51
|
if ((0, import_utils.isString)(tag)) {
|
|
56
|
-
if ((0, import_utils.isValidHtmlTag)(tag))
|
|
57
|
-
return tag;
|
|
52
|
+
if ((0, import_utils.isValidHtmlTag)(tag)) return tag;
|
|
58
53
|
} else {
|
|
59
54
|
let keyAsTag = key.toLowerCase();
|
|
60
|
-
if (keyAsTag.includes("."))
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
keyAsTag = keyAsTag.split("_")[0];
|
|
64
|
-
if ((0, import_utils.isValidHtmlTag)(keyAsTag))
|
|
65
|
-
return keyAsTag;
|
|
55
|
+
if (keyAsTag.includes(".")) keyAsTag = keyAsTag.split(".")[0];
|
|
56
|
+
if (keyAsTag.includes("_")) keyAsTag = keyAsTag.split("_")[0];
|
|
57
|
+
if ((0, import_utils.isValidHtmlTag)(keyAsTag)) return keyAsTag;
|
|
66
58
|
}
|
|
67
59
|
return "div";
|
|
68
60
|
};
|
|
@@ -73,13 +65,10 @@ const cacheNode = (element) => {
|
|
|
73
65
|
if (!(0, import_event.canRenderTag)(tag)) {
|
|
74
66
|
return (0, import_report.report)("HTMLInvalidTag", element.tag, element);
|
|
75
67
|
}
|
|
76
|
-
if (!win.nodeCaches)
|
|
77
|
-
win.nodeCaches = {};
|
|
68
|
+
if (!win.nodeCaches) win.nodeCaches = {};
|
|
78
69
|
let cachedTag = win.nodeCaches[tag];
|
|
79
|
-
if (!cachedTag)
|
|
80
|
-
cachedTag = win.nodeCaches[tag] = createHTMLNode(element);
|
|
70
|
+
if (!cachedTag) cachedTag = win.nodeCaches[tag] = createHTMLNode(element);
|
|
81
71
|
const clonedNode = cachedTag.cloneNode(true);
|
|
82
|
-
if (tag === "string")
|
|
83
|
-
clonedNode.nodeValue = element.text;
|
|
72
|
+
if (tag === "string") clonedNode.nodeValue = element.text;
|
|
84
73
|
return clonedNode;
|
|
85
74
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -13,8 +13,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
};
|
|
14
14
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var
|
|
17
|
-
module.exports = __toCommonJS(
|
|
18
|
-
__reExport(
|
|
19
|
-
__reExport(
|
|
20
|
-
__reExport(
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./create.js"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./cache.js"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./append.js"), module.exports);
|
package/dist/esm/append.js
CHANGED
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
const appendNode = (node, parentNode) => {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
try {
|
|
3
|
+
parentNode.appendChild(node);
|
|
4
|
+
return node;
|
|
5
|
+
} catch (e) {
|
|
6
|
+
console.error("Does not support to append", parentNode, node);
|
|
7
|
+
}
|
|
4
8
|
};
|
|
5
9
|
const insertNodeAfter = (node, siblingNode, parentNode) => {
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
if (!node) {
|
|
11
|
+
throw new Error("Node is required");
|
|
12
|
+
}
|
|
13
|
+
const parent = parentNode || (siblingNode == null ? void 0 : siblingNode.parentNode);
|
|
14
|
+
if (siblingNode == null ? void 0 : siblingNode.nextSibling) {
|
|
8
15
|
parent && parent.insertBefore(node, siblingNode.nextSibling);
|
|
9
16
|
} else if (siblingNode == null ? void 0 : siblingNode.insertAdjacentElement) {
|
|
10
17
|
siblingNode.insertAdjacentElement("afterend", node);
|
|
11
18
|
} else {
|
|
12
|
-
parent.insertBefore(node, siblingNode);
|
|
19
|
+
parent && parent.insertBefore(node, siblingNode);
|
|
13
20
|
}
|
|
14
21
|
};
|
|
15
22
|
const insertNodeBefore = (node, siblingNode, parentNode) => {
|
|
23
|
+
if (!node) {
|
|
24
|
+
throw new Error("Node is required");
|
|
25
|
+
}
|
|
16
26
|
const parent = parentNode || siblingNode.parentNode;
|
|
17
27
|
parent && parent.insertBefore(node, siblingNode);
|
|
18
28
|
};
|
|
19
29
|
const assignNode = (element, parent, key, attachOptions) => {
|
|
30
|
+
if (!element) {
|
|
31
|
+
throw new Error("Element is required");
|
|
32
|
+
}
|
|
33
|
+
if (!parent) {
|
|
34
|
+
throw new Error("Parent is required");
|
|
35
|
+
}
|
|
20
36
|
parent[key || element.key] = element;
|
|
21
37
|
if (element.tag !== "shadow") {
|
|
22
38
|
if (attachOptions && attachOptions.position) {
|
|
39
|
+
;
|
|
23
40
|
(attachOptions.position === "before" ? insertNodeBefore : insertNodeAfter)(element.node, attachOptions.node || parent.node);
|
|
24
41
|
} else {
|
|
25
42
|
appendNode(element.node, parent.node);
|
package/dist/esm/cache.js
CHANGED
|
@@ -5,14 +5,12 @@ const createHTMLNode = (element) => {
|
|
|
5
5
|
const { tag, context } = element;
|
|
6
6
|
const doc = context.document || document;
|
|
7
7
|
if (tag) {
|
|
8
|
-
if (tag === "string")
|
|
9
|
-
return doc.createTextNode(element.text);
|
|
8
|
+
if (tag === "string") return doc.createTextNode(element.text);
|
|
10
9
|
else if (tag === "fragment") {
|
|
11
10
|
return doc.createDocumentFragment();
|
|
12
11
|
} else if (tag === "svg" || tag === "path") {
|
|
13
12
|
return doc.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
14
|
-
} else
|
|
15
|
-
return doc.createElement(tag);
|
|
13
|
+
} else return doc.createElement(tag);
|
|
16
14
|
} else {
|
|
17
15
|
return doc.createElement("div");
|
|
18
16
|
}
|
|
@@ -20,24 +18,18 @@ const createHTMLNode = (element) => {
|
|
|
20
18
|
const detectTag = (element) => {
|
|
21
19
|
let { tag, key, props } = element;
|
|
22
20
|
tag = exec(tag, element);
|
|
23
|
-
if (tag === true)
|
|
24
|
-
tag = key;
|
|
21
|
+
if (tag === true) tag = key;
|
|
25
22
|
if (isObject(props) && isString(props.tag)) {
|
|
26
23
|
const tagExists = isValidHtmlTag(props.tag);
|
|
27
|
-
if (tagExists)
|
|
28
|
-
return props.tag;
|
|
24
|
+
if (tagExists) return props.tag;
|
|
29
25
|
}
|
|
30
26
|
if (isString(tag)) {
|
|
31
|
-
if (isValidHtmlTag(tag))
|
|
32
|
-
return tag;
|
|
27
|
+
if (isValidHtmlTag(tag)) return tag;
|
|
33
28
|
} else {
|
|
34
29
|
let keyAsTag = key.toLowerCase();
|
|
35
|
-
if (keyAsTag.includes("."))
|
|
36
|
-
|
|
37
|
-
if (keyAsTag
|
|
38
|
-
keyAsTag = keyAsTag.split("_")[0];
|
|
39
|
-
if (isValidHtmlTag(keyAsTag))
|
|
40
|
-
return keyAsTag;
|
|
30
|
+
if (keyAsTag.includes(".")) keyAsTag = keyAsTag.split(".")[0];
|
|
31
|
+
if (keyAsTag.includes("_")) keyAsTag = keyAsTag.split("_")[0];
|
|
32
|
+
if (isValidHtmlTag(keyAsTag)) return keyAsTag;
|
|
41
33
|
}
|
|
42
34
|
return "div";
|
|
43
35
|
};
|
|
@@ -48,14 +40,11 @@ const cacheNode = (element) => {
|
|
|
48
40
|
if (!canRenderTag(tag)) {
|
|
49
41
|
return report("HTMLInvalidTag", element.tag, element);
|
|
50
42
|
}
|
|
51
|
-
if (!win.nodeCaches)
|
|
52
|
-
win.nodeCaches = {};
|
|
43
|
+
if (!win.nodeCaches) win.nodeCaches = {};
|
|
53
44
|
let cachedTag = win.nodeCaches[tag];
|
|
54
|
-
if (!cachedTag)
|
|
55
|
-
cachedTag = win.nodeCaches[tag] = createHTMLNode(element);
|
|
45
|
+
if (!cachedTag) cachedTag = win.nodeCaches[tag] = createHTMLNode(element);
|
|
56
46
|
const clonedNode = cachedTag.cloneNode(true);
|
|
57
|
-
if (tag === "string")
|
|
58
|
-
clonedNode.nodeValue = element.text;
|
|
47
|
+
if (tag === "string") clonedNode.nodeValue = element.text;
|
|
59
48
|
return clonedNode;
|
|
60
49
|
};
|
|
61
50
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/render",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@domql/event": "^
|
|
22
|
-
"@domql/report": "^
|
|
23
|
-
"@domql/utils": "^
|
|
21
|
+
"@domql/event": "^3.0.0",
|
|
22
|
+
"@domql/report": "^3.0.0",
|
|
23
|
+
"@domql/utils": "^3.0.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
30
30
|
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "bcbdc271a602b958de6a60ab387ea7715a935dc1"
|
|
33
33
|
}
|