UNPKG

woby

Version:

A high-performance framework with fine-grained observable/signal-based reactivity for building rich applications.

254 lines (253 loc) 8.21 kB
import { i as isFunction, E as get, h as assign, K as once, F as FragmentUtils, L as resolveChild, q as isVoidChild, M as createText, N as SYMBOL_UNCACHED, P as createComment, Q as diff } from "./setters-Ddu0s6oK.js"; import { a1, a2, a4, S, Y, Z, _, a0, a3, I, l, $, w, U, V, W, X, u, R, J, T } from "./setters-Ddu0s6oK.js"; import { c as createElement } from "./create_element.ssr-B59OYen7.js"; import { m as memo, r as resolve, h as htm, u as useResource, a as useResolved } from "./merge_style-CyMhMoCQ.js"; import { o, E, F, I as I2, S as S2, c, T as T2, z, A, B, C, G, D, d, e, f, g, b, i, j, k, l as l2, n, p, q, s, t, v, w as w2, x, y } from "./merge_style-CyMhMoCQ.js"; import { F as F2 } from "./fragment-CrJfXftf.js"; import { r } from "./root-B8Ruf358.js"; import { t as t2 } from "./template-C8ap5u3t.js"; import { w as w3 } from "./wrap_clone_element-CPcdGL7P.js"; const Dynamic = ({ component, props /* , children */ }) => { if (isFunction(component) || isFunction(props)) { return memo(() => { return resolve(createElement( get(component, false), get(props) /* children */ )); }); } else { return createElement( component, props /* children */ ); } }; const registry = {}; const h = (type, props, ...children) => createElement(registry[type] || type, props, ...children); const register = (components) => void assign(registry, components); const html = assign(htm.bind(h), { register }); const lazy = (fetcher) => { const fetcherOnce = once(fetcher); const component = (props) => { const resource = useResource(fetcherOnce); return memo(() => { return useResolved(resource, ({ pending, error, value }) => { if (pending) return; if (error) throw error; const component2 = "default" in value ? value.default : value; return resolve(createElement(component2, props)); }); }); }; component.preload = () => { return new Promise((resolve2, reject) => { const resource = useResource(fetcherOnce); useResolved(resource, ({ pending, error }) => { if (pending) return; if (error) return reject(error); return resolve2(); }); }); }; return component; }; const setChildReplacementText = (child, childPrev) => { if (childPrev.nodeType === 3) { childPrev.nodeValue = child; return childPrev; } else { const parent = childPrev.parentElement; if (!parent) throw new Error("Invalid child replacement"); const textNode = createText(child); parent.replaceChild(textNode, childPrev); return textNode; } }; const setChildStatic = (parent, fragment, fragmentOnly, child, dynamic, stack) => { if (!dynamic && isVoidChild(child)) return; const prev = FragmentUtils.getChildren(fragment); const prevIsArray = prev instanceof Array; const prevLength = prevIsArray ? prev.length : 1; const prevFirst = prevIsArray ? prev[0] : prev; const prevLast = prevIsArray ? prev[prevLength - 1] : prev; const prevSibling = (prevLast == null ? void 0 : prevLast.nextSibling) || null; if (prevLength === 0) { const type = typeof child; if (type === "string" || type === "number" || type === "bigint") { const textNode = createText(child); if (!fragmentOnly) { parent.appendChild(textNode); } FragmentUtils.replaceWithNode(fragment, textNode); return; } else if (type === "object" && child !== null && typeof child.nodeType === "number") { const node = child; if (!fragmentOnly) { parent.insertBefore(node, null); } FragmentUtils.replaceWithNode(fragment, node); return; } } if (prevLength === 1) { const type = typeof child; if (type === "string" || type === "number" || type === "bigint") { const node = setChildReplacementText(String(child), prevFirst); FragmentUtils.replaceWithNode(fragment, node); return; } } const fragmentNext = FragmentUtils.make(); const children = Array.isArray(child) ? child : [child]; for (let i2 = 0, l3 = children.length; i2 < l3; i2++) { const child2 = children[i2]; const type = typeof child2; if (type === "string" || type === "number" || type === "bigint") { FragmentUtils.pushNode(fragmentNext, createText(child2)); } else if (type === "object" && child2 !== null && typeof child2.nodeType === "number") { FragmentUtils.pushNode(fragmentNext, child2); } else if (type === "function") { const fragment2 = FragmentUtils.make(); let childFragmentOnly = !fragmentOnly; FragmentUtils.pushFragment(fragmentNext, fragment2); resolveChild(child2, (child3, dynamic2, stack2) => { const fragmentOnly2 = childFragmentOnly; childFragmentOnly = false; setChildStatic(parent, fragment2, fragmentOnly2, child3, dynamic2, stack2); }, false, stack); } } let next = FragmentUtils.getChildren(fragmentNext); let nextLength = fragmentNext.length; if (nextLength === 0 && prevLength === 1 && prevFirst.nodeType === 8) { return; } if (!fragmentOnly && (nextLength === 0 || prevLength === 1 && prevFirst.nodeType === 8 || children[SYMBOL_UNCACHED])) { const { childNodes } = parent; if (childNodes.length === prevLength) { parent.textContent = ""; if (nextLength === 0) { const placeholder = createComment(""); FragmentUtils.pushNode(fragmentNext, placeholder); if (next !== fragmentNext.values) { next = placeholder; nextLength += 1; } } if (prevSibling) { if (next instanceof Array) { prevSibling.before.apply(prevSibling, next); } else { parent.insertBefore(next, prevSibling); } } else { if (next instanceof Array) { parent.append.apply(parent, next); } else { parent.append(next); } } FragmentUtils.replaceWithFragment(fragment, fragmentNext); return; } } if (nextLength === 0) { const placeholder = createComment(""); FragmentUtils.pushNode(fragmentNext, placeholder); if (next !== fragmentNext.values) { next = placeholder; nextLength += 1; } } if (!fragmentOnly) { diff(parent, prev, next, prevSibling); } FragmentUtils.replaceWithFragment(fragment, fragmentNext); }; const setChild = (parent, child, fragment = FragmentUtils.make(), stack) => { resolveChild(child, setChildStatic.bind(void 0, parent, fragment, false), false, stack); }; const renderToString = (child) => { const p2 = { children: null }; const stack = new Error(); setChild(p2, child, FragmentUtils.make(), stack); return p2.children.flat(Infinity).join(""); }; export { o as $, get as $$, a1 as CONTEXTS_DATA, a2 as DIRECTIVES, Dynamic, E as ErrorBoundary, F as For, F2 as Fragment, I2 as If, a4 as SYMBOLS_DIRECTIVES, S as SYMBOL_CLONE, Y as SYMBOL_OBSERVABLE, Z as SYMBOL_OBSERVABLE_FROZEN, _ as SYMBOL_OBSERVABLE_READABLE, a0 as SYMBOL_OBSERVABLE_WRITABLE, a3 as SYMBOL_SUSPENSE, I as SYMBOL_SUSPENSE_COLLECTOR, l as SYMBOL_TEMPLATE_ACCESSOR, SYMBOL_UNCACHED, $ as SYMBOL_UNTRACKED, w as SYMBOL_UNTRACKED_UNWRAPPED, S2 as Suspense, c as Switch, T2 as Ternary, z as batch, A as createContext, B as createDirective, createElement, createElement as h, C as hmr, html, U as isBatching, V as isObservable, W as isStore, lazy, G as mergeStyles, renderToString as render, renderToString, resolve, X as store, t2 as template, D as tick, u as untrack, d as useAbortController, e as useAbortSignal, f as useAnimationFrame, g as useAnimationLoop, b as useBoolean, R as useCleanup, i as useContext, j as useDisposed, J as useEffect, k as useEventListener, l2 as useFetch, n as useIdleCallback, p as useIdleLoop, q as useInterval, memo as useMemo, T as useMicrotask, s as usePromise, t as useReadonly, useResolved, useResource, r as useRoot, v as useSelector, w2 as useSuspended, x as useTimeout, y as useUntracked, w3 as wrapCloneElement }; //# sourceMappingURL=ssr.es.js.map