@lightningjs/solid
Advanced tools
Comparing version 0.6.8 to 0.6.9
@@ -1,4 +0,6 @@ | ||
import { createSignal, createRenderEffect, untrack, sharedConfig, createEffect, mergeProps as mergeProps$1, createRoot, createMemo, createComponent as createComponent$1 } from 'solid-js'; | ||
import { createSignal, createEffect } from 'solid-js'; | ||
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch } from 'solid-js'; | ||
import { MainRenderDriver, ThreadXRenderDriver, RendererMain } from '@lightningjs/renderer'; | ||
import { createRenderer } from 'solid-js/universal'; | ||
import { createElement as createElement$1, spread as spread$1, use as use$1, setProp as setProp$1, insert as insert$1 } from '@lightningjs/solid'; | ||
@@ -24,414 +26,2 @@ /* | ||
const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"]; | ||
const Properties = /*#__PURE__*/new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]); | ||
const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]); | ||
const Aliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
className: "class", | ||
htmlFor: "for" | ||
}); | ||
const PropAliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
class: "className", | ||
formnovalidate: { | ||
$: "formNoValidate", | ||
BUTTON: 1, | ||
INPUT: 1 | ||
}, | ||
ismap: { | ||
$: "isMap", | ||
IMG: 1 | ||
}, | ||
nomodule: { | ||
$: "noModule", | ||
SCRIPT: 1 | ||
}, | ||
playsinline: { | ||
$: "playsInline", | ||
VIDEO: 1 | ||
}, | ||
readonly: { | ||
$: "readOnly", | ||
INPUT: 1, | ||
TEXTAREA: 1 | ||
} | ||
}); | ||
function getPropAlias(prop, tagName) { | ||
const a = PropAliases[prop]; | ||
return typeof a === "object" ? a[tagName] ? a["$"] : undefined : a; | ||
} | ||
const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]); | ||
const SVGNamespace = { | ||
xlink: "http://www.w3.org/1999/xlink", | ||
xml: "http://www.w3.org/XML/1998/namespace" | ||
}; | ||
function reconcileArrays(parentNode, a, b) { | ||
let bLength = b.length, | ||
aEnd = a.length, | ||
bEnd = bLength, | ||
aStart = 0, | ||
bStart = 0, | ||
after = a[aEnd - 1].nextSibling, | ||
map = null; | ||
while (aStart < aEnd || bStart < bEnd) { | ||
if (a[aStart] === b[bStart]) { | ||
aStart++; | ||
bStart++; | ||
continue; | ||
} | ||
while (a[aEnd - 1] === b[bEnd - 1]) { | ||
aEnd--; | ||
bEnd--; | ||
} | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] : after; | ||
while (bStart < bEnd) parentNode.insertBefore(b[bStart++], node); | ||
} else if (bEnd === bStart) { | ||
while (aStart < aEnd) { | ||
if (!map || !map.has(a[aStart])) a[aStart].remove(); | ||
aStart++; | ||
} | ||
} else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) { | ||
const node = a[--aEnd].nextSibling; | ||
parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling); | ||
parentNode.insertBefore(b[--bEnd], node); | ||
a[aEnd] = b[bEnd]; | ||
} else { | ||
if (!map) { | ||
map = new Map(); | ||
let i = bStart; | ||
while (i < bEnd) map.set(b[i], i++); | ||
} | ||
const index = map.get(a[aStart]); | ||
if (index != null) { | ||
if (bStart < index && index < bEnd) { | ||
let i = aStart, | ||
sequence = 1, | ||
t; | ||
while (++i < aEnd && i < bEnd) { | ||
if ((t = map.get(a[i])) == null || t !== index + sequence) break; | ||
sequence++; | ||
} | ||
if (sequence > index - bStart) { | ||
const node = a[aStart]; | ||
while (bStart < index) parentNode.insertBefore(b[bStart++], node); | ||
} else parentNode.replaceChild(b[bStart++], a[aStart++]); | ||
} else aStart++; | ||
} else a[aStart++].remove(); | ||
} | ||
} | ||
} | ||
const $$EVENTS = "_$DX_DELEGATE"; | ||
function template(html, isCE, isSVG) { | ||
let node; | ||
const create = () => { | ||
const t = document.createElement("template"); | ||
t.innerHTML = html; | ||
return isSVG ? t.content.firstChild.firstChild : t.content.firstChild; | ||
}; | ||
const fn = isCE ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true); | ||
fn.cloneNode = fn; | ||
return fn; | ||
} | ||
function delegateEvents(eventNames, document = window.document) { | ||
const e = document[$$EVENTS] || (document[$$EVENTS] = new Set()); | ||
for (let i = 0, l = eventNames.length; i < l; i++) { | ||
const name = eventNames[i]; | ||
if (!e.has(name)) { | ||
e.add(name); | ||
document.addEventListener(name, eventHandler); | ||
} | ||
} | ||
} | ||
function setAttribute(node, name, value) { | ||
if (sharedConfig.context) return; | ||
if (value == null) node.removeAttribute(name);else node.setAttribute(name, value); | ||
} | ||
function setAttributeNS(node, namespace, name, value) { | ||
if (sharedConfig.context) return; | ||
if (value == null) node.removeAttributeNS(namespace, name);else node.setAttributeNS(namespace, name, value); | ||
} | ||
function className(node, value) { | ||
if (sharedConfig.context) return; | ||
if (value == null) node.removeAttribute("class");else node.className = value; | ||
} | ||
function addEventListener(node, name, handler, delegate) { | ||
if (delegate) { | ||
if (Array.isArray(handler)) { | ||
node[`$$${name}`] = handler[0]; | ||
node[`$$${name}Data`] = handler[1]; | ||
} else node[`$$${name}`] = handler; | ||
} else if (Array.isArray(handler)) { | ||
const handlerFn = handler[0]; | ||
node.addEventListener(name, handler[0] = e => handlerFn.call(node, handler[1], e)); | ||
} else node.addEventListener(name, handler); | ||
} | ||
function classList(node, value, prev = {}) { | ||
const classKeys = Object.keys(value || {}), | ||
prevKeys = Object.keys(prev); | ||
let i, len; | ||
for (i = 0, len = prevKeys.length; i < len; i++) { | ||
const key = prevKeys[i]; | ||
if (!key || key === "undefined" || value[key]) continue; | ||
toggleClassKey(node, key, false); | ||
delete prev[key]; | ||
} | ||
for (i = 0, len = classKeys.length; i < len; i++) { | ||
const key = classKeys[i], | ||
classValue = !!value[key]; | ||
if (!key || key === "undefined" || prev[key] === classValue || !classValue) continue; | ||
toggleClassKey(node, key, true); | ||
prev[key] = classValue; | ||
} | ||
return prev; | ||
} | ||
function style(node, value, prev) { | ||
if (!value) return prev ? setAttribute(node, "style") : value; | ||
const nodeStyle = node.style; | ||
if (typeof value === "string") return nodeStyle.cssText = value; | ||
typeof prev === "string" && (nodeStyle.cssText = prev = undefined); | ||
prev || (prev = {}); | ||
value || (value = {}); | ||
let v, s; | ||
for (s in prev) { | ||
value[s] == null && nodeStyle.removeProperty(s); | ||
delete prev[s]; | ||
} | ||
for (s in value) { | ||
v = value[s]; | ||
if (v !== prev[s]) { | ||
nodeStyle.setProperty(s, v); | ||
prev[s] = v; | ||
} | ||
} | ||
return prev; | ||
} | ||
function spread$1(node, props = {}, isSVG, skipChildren) { | ||
const prevProps = {}; | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
} | ||
createRenderEffect(() => props.ref && props.ref(node)); | ||
createRenderEffect(() => assign(node, props, isSVG, true, prevProps, true)); | ||
return prevProps; | ||
} | ||
function use$1(fn, element, arg) { | ||
return untrack(() => fn(element, arg)); | ||
} | ||
function insert$1(parent, accessor, marker, initial) { | ||
if (marker !== undefined && !initial) initial = []; | ||
if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker); | ||
createRenderEffect(current => insertExpression(parent, accessor(), current, marker), initial); | ||
} | ||
function assign(node, props, isSVG, skipChildren, prevProps = {}, skipRef = false) { | ||
props || (props = {}); | ||
for (const prop in prevProps) { | ||
if (!(prop in props)) { | ||
if (prop === "children") continue; | ||
prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef); | ||
} | ||
} | ||
for (const prop in props) { | ||
if (prop === "children") { | ||
if (!skipChildren) insertExpression(node, props.children); | ||
continue; | ||
} | ||
const value = props[prop]; | ||
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef); | ||
} | ||
} | ||
function toPropertyName(name) { | ||
return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase()); | ||
} | ||
function toggleClassKey(node, key, value) { | ||
const classNames = key.trim().split(/\s+/); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value); | ||
} | ||
function assignProp(node, prop, value, prev, isSVG, skipRef) { | ||
let isCE, isProp, isChildProp, propAlias, forceProp; | ||
if (prop === "style") return style(node, value, prev); | ||
if (prop === "classList") return classList(node, value, prev); | ||
if (value === prev) return prev; | ||
if (prop === "ref") { | ||
if (!skipRef) value(node); | ||
} else if (prop.slice(0, 3) === "on:") { | ||
const e = prop.slice(3); | ||
prev && node.removeEventListener(e, prev); | ||
value && node.addEventListener(e, value); | ||
} else if (prop.slice(0, 10) === "oncapture:") { | ||
const e = prop.slice(10); | ||
prev && node.removeEventListener(e, prev, true); | ||
value && node.addEventListener(e, value, true); | ||
} else if (prop.slice(0, 2) === "on") { | ||
const name = prop.slice(2).toLowerCase(); | ||
const delegate = DelegatedEvents.has(name); | ||
if (!delegate && prev) { | ||
const h = Array.isArray(prev) ? prev[0] : prev; | ||
node.removeEventListener(name, h); | ||
} | ||
if (delegate || value) { | ||
addEventListener(node, name, value, delegate); | ||
delegate && delegateEvents([name]); | ||
} | ||
} else if (prop.slice(0, 5) === "attr:") { | ||
setAttribute(node, prop.slice(5), value); | ||
} else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) { | ||
if (forceProp) { | ||
prop = prop.slice(5); | ||
isProp = true; | ||
} else if (sharedConfig.context) return value; | ||
if (prop === "class" || prop === "className") className(node, value);else if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[propAlias || prop] = value; | ||
} else { | ||
const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]]; | ||
if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value); | ||
} | ||
return value; | ||
} | ||
function eventHandler(e) { | ||
const key = `$$${e.type}`; | ||
let node = e.composedPath && e.composedPath()[0] || e.target; | ||
if (e.target !== node) { | ||
Object.defineProperty(e, "target", { | ||
configurable: true, | ||
value: node | ||
}); | ||
} | ||
Object.defineProperty(e, "currentTarget", { | ||
configurable: true, | ||
get() { | ||
return node || document; | ||
} | ||
}); | ||
if (sharedConfig.registry && !sharedConfig.done) sharedConfig.done = _$HY.done = true; | ||
while (node) { | ||
const handler = node[key]; | ||
if (handler && !node.disabled) { | ||
const data = node[`${key}Data`]; | ||
data !== undefined ? handler.call(node, data, e) : handler.call(node, e); | ||
if (e.cancelBubble) return; | ||
} | ||
node = node._$host || node.parentNode || node.host; | ||
} | ||
} | ||
function insertExpression(parent, value, current, marker, unwrapArray) { | ||
if (sharedConfig.context) { | ||
!current && (current = [...parent.childNodes]); | ||
let cleaned = []; | ||
for (let i = 0; i < current.length; i++) { | ||
const node = current[i]; | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove();else cleaned.push(node); | ||
} | ||
current = cleaned; | ||
} | ||
while (typeof current === "function") current = current(); | ||
if (value === current) return current; | ||
const t = typeof value, | ||
multi = marker !== undefined; | ||
parent = multi && current[0] && current[0].parentNode || parent; | ||
if (t === "string" || t === "number") { | ||
if (sharedConfig.context) return current; | ||
if (t === "number") value = value.toString(); | ||
if (multi) { | ||
let node = current[0]; | ||
if (node && node.nodeType === 3) { | ||
node.data = value; | ||
} else node = document.createTextNode(value); | ||
current = cleanChildren(parent, current, marker, node); | ||
} else { | ||
if (current !== "" && typeof current === "string") { | ||
current = parent.firstChild.data = value; | ||
} else current = parent.textContent = value; | ||
} | ||
} else if (value == null || t === "boolean") { | ||
if (sharedConfig.context) return current; | ||
current = cleanChildren(parent, current, marker); | ||
} else if (t === "function") { | ||
createRenderEffect(() => { | ||
let v = value(); | ||
while (typeof v === "function") v = v(); | ||
current = insertExpression(parent, v, current, marker); | ||
}); | ||
return () => current; | ||
} else if (Array.isArray(value)) { | ||
const array = []; | ||
const currentArray = current && Array.isArray(current); | ||
if (normalizeIncomingArray(array, value, current, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
return () => current; | ||
} | ||
if (sharedConfig.context) { | ||
if (!array.length) return current; | ||
if (marker === undefined) return [...parent.childNodes]; | ||
let node = array[0]; | ||
let nodes = [node]; | ||
while ((node = node.nextSibling) !== marker) nodes.push(node); | ||
return current = nodes; | ||
} | ||
if (array.length === 0) { | ||
current = cleanChildren(parent, current, marker); | ||
if (multi) return current; | ||
} else if (currentArray) { | ||
if (current.length === 0) { | ||
appendNodes(parent, array, marker); | ||
} else reconcileArrays(parent, current, array); | ||
} else { | ||
current && cleanChildren(parent); | ||
appendNodes(parent, array); | ||
} | ||
current = array; | ||
} else if (value.nodeType) { | ||
if (sharedConfig.context && value.parentNode) return current = multi ? [value] : value; | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
cleanChildren(parent, current, null, value); | ||
} else if (current == null || current === "" || !parent.firstChild) { | ||
parent.appendChild(value); | ||
} else parent.replaceChild(value, parent.firstChild); | ||
current = value; | ||
} else ; | ||
return current; | ||
} | ||
function normalizeIncomingArray(normalized, array, current, unwrap) { | ||
let dynamic = false; | ||
for (let i = 0, len = array.length; i < len; i++) { | ||
let item = array[i], | ||
prev = current && current[i], | ||
t; | ||
if (item == null || item === true || item === false) ;else if ((t = typeof item) === "object" && item.nodeType) { | ||
normalized.push(item); | ||
} else if (Array.isArray(item)) { | ||
dynamic = normalizeIncomingArray(normalized, item, prev) || dynamic; | ||
} else if (t === "function") { | ||
if (unwrap) { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item], Array.isArray(prev) ? prev : [prev]) || dynamic; | ||
} else { | ||
normalized.push(item); | ||
dynamic = true; | ||
} | ||
} else { | ||
const value = String(item); | ||
if (prev && prev.nodeType === 3 && prev.data === value) normalized.push(prev);else normalized.push(document.createTextNode(value)); | ||
} | ||
} | ||
return dynamic; | ||
} | ||
function appendNodes(parent, array, marker = null) { | ||
for (let i = 0, len = array.length; i < len; i++) parent.insertBefore(array[i], marker); | ||
} | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) return parent.textContent = ""; | ||
const node = replacement || document.createTextNode(""); | ||
if (current.length) { | ||
let inserted = false; | ||
for (let i = current.length - 1; i >= 0; i--) { | ||
const el = current[i]; | ||
if (node !== el) { | ||
const isParent = el.parentNode === parent; | ||
if (!inserted && !i) isParent ? parent.replaceChild(node, el) : parent.insertBefore(node, marker);else isParent && el.remove(); | ||
} else inserted = true; | ||
} | ||
} else parent.insertBefore(node, marker); | ||
return [node]; | ||
} | ||
const _tmpl$$2 = /*#__PURE__*/template(`<svg><text></svg>`, false, true); | ||
/* | ||
@@ -456,4 +46,4 @@ * Copyright 2023 Comcast Cable Communications Management, LLC | ||
return (() => { | ||
const _el$ = _tmpl$$2(); | ||
spread$1(_el$, props, true, false); | ||
const _el$ = createElement$1("text"); | ||
spread$1(_el$, props, false); | ||
return _el$; | ||
@@ -463,3 +53,2 @@ })(); | ||
const _tmpl$$1 = /*#__PURE__*/template(`<node>`); | ||
/* | ||
@@ -484,4 +73,4 @@ * Copyright 2023 Comcast Cable Communications Management, LLC | ||
return (() => { | ||
const _el$ = _tmpl$$1(); | ||
spread$1(_el$, props, false, false); | ||
const _el$ = createElement$1("node"); | ||
spread$1(_el$, props, false); | ||
return _el$; | ||
@@ -1294,3 +883,2 @@ })(); | ||
const _tmpl$ = /*#__PURE__*/template(`<canvas zindex=0.1>`); | ||
function renderTopDown(node) { | ||
@@ -1316,5 +904,6 @@ if (node.name === 'TextNode') { | ||
return (() => { | ||
const _el$ = _tmpl$(); | ||
const _el$ = createElement$1("canvas"); | ||
const _ref$ = root; | ||
typeof _ref$ === "function" ? use$1(_ref$, _el$) : root = _el$; | ||
setProp$1(_el$, "zIndex", 0.1); | ||
insert$1(_el$, () => props.children); | ||
@@ -1325,239 +914,2 @@ return _el$; | ||
function createRenderer$1({ | ||
createElement, | ||
createTextNode, | ||
isTextNode, | ||
replaceText, | ||
insertNode, | ||
removeNode, | ||
setProperty, | ||
getParentNode, | ||
getFirstChild, | ||
getNextSibling | ||
}) { | ||
function insert(parent, accessor, marker, initial) { | ||
if (marker !== undefined && !initial) initial = []; | ||
if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker); | ||
createRenderEffect(current => insertExpression(parent, accessor(), current, marker), initial); | ||
} | ||
function insertExpression(parent, value, current, marker, unwrapArray) { | ||
while (typeof current === "function") current = current(); | ||
if (value === current) return current; | ||
const t = typeof value, | ||
multi = marker !== undefined; | ||
if (t === "string" || t === "number") { | ||
if (t === "number") value = value.toString(); | ||
if (multi) { | ||
let node = current[0]; | ||
if (node && isTextNode(node)) { | ||
replaceText(node, value); | ||
} else node = createTextNode(value); | ||
current = cleanChildren(parent, current, marker, node); | ||
} else { | ||
if (current !== "" && typeof current === "string") { | ||
replaceText(getFirstChild(parent), current = value); | ||
} else { | ||
cleanChildren(parent, current, marker, createTextNode(value)); | ||
current = value; | ||
} | ||
} | ||
} else if (value == null || t === "boolean") { | ||
current = cleanChildren(parent, current, marker); | ||
} else if (t === "function") { | ||
createRenderEffect(() => { | ||
let v = value(); | ||
while (typeof v === "function") v = v(); | ||
current = insertExpression(parent, v, current, marker); | ||
}); | ||
return () => current; | ||
} else if (Array.isArray(value)) { | ||
const array = []; | ||
if (normalizeIncomingArray(array, value, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
return () => current; | ||
} | ||
if (array.length === 0) { | ||
const replacement = cleanChildren(parent, current, marker); | ||
if (multi) return current = replacement; | ||
} else { | ||
if (Array.isArray(current)) { | ||
if (current.length === 0) { | ||
appendNodes(parent, array, marker); | ||
} else reconcileArrays(parent, current, array); | ||
} else if (current == null || current === "") { | ||
appendNodes(parent, array); | ||
} else { | ||
reconcileArrays(parent, multi && current || [getFirstChild(parent)], array); | ||
} | ||
} | ||
current = array; | ||
} else { | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
cleanChildren(parent, current, null, value); | ||
} else if (current == null || current === "" || !getFirstChild(parent)) { | ||
insertNode(parent, value); | ||
} else replaceNode(parent, value, getFirstChild(parent)); | ||
current = value; | ||
} | ||
return current; | ||
} | ||
function normalizeIncomingArray(normalized, array, unwrap) { | ||
let dynamic = false; | ||
for (let i = 0, len = array.length; i < len; i++) { | ||
let item = array[i], | ||
t; | ||
if (item == null || item === true || item === false) ;else if (Array.isArray(item)) { | ||
dynamic = normalizeIncomingArray(normalized, item) || dynamic; | ||
} else if ((t = typeof item) === "string" || t === "number") { | ||
normalized.push(createTextNode(item)); | ||
} else if (t === "function") { | ||
if (unwrap) { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
} else { | ||
normalized.push(item); | ||
dynamic = true; | ||
} | ||
} else normalized.push(item); | ||
} | ||
return dynamic; | ||
} | ||
function reconcileArrays(parentNode, a, b) { | ||
let bLength = b.length, | ||
aEnd = a.length, | ||
bEnd = bLength, | ||
aStart = 0, | ||
bStart = 0, | ||
after = getNextSibling(a[aEnd - 1]), | ||
map = null; | ||
while (aStart < aEnd || bStart < bEnd) { | ||
if (a[aStart] === b[bStart]) { | ||
aStart++; | ||
bStart++; | ||
continue; | ||
} | ||
while (a[aEnd - 1] === b[bEnd - 1]) { | ||
aEnd--; | ||
bEnd--; | ||
} | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart] : after; | ||
while (bStart < bEnd) insertNode(parentNode, b[bStart++], node); | ||
} else if (bEnd === bStart) { | ||
while (aStart < aEnd) { | ||
if (!map || !map.has(a[aStart])) removeNode(parentNode, a[aStart]); | ||
aStart++; | ||
} | ||
} else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) { | ||
const node = getNextSibling(a[--aEnd]); | ||
insertNode(parentNode, b[bStart++], getNextSibling(a[aStart++])); | ||
insertNode(parentNode, b[--bEnd], node); | ||
a[aEnd] = b[bEnd]; | ||
} else { | ||
if (!map) { | ||
map = new Map(); | ||
let i = bStart; | ||
while (i < bEnd) map.set(b[i], i++); | ||
} | ||
const index = map.get(a[aStart]); | ||
if (index != null) { | ||
if (bStart < index && index < bEnd) { | ||
let i = aStart, | ||
sequence = 1, | ||
t; | ||
while (++i < aEnd && i < bEnd) { | ||
if ((t = map.get(a[i])) == null || t !== index + sequence) break; | ||
sequence++; | ||
} | ||
if (sequence > index - bStart) { | ||
const node = a[aStart]; | ||
while (bStart < index) insertNode(parentNode, b[bStart++], node); | ||
} else replaceNode(parentNode, b[bStart++], a[aStart++]); | ||
} else aStart++; | ||
} else removeNode(parentNode, a[aStart++]); | ||
} | ||
} | ||
} | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) { | ||
let removed; | ||
while (removed = getFirstChild(parent)) removeNode(parent, removed); | ||
replacement && insertNode(parent, replacement); | ||
return ""; | ||
} | ||
const node = replacement || createTextNode(""); | ||
if (current.length) { | ||
let inserted = false; | ||
for (let i = current.length - 1; i >= 0; i--) { | ||
const el = current[i]; | ||
if (node !== el) { | ||
const isParent = getParentNode(el) === parent; | ||
if (!inserted && !i) isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker);else isParent && removeNode(parent, el); | ||
} else inserted = true; | ||
} | ||
} else insertNode(parent, node, marker); | ||
return [node]; | ||
} | ||
function appendNodes(parent, array, marker) { | ||
for (let i = 0, len = array.length; i < len; i++) insertNode(parent, array[i], marker); | ||
} | ||
function replaceNode(parent, newNode, oldNode) { | ||
insertNode(parent, newNode, oldNode); | ||
removeNode(parent, oldNode); | ||
} | ||
function spreadExpression(node, props, prevProps = {}, skipChildren) { | ||
props || (props = {}); | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
} | ||
createRenderEffect(() => props.ref && props.ref(node)); | ||
createRenderEffect(() => { | ||
for (const prop in props) { | ||
if (prop === "children" || prop === "ref") continue; | ||
const value = props[prop]; | ||
if (value === prevProps[prop]) continue; | ||
setProperty(node, prop, value, prevProps[prop]); | ||
prevProps[prop] = value; | ||
} | ||
}); | ||
return prevProps; | ||
} | ||
return { | ||
render(code, element) { | ||
let disposer; | ||
createRoot(dispose => { | ||
disposer = dispose; | ||
insert(element, code()); | ||
}); | ||
return disposer; | ||
}, | ||
insert, | ||
spread(node, accessor, skipChildren) { | ||
if (typeof accessor === "function") { | ||
createRenderEffect(current => spreadExpression(node, accessor(), current, skipChildren)); | ||
} else spreadExpression(node, accessor, undefined, skipChildren); | ||
}, | ||
createElement, | ||
createTextNode, | ||
insertNode, | ||
setProp(node, name, value, prev) { | ||
setProperty(node, name, value, prev); | ||
return value; | ||
}, | ||
mergeProps: mergeProps$1, | ||
effect: createRenderEffect, | ||
memo: createMemo, | ||
createComponent: createComponent$1, | ||
use(fn, element, arg) { | ||
return untrack(() => fn(element, arg)); | ||
} | ||
}; | ||
} | ||
function createRenderer(options) { | ||
const renderer = createRenderer$1(options); | ||
renderer.mergeProps = mergeProps$1; | ||
return renderer; | ||
} | ||
/* | ||
@@ -1564,0 +916,0 @@ * Copyright 2023 Comcast Cable Communications Management, LLC |
{ | ||
"name": "@lightningjs/solid", | ||
"version": "0.6.8", | ||
"version": "0.6.9", | ||
"description": "Lightning renderer for solid universal", | ||
@@ -70,2 +70,3 @@ "type": "module", | ||
"dependencies": { | ||
"@lightningjs/solid": "file:./", | ||
"@lightningjs/renderer": "^0.3.6" | ||
@@ -72,0 +73,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
237552
3
3979
+ Added@lightningjs/solid@file:./