-
Notifications
You must be signed in to change notification settings - Fork 1
/
skruv.min.js.map
7 lines (7 loc) · 12.1 KB
/
skruv.min.js.map
1
2
3
4
5
6
7
{
"version": 3,
"sources": ["skruv.js"],
"sourcesContent": ["const htmlNS = 'http://www.w3.org/1999/xhtml'\n/** @type {import(\"./utilityTypes\").keyedMap} */\nconst keyed = new WeakMap()\n/** @type {import(\"./utilityTypes\").oldKeysMap} */\nconst oldKeys = new WeakMap()\n/** @type {import(\"./utilityTypes\").attributesMap} */\nconst attributesMap = new WeakMap()\n/** @type {import(\"./utilityTypes\").domCacheObj} */\nconst domCache = {}\n/**\n * @param {import(\"./utilityTypes\").Vnode} current\n * @param {import(\"./utilityTypes\").AnyRealElement} currentNode\n * @param {ParentNode?} parentNode\n * @param {string} ns\n */\nexport const render = (\n current,\n // @ts-expect-error\n currentNode = globalThis.document.documentElement,\n // @ts-expect-error\n parentNode = currentNode.parentNode,\n ns = htmlNS,\n forceFull = false\n) => {\n if (!parentNode) {\n throw new Error('No parent to render to')\n }\n if (typeof current === 'boolean' || !current) {\n // @ts-expect-error\n if (currentNode) { parentNode.removeChild(currentNode) }\n return\n }\n if (!globalThis?.isSkruvSSR && current?.t?.toLowerCase() === 'skruvtext' && current?.c?.[0]) {\n current.r = () => {\n // @ts-expect-error\n if (!currentNode || !parentNode.contains(currentNode)) { return false }\n render(current, currentNode, parentNode, ns)\n return true\n }\n // @ts-expect-error\n render(current?.c?.[0], currentNode)\n return\n }\n const txtNode = (typeof current === 'string' || typeof current === 'number')\n if (\n forceFull ||\n !currentNode ||\n (txtNode && currentNode.nodeName !== '#text') ||\n (!txtNode && currentNode.nodeName.toLowerCase() !== current.t.toLowerCase())\n ) {\n const _currentNode = currentNode\n if (txtNode) {\n // @ts-expect-error: When this is a textnode we will only use it for text, so this should be fine\n currentNode = document.createTextNode('' + current)\n } else {\n if (current.t === 'svg') { ns = 'http://www.w3.org/2000/svg' }\n if (current.t === 'math') { ns = 'http://www.w3.org/1998/Math/MathML' }\n if (current.t === 'feed') { ns = 'http://www.w3.org/2005/Atom' }\n if (current.t === 'urlset' || current.t === 'sitemapindex') { ns = 'https://www.sitemaps.org/schemas/sitemap/0.9' }\n // @ts-expect-error: All the nodes are actually elements, since the domCache only contains elements\n currentNode = (domCache[current.t] || (domCache[current.t] = document.createElementNS(ns, current.t))).cloneNode(false)\n }\n if (_currentNode) {\n // @ts-expect-error\n parentNode.replaceChild(currentNode, _currentNode)\n } else {\n // @ts-expect-error\n parentNode.appendChild(currentNode)\n }\n if (txtNode) { return }\n }\n if (txtNode) {\n // We do a loose comparison to allow for numbers\n // eslint-disable-next-line eqeqeq\n if (currentNode.textContent != current) { currentNode.textContent = '' + current }\n return\n }\n if (current.r) {\n current.r = () => {\n // @ts-expect-error\n if (!currentNode || !parentNode.contains(currentNode)) { return false }\n render(current, currentNode, parentNode, ns)\n return true\n }\n }\n // This needs to come after the .r callback is registered since it should apply to child nodes, not the current node.\n if (current.t === 'foreignObject') { ns = htmlNS }\n /** @type {import(\"./utilityTypes\").Vnode[]} */\n // @ts-expect-error\n let children = current.c.flat(Infinity)\n if (!globalThis?.isSkruvSSR) { children = children.filter(c => !c?.t?.startsWith('skruv')) }\n /** @type {import(\"./utilityTypes\").attributes} */\n // @ts-expect-error\n let attributes = {}\n if (children[0]?.constructor === Object && !children[0]?.isSkruvDom) {\n // @ts-expect-error\n attributes = children[0]\n children = children.slice(1)\n let oldAttributes = attributesMap.get(currentNode)\n if (!oldAttributes) {\n oldAttributes = {}\n attributesMap.set(currentNode, oldAttributes)\n }\n for (const [key, value] of Object.entries(attributes)) {\n if (('' + oldAttributes[key]) === ('' + value)) { continue }\n if (key === 'skruvAfterCreate') {\n // Run after we have processed all the attributes and children\n setTimeout(() => value(currentNode), 0)\n oldAttributes[key] = value\n continue\n }\n if (key.startsWith('skruv')) { continue }\n if (key[0] === 'o' && key[1] === 'n') {\n const evt = key.slice(2)\n if (!oldAttributes[key]) {\n if (oldAttributes[key]) { currentNode.removeEventListener(evt, value) }\n currentNode.addEventListener(evt, value)\n } else if (!value) {\n currentNode.removeEventListener(evt, value)\n }\n oldAttributes[key] = value\n continue\n }\n if (\n (key === 'checked' || key === 'selected' || key === 'value') ||\n currentNode.nodeName.includes('-') // Support complex data passing for custom elements\n ) {\n // @ts-expect-error We have to index the element for custom elements or setting checked/selected/value\n currentNode[key] = value\n }\n if (value !== undefined) {\n currentNode.setAttribute(key, '' + value)\n } else {\n currentNode.removeAttribute(key)\n }\n oldAttributes[key] = value\n }\n }\n for (const key of currentNode.getAttributeNames().filter(e => !Object.keys(attributes).includes(e))) {\n currentNode.removeAttribute(key)\n }\n if (!children.length && currentNode.childNodes.length) {\n if (attributes.skruvWaitForNotEmpty) {\n return\n }\n currentNode.replaceChildren()\n return\n }\n if (currentNode.childNodes.length > children.length) {\n for (let i = (currentNode.childNodes.length - 1); i >= children.length; i--) {\n currentNode.removeChild(currentNode.childNodes[i])\n }\n }\n for (let i = 0; i < children.length; i++) {\n let forceFull = false\n /** @type {Element} */\n let keyedNode\n if (children[i]?.c) {\n // @ts-expect-error\n keyedNode = keyed.get(children[i].c[0]?.skruvKey)\n if (keyedNode) {\n // @ts-expect-error\n if (keyedNode !== currentNode.childNodes[i]) {\n // @ts-expect-error\n if (keyedNode === currentNode.childNodes[i + 1]) {\n currentNode.removeChild(currentNode.childNodes[i])\n // @ts-expect-error\n } else if (currentNode.childNodes[i] && keyed.get(children[i + 1]?.c?.[0]?.skruvKey) === currentNode.childNodes[i]) {\n // @ts-expect-error\n currentNode.insertBefore(keyedNode, currentNode.childNodes[i])\n } else if (currentNode.childNodes[i]) {\n // @ts-expect-error\n currentNode.replaceChild(keyedNode, currentNode.childNodes[i])\n } else {\n // @ts-expect-error\n currentNode.appendChild(keyedNode)\n }\n }\n // @ts-expect-error\n forceFull = children[i].c[0].skruvKey !== oldKeys.get(currentNode.childNodes[i])\n if (!forceFull) {\n const lastKeyCopy = keyed.get(currentNode.childNodes[i])\n if (lastKeyCopy) {\n let noChange = true\n // @ts-expect-error\n for (const k in children[i].c[0].skruvKey) {\n // @ts-expect-error\n if (children[i].c[0].skruvKey[k] !== lastKeyCopy[k]) {\n noChange = false\n }\n }\n if (noChange) { continue }\n }\n }\n } else {\n forceFull = keyed.has(currentNode.childNodes[i])\n }\n }\n // @ts-expect-error: This will be fine since if the node is of the wrong type a new one is created\n render(children[i], currentNode.childNodes[i] || false, currentNode, ns, forceFull)\n }\n if (attributes.skruvKey) {\n keyed.set(attributes.skruvKey, currentNode)\n oldKeys.set(currentNode, attributes.skruvKey)\n keyed.set(currentNode, { ...attributes.skruvKey })\n }\n}\n\n/** @type {import(\"./utilityTypes\").ElementMap} */ // @ts-expect-error\nexport const elementFactory = new Proxy({}, { get: (_, t) => (...c) => ({ isSkruvDom: true, t, c }) })\n"],
"mappings": "AAAA,IAAMA,EAAS,+BAETC,EAAQ,IAAI,QAEZC,EAAU,IAAI,QAEdC,EAAgB,IAAI,QAEpBC,EAAW,CAAC,EAOLC,EAAS,CACpBC,EAEAC,EAAc,WAAW,SAAS,gBAElCC,EAAaD,EAAY,WACzBE,EAAKT,EACLU,EAAY,KACT,CACH,GAAI,CAACF,EACH,MAAM,IAAI,MAAM,wBAAwB,EAE1C,GAAI,OAAOF,GAAY,WAAa,CAACA,EAAS,CAExCC,GAAeC,EAAW,YAAYD,CAAW,EACrD,MACF,CACA,GAAI,CAAC,YAAY,YAAcD,GAAS,GAAG,YAAY,IAAM,aAAeA,GAAS,IAAI,CAAC,EAAG,CAC3FA,EAAQ,EAAI,IAEN,CAACC,GAAe,CAACC,EAAW,SAASD,CAAW,EAAY,IAChEF,EAAOC,EAASC,EAAaC,EAAYC,CAAE,EACpC,IAGTJ,EAAOC,GAAS,IAAI,CAAC,EAAGC,CAAW,EACnC,MACF,CACA,IAAMI,EAAW,OAAOL,GAAY,UAAY,OAAOA,GAAY,SACnE,GACEI,GACA,CAACH,GACAI,GAAWJ,EAAY,WAAa,SACpC,CAACI,GAAWJ,EAAY,SAAS,YAAY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AAM,EAAAa,EAAG,EAAAb,CAAE,EAAG,CAAC",
"names": ["htmlNS", "keyed", "oldKeys", "attributesMap", "domCache", "render", "current", "currentNode", "parentNode", "ns", "forceFull", "txtNode", "_currentNode", "children", "c", "attributes", "oldAttributes", "key", "value", "evt", "i", "keyedNode", "lastKeyCopy", "noChange", "k", "elementFactory", "_", "t"]
}