@domql/render
Advanced tools
Comparing version 2.5.84 to 2.5.94
24
cache.js
@@ -5,17 +5,16 @@ 'use strict' | ||
import { canRenderTag } from '@domql/event' | ||
import { exec, isObject, isString, isValidHtmlTag } from '@domql/utils' | ||
import { exec, isObject, isString, isValidHtmlTag, document } from '@domql/utils' | ||
const cache = {} | ||
export const createHTMLNode = (element) => { | ||
const { tag } = element | ||
const { tag, context } = element | ||
const doc = context.document || document | ||
if (tag) { | ||
if (tag === 'string') return document.createTextNode(element.text) | ||
if (tag === 'string') return doc.createTextNode(element.text) | ||
else if (tag === 'fragment') { | ||
return document.createDocumentFragment() | ||
return doc.createDocumentFragment() | ||
} else if (tag === 'svg' || tag === 'path') { // TODO: change that | ||
return document.createElementNS('http://www.w3.org/2000/svg', tag) | ||
} else return document.createElement(tag) // TODO: allow strict mode to check validity | ||
return doc.createElementNS('http://www.w3.org/2000/svg', tag) | ||
} else return doc.createElement(tag) // TODO: allow strict mode to check validity | ||
} else { | ||
return document.createElement('div') | ||
return doc.createElement('div') | ||
} | ||
@@ -48,2 +47,4 @@ } | ||
export const cacheNode = (element) => { | ||
const { context } = element | ||
const win = context.window || window | ||
const tag = element.tag = detectTag(element) | ||
@@ -55,4 +56,5 @@ | ||
let cachedTag = cache[tag] | ||
if (!cachedTag) cachedTag = cache[tag] = createHTMLNode(element) | ||
if (!win.nodeCaches) win.nodeCaches = {} | ||
let cachedTag = win.nodeCaches[tag] | ||
if (!cachedTag) cachedTag = win.nodeCaches[tag] = createHTMLNode(element) | ||
@@ -59,0 +61,0 @@ const clonedNode = cachedTag.cloneNode(true) |
@@ -29,16 +29,16 @@ "use strict"; | ||
var import_utils = require("@domql/utils"); | ||
const cache = {}; | ||
const createHTMLNode = (element) => { | ||
const { tag } = element; | ||
const { tag, context } = element; | ||
const doc = context.document || import_utils.document; | ||
if (tag) { | ||
if (tag === "string") | ||
return document.createTextNode(element.text); | ||
return doc.createTextNode(element.text); | ||
else if (tag === "fragment") { | ||
return document.createDocumentFragment(); | ||
return doc.createDocumentFragment(); | ||
} else if (tag === "svg" || tag === "path") { | ||
return document.createElementNS("http://www.w3.org/2000/svg", tag); | ||
return doc.createElementNS("http://www.w3.org/2000/svg", tag); | ||
} else | ||
return document.createElement(tag); | ||
return doc.createElement(tag); | ||
} else { | ||
return document.createElement("div"); | ||
return doc.createElement("div"); | ||
} | ||
@@ -71,2 +71,4 @@ }; | ||
const cacheNode = (element) => { | ||
const { context } = element; | ||
const win = context.window || window; | ||
const tag = element.tag = detectTag(element); | ||
@@ -76,5 +78,7 @@ if (!(0, import_event.canRenderTag)(tag)) { | ||
} | ||
let cachedTag = cache[tag]; | ||
if (!win.nodeCaches) | ||
win.nodeCaches = {}; | ||
let cachedTag = win.nodeCaches[tag]; | ||
if (!cachedTag) | ||
cachedTag = cache[tag] = createHTMLNode(element); | ||
cachedTag = win.nodeCaches[tag] = createHTMLNode(element); | ||
const clonedNode = cachedTag.cloneNode(true); | ||
@@ -81,0 +85,0 @@ if (tag === "string") |
{ | ||
"name": "@domql/render", | ||
"version": "2.5.84", | ||
"version": "2.5.94", | ||
"license": "MIT", | ||
@@ -31,3 +31,3 @@ "type": "module", | ||
}, | ||
"gitHead": "4bd66069a10c9126fca5f29ca9c1f99e8b957228" | ||
"gitHead": "76edeab829524b706fd1a0bd3fac3fd5563a3b84" | ||
} |
12490
281