@domql/render 2.4.0 → 2.4.7
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 +26 -0
- package/cache.js +53 -0
- package/create.js +3 -0
- package/dist/cjs/append.js +39 -0
- package/dist/cjs/cache.js +73 -0
- package/dist/cjs/create.js +25 -0
- package/dist/cjs/index.js +4 -23
- package/index.js +3 -24
- package/package.json +7 -2
package/append.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Receives child and parent nodes as parametes
|
|
5
|
+
* and assigns them into real DOM tree
|
|
6
|
+
*/
|
|
7
|
+
export const appendNode = (node, parentNode) => {
|
|
8
|
+
parentNode.appendChild(node)
|
|
9
|
+
return node
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const insertNodeAfter = (node, siblingNode) => {
|
|
13
|
+
siblingNode.parentNode.insertBefore(node, siblingNode.nextSibling)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Receives elements and assigns the first
|
|
18
|
+
* parameter as a child of the second one
|
|
19
|
+
*/
|
|
20
|
+
export const assignNode = (element, parent, key, insertAfter) => {
|
|
21
|
+
parent[key || element.key] = element
|
|
22
|
+
if (element.tag !== 'shadow') {
|
|
23
|
+
(insertAfter ? insertNodeAfter : appendNode)(element.node, parent.node)
|
|
24
|
+
}
|
|
25
|
+
return element
|
|
26
|
+
}
|
package/cache.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { report } from '@domql/report'
|
|
4
|
+
import { canRender } from '@domql/event'
|
|
5
|
+
import { exec, isString, isValidHtmlTag } from '@domql/utils'
|
|
6
|
+
|
|
7
|
+
const cache = {}
|
|
8
|
+
|
|
9
|
+
export const createHTMLNode = (element) => {
|
|
10
|
+
const { tag } = element
|
|
11
|
+
if (tag) {
|
|
12
|
+
if (tag === 'string') return document.createTextNode(element.text)
|
|
13
|
+
else if (tag === 'fragment') {
|
|
14
|
+
return document.createDocumentFragment()
|
|
15
|
+
} else if (tag === 'svg' || tag === 'path') { // TODO: change that
|
|
16
|
+
return document.createElementNS('http://www.w3.org/2000/svg', tag)
|
|
17
|
+
} else return document.createElement(tag) // TODO: allow strict mode to check validity
|
|
18
|
+
} else {
|
|
19
|
+
return document.createElement('div')
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const detectTag = element => {
|
|
24
|
+
let { tag, key } = element
|
|
25
|
+
tag = exec(tag, element)
|
|
26
|
+
|
|
27
|
+
if (tag === true) tag = key
|
|
28
|
+
|
|
29
|
+
if (isString(tag)) {
|
|
30
|
+
const tagExists = isValidHtmlTag(tag)
|
|
31
|
+
if (tagExists) return tag
|
|
32
|
+
} else {
|
|
33
|
+
const isKeyATag = isValidHtmlTag(key)
|
|
34
|
+
if (isKeyATag) return key
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return 'div'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const cacheNode = (element) => {
|
|
41
|
+
const tag = element.tag = detectTag(element)
|
|
42
|
+
|
|
43
|
+
if (!canRender(element)) {
|
|
44
|
+
return report('HTMLInvalidTag', element.tag, element)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let cachedTag = cache[tag]
|
|
48
|
+
if (!cachedTag) cachedTag = cache[tag] = createHTMLNode(element)
|
|
49
|
+
|
|
50
|
+
const clonedNode = cachedTag.cloneNode(true)
|
|
51
|
+
if (tag === 'string') clonedNode.nodeValue = element.text
|
|
52
|
+
return clonedNode
|
|
53
|
+
}
|
package/create.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var append_exports = {};
|
|
20
|
+
__export(append_exports, {
|
|
21
|
+
appendNode: () => appendNode,
|
|
22
|
+
assignNode: () => assignNode,
|
|
23
|
+
insertNodeAfter: () => insertNodeAfter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(append_exports);
|
|
26
|
+
const appendNode = (node, parentNode) => {
|
|
27
|
+
parentNode.appendChild(node);
|
|
28
|
+
return node;
|
|
29
|
+
};
|
|
30
|
+
const insertNodeAfter = (node, siblingNode) => {
|
|
31
|
+
siblingNode.parentNode.insertBefore(node, siblingNode.nextSibling);
|
|
32
|
+
};
|
|
33
|
+
const assignNode = (element, parent, key, insertAfter) => {
|
|
34
|
+
parent[key || element.key] = element;
|
|
35
|
+
if (element.tag !== "shadow") {
|
|
36
|
+
(insertAfter ? insertNodeAfter : appendNode)(element.node, parent.node);
|
|
37
|
+
}
|
|
38
|
+
return element;
|
|
39
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cache_exports = {};
|
|
20
|
+
__export(cache_exports, {
|
|
21
|
+
cacheNode: () => cacheNode,
|
|
22
|
+
createHTMLNode: () => createHTMLNode,
|
|
23
|
+
detectTag: () => detectTag
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(cache_exports);
|
|
26
|
+
var import_report = require("@domql/report");
|
|
27
|
+
var import_event = require("@domql/event");
|
|
28
|
+
var import_utils = require("@domql/utils");
|
|
29
|
+
const cache = {};
|
|
30
|
+
const createHTMLNode = (element) => {
|
|
31
|
+
const { tag } = element;
|
|
32
|
+
if (tag) {
|
|
33
|
+
if (tag === "string")
|
|
34
|
+
return document.createTextNode(element.text);
|
|
35
|
+
else if (tag === "fragment") {
|
|
36
|
+
return document.createDocumentFragment();
|
|
37
|
+
} else if (tag === "svg" || tag === "path") {
|
|
38
|
+
return document.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
39
|
+
} else
|
|
40
|
+
return document.createElement(tag);
|
|
41
|
+
} else {
|
|
42
|
+
return document.createElement("div");
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const detectTag = (element) => {
|
|
46
|
+
let { tag, key } = element;
|
|
47
|
+
tag = (0, import_utils.exec)(tag, element);
|
|
48
|
+
if (tag === true)
|
|
49
|
+
tag = key;
|
|
50
|
+
if ((0, import_utils.isString)(tag)) {
|
|
51
|
+
const tagExists = (0, import_utils.isValidHtmlTag)(tag);
|
|
52
|
+
if (tagExists)
|
|
53
|
+
return tag;
|
|
54
|
+
} else {
|
|
55
|
+
const isKeyATag = (0, import_utils.isValidHtmlTag)(key);
|
|
56
|
+
if (isKeyATag)
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
return "div";
|
|
60
|
+
};
|
|
61
|
+
const cacheNode = (element) => {
|
|
62
|
+
const tag = element.tag = detectTag(element);
|
|
63
|
+
if (!(0, import_event.canRender)(element)) {
|
|
64
|
+
return (0, import_report.report)("HTMLInvalidTag", element.tag, element);
|
|
65
|
+
}
|
|
66
|
+
let cachedTag = cache[tag];
|
|
67
|
+
if (!cachedTag)
|
|
68
|
+
cachedTag = cache[tag] = createHTMLNode(element);
|
|
69
|
+
const clonedNode = cachedTag.cloneNode(true);
|
|
70
|
+
if (tag === "string")
|
|
71
|
+
clonedNode.nodeValue = element.text;
|
|
72
|
+
return clonedNode;
|
|
73
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var create_exports = {};
|
|
20
|
+
__export(create_exports, {
|
|
21
|
+
createNode: () => createNode
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(create_exports);
|
|
24
|
+
const createNode = (element) => {
|
|
25
|
+
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
6
|
var __copyProps = (to, from, except, desc) => {
|
|
11
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,25 +11,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
11
|
}
|
|
16
12
|
return to;
|
|
17
13
|
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
16
|
var render_exports = {};
|
|
20
|
-
__export(render_exports, {
|
|
21
|
-
appendNode: () => appendNode,
|
|
22
|
-
assignNode: () => assignNode,
|
|
23
|
-
insertNodeAfter: () => insertNodeAfter
|
|
24
|
-
});
|
|
25
17
|
module.exports = __toCommonJS(render_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
const insertNodeAfter = (node, siblingNode) => {
|
|
31
|
-
siblingNode.parentNode.insertBefore(node, siblingNode.nextSibling);
|
|
32
|
-
};
|
|
33
|
-
const assignNode = (element, parent, key, insertAfter) => {
|
|
34
|
-
parent[key || element.key] = element;
|
|
35
|
-
if (element.tag !== "shadow") {
|
|
36
|
-
(insertAfter ? insertNodeAfter : appendNode)(element.node, parent.node);
|
|
37
|
-
}
|
|
38
|
-
return element;
|
|
39
|
-
};
|
|
18
|
+
__reExport(render_exports, require("./create"), module.exports);
|
|
19
|
+
__reExport(render_exports, require("./cache"), module.exports);
|
|
20
|
+
__reExport(render_exports, require("./append"), module.exports);
|
package/index.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
export const appendNode = (node, parentNode) => {
|
|
8
|
-
parentNode.appendChild(node)
|
|
9
|
-
return node
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const insertNodeAfter = (node, siblingNode) => {
|
|
13
|
-
siblingNode.parentNode.insertBefore(node, siblingNode.nextSibling)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Receives elements and assigns the first
|
|
18
|
-
* parameter as a child of the second one
|
|
19
|
-
*/
|
|
20
|
-
export const assignNode = (element, parent, key, insertAfter) => {
|
|
21
|
-
parent[key || element.key] = element
|
|
22
|
-
if (element.tag !== 'shadow') {
|
|
23
|
-
(insertAfter ? insertNodeAfter : appendNode)(element.node, parent.node)
|
|
24
|
-
}
|
|
25
|
-
return element
|
|
26
|
-
}
|
|
3
|
+
export * from './create'
|
|
4
|
+
export * from './cache'
|
|
5
|
+
export * from './append'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/render",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"*.js",
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@domql/event": "latest",
|
|
21
|
+
"@domql/report": "latest",
|
|
22
|
+
"@domql/utils": "latest"
|
|
23
|
+
},
|
|
19
24
|
"scripts": {
|
|
20
25
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
21
26
|
"build:esm": "npx esbuild *.js --target=es2019 --format=esm --outdir=dist/esm",
|
|
@@ -23,5 +28,5 @@
|
|
|
23
28
|
"build": "yarn build:cjs",
|
|
24
29
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
25
30
|
},
|
|
26
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "fd9683a7d42893983463967fa512ac095a6a36e9"
|
|
27
32
|
}
|