@erickmerchant/framework
Advanced tools
Comparing version 47.0.0 to 47.1.0
@@ -36,3 +36,3 @@ import {tokenTypes} from './html.js' | ||
const morphAttribute = (target, key, value, isExistingElement) => { | ||
const morphAttribute = (target, key, value, existing) => { | ||
const firstChar = key.charAt(0) | ||
@@ -69,3 +69,3 @@ const hasDash = ~key.indexOf('-') | ||
} | ||
} else if (isExistingElement && value == null) { | ||
} else if (existing && value == null) { | ||
target.removeAttribute(key) | ||
@@ -77,15 +77,11 @@ } else if (value != null && target.getAttribute(key) !== value) { | ||
const morph = ( | ||
target, | ||
next, | ||
variables, | ||
isExistingElement = true, | ||
isSameView = true | ||
) => { | ||
const morph = (target, next, variables, existing = true, same = true) => { | ||
const document = target.ownerDocument | ||
if (next.view) { | ||
const meta = readMeta(target) | ||
isSameView = next.view === meta.view | ||
same = next.view === meta.view | ||
if (next.dynamic || !isExistingElement || !isSameView) { | ||
if (next.dynamic || !existing || !same) { | ||
meta.view = next.view | ||
@@ -101,3 +97,3 @@ | ||
if (isExistingElement && isSameView) { | ||
if (existing && same) { | ||
attributeIndex = next.offsets.attributes | ||
@@ -120,3 +116,3 @@ } | ||
if (attribute.key) { | ||
morphAttribute(target, attribute.key, value, isExistingElement) | ||
morphAttribute(target, attribute.key, value, existing) | ||
} else { | ||
@@ -130,3 +126,3 @@ for ( | ||
morphAttribute(target, key, value[key], isExistingElement) | ||
morphAttribute(target, key, value[key], existing) | ||
} | ||
@@ -140,3 +136,3 @@ } | ||
if (isExistingElement && isSameView) { | ||
if (existing && same) { | ||
childIndex = next.offsets.children | ||
@@ -156,17 +152,19 @@ | ||
let nextChild | ||
let i | ||
if (!Array.isArray(child)) { | ||
child = [child] | ||
nextChild = child | ||
} else { | ||
i = 0 | ||
nextChild = child[i] | ||
} | ||
for (let i = 0; i < child.length; i++) { | ||
const next = child[i] | ||
while (nextChild != null) { | ||
let mode = !existing || childNode == null ? 2 : !same ? 1 : 0 | ||
const document = target.ownerDocument | ||
let mode = | ||
!isExistingElement || childNode == null ? 2 : !isSameView ? 1 : 0 | ||
let currentChild = childNode | ||
if (!next?.type || next.type === tokenTypes.text) { | ||
if (!nextChild?.type || nextChild.type === tokenTypes.text) { | ||
if (!mode && childNode.nodeType !== 3) { | ||
@@ -176,3 +174,3 @@ mode = 1 | ||
const value = next?.value ?? next ?? '' | ||
const value = nextChild?.value ?? nextChild ?? '' | ||
@@ -188,3 +186,3 @@ if (mode) { | ||
(childNode.nodeType !== 1 || | ||
childNode.nodeName.toLowerCase() !== next.tag) | ||
childNode.nodeName.toLowerCase() !== nextChild.tag) | ||
) { | ||
@@ -196,11 +194,11 @@ mode = 1 | ||
const isSvg = | ||
next.tag === 'svg' || target.namespaceURI === svgNamespace | ||
nextChild.tag === 'svg' || target.namespaceURI === svgNamespace | ||
currentChild = isSvg | ||
? document.createElementNS(svgNamespace, next.tag) | ||
: document.createElement(next.tag) | ||
? document.createElementNS(svgNamespace, nextChild.tag) | ||
: document.createElement(nextChild.tag) | ||
} | ||
if (next.view || mode || next.dynamic) { | ||
morph(currentChild, next, variables, !mode, isSameView) | ||
if (nextChild.view || mode || nextChild.dynamic) { | ||
morph(currentChild, nextChild, variables, !mode, same) | ||
} | ||
@@ -216,15 +214,15 @@ } | ||
childNode = currentChild?.nextSibling | ||
nextChild = i != null ? child[++i] : null | ||
} | ||
} | ||
if (childNode) { | ||
let nextChild | ||
let nextChild | ||
do { | ||
nextChild = childNode?.nextSibling | ||
while (childNode) { | ||
nextChild = childNode?.nextSibling | ||
target.removeChild(childNode) | ||
target.removeChild(childNode) | ||
childNode = nextChild | ||
} while (childNode) | ||
childNode = nextChild | ||
} | ||
@@ -231,0 +229,0 @@ } |
19
html.js
@@ -302,11 +302,20 @@ const weakMap = new WeakMap() | ||
const html = (strs, ...variables) => { | ||
let result = weakMap.get(strs) | ||
let template = weakMap.get(strs) | ||
if (!result) { | ||
result = toTemplate(strs, variables) | ||
if (!template) { | ||
template = toTemplate(strs, variables) | ||
weakMap.set(strs, result) | ||
weakMap.set(strs, template) | ||
} | ||
return {variables, ...result} | ||
return { | ||
view: template.view, | ||
tag: template.tag, | ||
dynamic: template.dynamic, | ||
type: template.type, | ||
attributes: template.attributes, | ||
children: template.children, | ||
offsets: template.offsets, | ||
variables | ||
} | ||
} | ||
@@ -313,0 +322,0 @@ |
{ | ||
"name": "@erickmerchant/framework", | ||
"version": "47.0.0", | ||
"version": "47.1.0", | ||
"description": "A front-end framework.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/erickmerchant/framework#readme", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17073
559