@domql/render 2.5.82 → 2.5.94
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/cache.js +13 -11
- package/dist/cjs/cache.js +13 -9
- package/package.json +2 -2
package/cache.js
CHANGED
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import { report } from '@domql/report'
|
|
4
4
|
import { canRenderTag } from '@domql/event'
|
|
5
|
-
import { exec, isObject, isString, isValidHtmlTag } from '@domql/utils'
|
|
6
|
-
|
|
7
|
-
const cache = {}
|
|
5
|
+
import { exec, isObject, isString, isValidHtmlTag, document } from '@domql/utils'
|
|
8
6
|
|
|
9
7
|
export const createHTMLNode = (element) => {
|
|
10
|
-
const { tag } = element
|
|
8
|
+
const { tag, context } = element
|
|
9
|
+
const doc = context.document || document
|
|
11
10
|
if (tag) {
|
|
12
|
-
if (tag === 'string') return
|
|
11
|
+
if (tag === 'string') return doc.createTextNode(element.text)
|
|
13
12
|
else if (tag === 'fragment') {
|
|
14
|
-
return
|
|
13
|
+
return doc.createDocumentFragment()
|
|
15
14
|
} else if (tag === 'svg' || tag === 'path') { // TODO: change that
|
|
16
|
-
return
|
|
17
|
-
} else return
|
|
15
|
+
return doc.createElementNS('http://www.w3.org/2000/svg', tag)
|
|
16
|
+
} else return doc.createElement(tag) // TODO: allow strict mode to check validity
|
|
18
17
|
} else {
|
|
19
|
-
return
|
|
18
|
+
return doc.createElement('div')
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
|
@@ -44,14 +43,17 @@ export const detectTag = element => {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
export const cacheNode = (element) => {
|
|
46
|
+
const { context } = element
|
|
47
|
+
const win = context.window || window
|
|
47
48
|
const tag = element.tag = detectTag(element)
|
|
48
49
|
|
|
49
50
|
if (!canRenderTag(tag)) {
|
|
50
51
|
return report('HTMLInvalidTag', element.tag, element)
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
if (!win.nodeCaches) win.nodeCaches = {}
|
|
55
|
+
let cachedTag = win.nodeCaches[tag]
|
|
56
|
+
if (!cachedTag) cachedTag = win.nodeCaches[tag] = createHTMLNode(element)
|
|
55
57
|
|
|
56
58
|
const clonedNode = cachedTag.cloneNode(true)
|
|
57
59
|
if (tag === 'string') clonedNode.nodeValue = element.text
|
package/dist/cjs/cache.js
CHANGED
|
@@ -26,20 +26,20 @@ module.exports = __toCommonJS(cache_exports);
|
|
|
26
26
|
var import_report = require("@domql/report");
|
|
27
27
|
var import_event = require("@domql/event");
|
|
28
28
|
var import_utils = require("@domql/utils");
|
|
29
|
-
const cache = {};
|
|
30
29
|
const createHTMLNode = (element) => {
|
|
31
|
-
const { tag } = element;
|
|
30
|
+
const { tag, context } = element;
|
|
31
|
+
const doc = context.document || import_utils.document;
|
|
32
32
|
if (tag) {
|
|
33
33
|
if (tag === "string")
|
|
34
|
-
return
|
|
34
|
+
return doc.createTextNode(element.text);
|
|
35
35
|
else if (tag === "fragment") {
|
|
36
|
-
return
|
|
36
|
+
return doc.createDocumentFragment();
|
|
37
37
|
} else if (tag === "svg" || tag === "path") {
|
|
38
|
-
return
|
|
38
|
+
return doc.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
39
39
|
} else
|
|
40
|
-
return
|
|
40
|
+
return doc.createElement(tag);
|
|
41
41
|
} else {
|
|
42
|
-
return
|
|
42
|
+
return doc.createElement("div");
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
const detectTag = (element) => {
|
|
@@ -67,13 +67,17 @@ const detectTag = (element) => {
|
|
|
67
67
|
return "div";
|
|
68
68
|
};
|
|
69
69
|
const cacheNode = (element) => {
|
|
70
|
+
const { context } = element;
|
|
71
|
+
const win = context.window || window;
|
|
70
72
|
const tag = element.tag = detectTag(element);
|
|
71
73
|
if (!(0, import_event.canRenderTag)(tag)) {
|
|
72
74
|
return (0, import_report.report)("HTMLInvalidTag", element.tag, element);
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
if (!win.nodeCaches)
|
|
77
|
+
win.nodeCaches = {};
|
|
78
|
+
let cachedTag = win.nodeCaches[tag];
|
|
75
79
|
if (!cachedTag)
|
|
76
|
-
cachedTag =
|
|
80
|
+
cachedTag = win.nodeCaches[tag] = createHTMLNode(element);
|
|
77
81
|
const clonedNode = cachedTag.cloneNode(true);
|
|
78
82
|
if (tag === "string")
|
|
79
83
|
clonedNode.nodeValue = element.text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/render",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.94",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"build": "yarn build:cjs",
|
|
29
29
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "76edeab829524b706fd1a0bd3fac3fd5563a3b84"
|
|
32
32
|
}
|