solid-js
Version:
A declarative JavaScript library for building user interfaces.
778 lines (771 loc) • 28 kB
JavaScript
import { createMemo, sharedConfig, createRoot, splitProps } from 'solid-js';
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, createRenderEffect as effect, getOwner, mergeProps, untrack } from 'solid-js';
import { Feature, Serializer, getCrossReferenceHeader } from 'seroval';
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
const booleans = ["allowfullscreen", "async", "alpha",
"autofocus",
"autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden",
"indeterminate", "inert",
"ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless",
"selected", "adauctionheaders",
"browsingtopics",
"credentialless",
"defaultchecked", "defaultmuted", "defaultselected", "defer", "disablepictureinpicture", "disableremoteplayback", "preservespitch",
"shadowrootclonable", "shadowrootcustomelementregistry",
"shadowrootdelegatesfocus", "shadowrootserializable",
"sharedstoragewritable"
];
const BooleanAttributes = /*#__PURE__*/new Set(booleans);
const Properties = /*#__PURE__*/new Set([
"className", "value",
"readOnly", "noValidate", "formNoValidate", "isMap", "noModule", "playsInline", "adAuctionHeaders",
"allowFullscreen", "browsingTopics",
"defaultChecked", "defaultMuted", "defaultSelected", "disablePictureInPicture", "disableRemotePlayback", "preservesPitch", "shadowRootClonable", "shadowRootCustomElementRegistry",
"shadowRootDelegatesFocus", "shadowRootSerializable",
"sharedStorageWritable",
...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",
novalidate: {
$: "noValidate",
FORM: 1
},
formnovalidate: {
$: "formNoValidate",
BUTTON: 1,
INPUT: 1
},
ismap: {
$: "isMap",
IMG: 1
},
nomodule: {
$: "noModule",
SCRIPT: 1
},
playsinline: {
$: "playsInline",
VIDEO: 1
},
readonly: {
$: "readOnly",
INPUT: 1,
TEXTAREA: 1
},
adauctionheaders: {
$: "adAuctionHeaders",
IFRAME: 1
},
allowfullscreen: {
$: "allowFullscreen",
IFRAME: 1
},
browsingtopics: {
$: "browsingTopics",
IMG: 1
},
defaultchecked: {
$: "defaultChecked",
INPUT: 1
},
defaultmuted: {
$: "defaultMuted",
AUDIO: 1,
VIDEO: 1
},
defaultselected: {
$: "defaultSelected",
OPTION: 1
},
disablepictureinpicture: {
$: "disablePictureInPicture",
VIDEO: 1
},
disableremoteplayback: {
$: "disableRemotePlayback",
AUDIO: 1,
VIDEO: 1
},
preservespitch: {
$: "preservesPitch",
AUDIO: 1,
VIDEO: 1
},
shadowrootclonable: {
$: "shadowRootClonable",
TEMPLATE: 1
},
shadowrootdelegatesfocus: {
$: "shadowRootDelegatesFocus",
TEMPLATE: 1
},
shadowrootserializable: {
$: "shadowRootSerializable",
TEMPLATE: 1
},
sharedstoragewritable: {
$: "sharedStorageWritable",
IFRAME: 1,
IMG: 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 SVGElements = /*#__PURE__*/new Set([
"altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect",
"set", "stop",
"svg", "switch", "symbol", "text", "textPath",
"tref", "tspan", "use", "view", "vkern"]);
const SVGNamespace = {
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace"
};
const DOMElements = /*#__PURE__*/new Set(["html", "base", "head", "link", "meta", "style", "title", "body", "address", "article", "aside", "footer", "header", "main", "nav", "section", "body", "blockquote", "dd", "div", "dl", "dt", "figcaption", "figure", "hr", "li", "ol", "p", "pre", "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn", "em", "i", "kbd", "mark", "q", "rp", "rt", "ruby", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "area", "audio", "img", "map", "track", "video", "embed", "iframe", "object", "param", "picture", "portal", "source", "svg", "math", "canvas", "noscript", "script", "del", "ins", "caption", "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "button", "datalist", "fieldset", "form", "input", "label", "legend", "meter", "optgroup", "option", "output", "progress", "select", "textarea", "details", "dialog", "menu", "summary", "details", "slot", "template", "acronym", "applet", "basefont", "bgsound", "big", "blink", "center", "content", "dir", "font", "frame", "frameset", "hgroup", "image", "keygen", "marquee", "menuitem", "nobr", "noembed", "noframes", "plaintext", "rb", "rtc", "shadow", "spacer", "strike", "tt", "xmp", "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "main", "map", "mark", "marquee", "menu", "menuitem", "meta", "meter", "nav", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "portal", "pre", "progress", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp", "input", "h1", "h2", "h3", "h4", "h5", "h6",
"webview",
"isindex", "listing", "multicol", "nextid", "noindex", "search"]);
const memo = fn => createMemo(() => fn());
const ES2017FLAG = Feature.AggregateError
| Feature.BigIntTypedArray;
const GLOBAL_IDENTIFIER = '_$HY.r';
function createSerializer({
onData,
onDone,
scopeId,
onError
}) {
return new Serializer({
scopeId,
plugins: [AbortSignalPlugin,
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin],
globalIdentifier: GLOBAL_IDENTIFIER,
disabledFeatures: ES2017FLAG,
onData,
onDone,
onError
});
}
function getLocalHeaderScript(id) {
return getCrossReferenceHeader(id) + ';';
}
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
const REPLACE_SCRIPT = `function $df(e,n,o,t){if(n=document.getElementById(e),o=document.getElementById("pl-"+e)){for(;o&&8!==o.nodeType&&o.nodeValue!=="pl-"+e;)t=o.nextSibling,o.remove(),o=t;_$HY.done?o.remove():o.replaceWith(n.content)}n.remove(),_$HY.fe(e)}`;
function renderToString(code, options = {}) {
const {
renderId
} = options;
let scripts = "";
const serializer = createSerializer({
scopeId: renderId,
onData(script) {
if (!scripts) {
scripts = getLocalHeaderScript(renderId);
}
scripts += script + ";";
},
onError: options.onError
});
sharedConfig.context = {
id: renderId || "",
count: 0,
suspense: {},
lazy: {},
assets: [],
nonce: options.nonce,
serialize(id, p) {
!sharedConfig.context.noHydrate && serializer.write(id, p);
},
roots: 0,
nextRoot() {
return this.renderId + "i-" + this.roots++;
}
};
let html = createRoot(d => {
setTimeout(d);
return resolveSSRNode(escape(code()));
});
sharedConfig.context.noHydrate = true;
serializer.close();
html = injectAssets(sharedConfig.context.assets, html);
if (scripts.length) html = injectScripts(html, scripts, options.nonce);
return html;
}
function renderToStringAsync(code, options = {}) {
const {
timeoutMs = 30000
} = options;
let timeoutHandle;
const timeout = new Promise((_, reject) => {
timeoutHandle = setTimeout(() => reject("renderToString timed out"), timeoutMs);
});
return Promise.race([renderToStream(code, options), timeout]).then(html => {
clearTimeout(timeoutHandle);
return html;
});
}
function renderToStream(code, options = {}) {
let {
nonce,
onCompleteShell,
onCompleteAll,
renderId,
noScripts
} = options;
let dispose;
const blockingPromises = [];
const pushTask = task => {
if (noScripts) return;
if (!tasks && !firstFlushed) {
tasks = getLocalHeaderScript(renderId);
}
tasks += task + ";";
if (!timer && firstFlushed) {
timer = setTimeout(writeTasks);
}
};
const onDone = () => {
writeTasks();
doShell();
onCompleteAll && onCompleteAll({
write(v) {
!completed && buffer.write(v);
}
});
writable && writable.end();
completed = true;
if (firstFlushed) dispose();
};
const serializer = createSerializer({
scopeId: options.renderId,
onData: pushTask,
onDone,
onError: options.onError
});
const flushEnd = () => {
if (!registry.size) {
queue(() => queue(() => serializer.flush()));
}
};
const registry = new Map();
const writeTasks = () => {
if (tasks.length && !completed && firstFlushed) {
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks}</script>`);
tasks = "";
}
timer && clearTimeout(timer);
timer = null;
};
let context;
let writable;
let tmp = "";
let tasks = "";
let firstFlushed = false;
let completed = false;
let shellCompleted = false;
let scriptFlushed = false;
let timer = null;
let buffer = {
write(payload) {
tmp += payload;
}
};
sharedConfig.context = context = {
id: renderId || "",
count: 0,
async: true,
resources: {},
lazy: {},
suspense: {},
assets: [],
nonce,
block(p) {
if (!firstFlushed) blockingPromises.push(p);
},
replace(id, payloadFn) {
if (firstFlushed) return;
const placeholder = `<!--!$${id}-->`;
const first = html.indexOf(placeholder);
if (first === -1) return;
const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length);
html = html.slice(0, first) + resolveSSRNode(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
},
serialize(id, p, wait) {
const serverOnly = sharedConfig.context.noHydrate;
if (!firstFlushed && wait && typeof p === "object" && "then" in p) {
blockingPromises.push(p);
!serverOnly && p.then(d => {
serializer.write(id, d);
}).catch(e => {
serializer.write(id, e);
});
} else if (!serverOnly) serializer.write(id, p);
},
roots: 0,
nextRoot() {
return this.renderId + "i-" + this.roots++;
},
registerFragment(key) {
if (!registry.has(key)) {
let resolve, reject;
const p = new Promise((r, rej) => (resolve = r, reject = rej));
registry.set(key, err => queue(() => queue(() => {
err ? reject(err) : resolve(true);
queue(flushEnd);
})));
serializer.write(key, p);
}
return (value, error) => {
if (registry.has(key)) {
const resolve = registry.get(key);
registry.delete(key);
if (waitForFragments(registry, key)) {
resolve();
return;
}
if (!completed) {
if (!firstFlushed) {
queue(() => html = replacePlaceholder(html, key, value !== undefined ? value : ""));
resolve(error);
} else {
buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
pushTask(`$df("${key}")${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
resolve(error);
scriptFlushed = true;
}
}
}
return firstFlushed;
};
}
};
let html = createRoot(d => {
dispose = d;
return resolveSSRNode(escape(code()));
});
function doShell() {
if (shellCompleted) return;
sharedConfig.context = context;
context.noHydrate = true;
html = injectAssets(context.assets, html);
if (tasks.length) html = injectScripts(html, tasks, nonce);
buffer.write(html);
tasks = "";
onCompleteShell && onCompleteShell({
write(v) {
!completed && buffer.write(v);
}
});
shellCompleted = true;
}
return {
then(fn) {
function complete() {
dispose();
fn(tmp);
}
if (onCompleteAll) {
let ogComplete = onCompleteAll;
onCompleteAll = options => {
ogComplete(options);
complete();
};
} else onCompleteAll = complete;
queue(flushEnd);
},
pipe(w) {
allSettled(blockingPromises).then(() => {
setTimeout(() => {
doShell();
buffer = writable = w;
buffer.write(tmp);
firstFlushed = true;
if (completed) {
dispose();
writable.end();
} else flushEnd();
});
});
},
pipeTo(w) {
return allSettled(blockingPromises).then(() => {
let resolve;
const p = new Promise(r => resolve = r);
setTimeout(() => {
doShell();
const encoder = new TextEncoder();
const writer = w.getWriter();
writable = {
end() {
writer.releaseLock();
w.close();
resolve();
}
};
buffer = {
write(payload) {
writer.write(encoder.encode(payload));
}
};
buffer.write(tmp);
firstFlushed = true;
if (completed) {
dispose();
writable.end();
} else flushEnd();
});
return p;
});
}
};
}
function HydrationScript(props) {
const {
nonce
} = sharedConfig.context;
return ssr(generateHydrationScript({
nonce,
...props
}));
}
function ssr(t, ...nodes) {
if (nodes.length) {
let result = "";
for (let i = 0; i < nodes.length; i++) {
result += t[i];
const node = nodes[i];
if (node !== undefined) result += resolveSSRNode(node);
}
t = result + t[nodes.length];
}
return {
t
};
}
function ssrClassList(value) {
if (!value) return "";
let classKeys = Object.keys(value),
result = "";
for (let i = 0, len = classKeys.length; i < len; i++) {
const key = classKeys[i],
classValue = !!value[key];
if (!key || key === "undefined" || !classValue) continue;
i && (result += " ");
result += escape(key);
}
return result;
}
function ssrStyle(value) {
if (!value) return "";
if (typeof value === "string") return escape(value, true);
let result = "";
const k = Object.keys(value);
for (let i = 0; i < k.length; i++) {
const s = k[i];
const v = value[s];
if (v != undefined) {
if (i) result += ";";
const r = escape(v, true);
if (r != undefined && r !== "undefined") {
result += `${s}:${r}`;
}
}
}
return result;
}
function ssrStyleProperty(name, value) {
return value != null ? name + value : "";
}
function ssrElement(tag, props, children, needsId) {
if (props == null) props = {};else if (typeof props === "function") props = props();
const skipChildren = VOID_ELEMENTS.test(tag);
const keys = Object.keys(props);
let result = `<${tag}${needsId ? ssrHydrationKey() : ""} `;
let classResolved;
for (let i = 0; i < keys.length; i++) {
const prop = keys[i];
if (ChildProperties.has(prop)) {
if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? props[prop] : escape(props[prop]);
continue;
}
const value = props[prop];
if (prop === "style") {
result += `style="${ssrStyle(value)}"`;
} else if (prop === "class" || prop === "className" || prop === "classList") {
if (classResolved) continue;
let n;
result += `class="${escape(((n = props.class) ? n + " " : "") + ((n = props.className) ? n + " " : ""), true) + ssrClassList(props.classList)}"`;
classResolved = true;
} else if (BooleanAttributes.has(prop)) {
if (value) result += prop;else continue;
} else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
continue;
} else if (prop.slice(0, 5) === "bool:") {
if (!value) continue;
result += escape(prop.slice(5));
} else if (prop.slice(0, 5) === "attr:") {
result += `${escape(prop.slice(5))}="${escape(value, true)}"`;
} else {
result += `${Aliases[prop] || escape(prop)}="${escape(value, true)}"`;
}
if (i !== keys.length - 1) result += " ";
}
if (skipChildren) return {
t: result + "/>"
};
if (typeof children === "function") children = children();
return {
t: result + `>${resolveSSRNode(children, true)}</${tag}>`
};
}
function ssrAttribute(key, value, isBoolean) {
return isBoolean ? value ? " " + key : "" : value != null ? ` ${key}="${value}"` : "";
}
function ssrHydrationKey() {
const hk = getHydrationKey();
return hk ? ` data-hk=${hk}` : "";
}
function escape(s, attr) {
const t = typeof s;
if (t !== "string") {
if (!attr && t === "function") return escape(s());
if (!attr && Array.isArray(s)) {
s = s.slice();
for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
return s;
}
if (attr && t === "boolean") return String(s);
return s;
}
const delim = attr ? '"' : "<";
const escDelim = attr ? """ : "<";
let iDelim = s.indexOf(delim);
let iAmp = s.indexOf("&");
if (iDelim < 0 && iAmp < 0) return s;
let left = 0,
out = "";
while (iDelim >= 0 && iAmp >= 0) {
if (iDelim < iAmp) {
if (left < iDelim) out += s.substring(left, iDelim);
out += escDelim;
left = iDelim + 1;
iDelim = s.indexOf(delim, left);
} else {
if (left < iAmp) out += s.substring(left, iAmp);
out += "&";
left = iAmp + 1;
iAmp = s.indexOf("&", left);
}
}
if (iDelim >= 0) {
do {
if (left < iDelim) out += s.substring(left, iDelim);
out += escDelim;
left = iDelim + 1;
iDelim = s.indexOf(delim, left);
} while (iDelim >= 0);
} else while (iAmp >= 0) {
if (left < iAmp) out += s.substring(left, iAmp);
out += "&";
left = iAmp + 1;
iAmp = s.indexOf("&", left);
}
return left < s.length ? out + s.substring(left) : out;
}
function resolveSSRNode(node, top) {
const t = typeof node;
if (t === "string") return node;
if (node == null || t === "boolean") return "";
if (Array.isArray(node)) {
let prev = {};
let mapped = "";
for (let i = 0, len = node.length; i < len; i++) {
if (!top && typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`;
mapped += resolveSSRNode(prev = node[i]);
}
return mapped;
}
if (t === "object") return node.t;
if (t === "function") return resolveSSRNode(node());
return String(node);
}
function getHydrationKey() {
const hydrate = sharedConfig.context;
return hydrate && !hydrate.noHydrate && sharedConfig.getNextContextId();
}
function useAssets(fn) {
sharedConfig.context.assets.push(() => resolveSSRNode(escape(fn())));
}
function getAssets() {
const assets = sharedConfig.context.assets;
let out = "";
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
return out;
}
function generateHydrationScript({
eventNames = ["click", "input"],
nonce
} = {}) {
return `<script${nonce ? ` nonce="${nonce}"` : ""}>window._$HY||(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('", "')}"].forEach((o=>document.addEventListener(o,(o=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`;
}
function Hydration(props) {
if (!sharedConfig.context.noHydrate) return props.children;
const context = sharedConfig.context;
sharedConfig.context = {
...context,
count: 0,
id: sharedConfig.getNextContextId(),
noHydrate: false
};
const res = props.children;
sharedConfig.context = context;
return res;
}
function NoHydration(props) {
if (sharedConfig.context) sharedConfig.context.noHydrate = true;
return props.children;
}
function queue(fn) {
return Promise.resolve().then(fn);
}
function allSettled(promises) {
let length = promises.length;
return Promise.allSettled(promises).then(() => {
if (promises.length !== length) return allSettled(promises);
return;
});
}
function injectAssets(assets, html) {
if (!assets || !assets.length) return html;
let out = "";
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
const index = html.indexOf("</head>");
if (index === -1) return html;
return html.slice(0, index) + out + html.slice(index);
}
function injectScripts(html, scripts, nonce) {
const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
const index = html.indexOf("<!--xs-->");
if (index > -1) {
return html.slice(0, index) + tag + html.slice(index);
}
return html + tag;
}
function waitForFragments(registry, key) {
for (const k of [...registry.keys()].reverse()) {
if (key.startsWith(k)) return true;
}
return false;
}
function replacePlaceholder(html, key, value) {
const marker = `<template id="pl-${key}">`;
const close = `<!--pl-${key}-->`;
const first = html.indexOf(marker);
if (first === -1) return html;
const last = html.indexOf(close, first + marker.length);
return html.slice(0, first) + value + html.slice(last + close.length);
}
const RequestContext = Symbol();
function getRequestEvent() {
return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.log("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
}
function Assets(props) {
useAssets(() => props.children);
}
function pipeToNodeWritable(code, writable, options = {}) {
if (options.onReady) {
options.onCompleteShell = ({
write
}) => {
options.onReady({
write,
startWriting() {
stream.pipe(writable);
}
});
};
}
const stream = renderToStream(code, options);
if (!options.onReady) stream.pipe(writable);
}
function pipeToWritable(code, writable, options = {}) {
if (options.onReady) {
options.onCompleteShell = ({
write
}) => {
options.onReady({
write,
startWriting() {
stream.pipeTo(writable);
}
});
};
}
const stream = renderToStream(code, options);
if (!options.onReady) stream.pipeTo(writable);
}
function ssrSpread(props, isSVG, skipChildren) {
let result = "";
if (props == null) return result;
if (typeof props === "function") props = props();
const keys = Object.keys(props);
let classResolved;
for (let i = 0; i < keys.length; i++) {
let prop = keys[i];
if (prop === "children") {
!skipChildren && console.warn(`SSR currently does not support spread children.`);
continue;
}
const value = props[prop];
if (prop === "style") {
result += `style="${ssrStyle(value)}"`;
} else if (prop === "class" || prop === "className" || prop === "classList") {
if (classResolved) continue;
let n;
result += `class="${(n = props.class) ? n + " " : ""}${(n = props.className) ? n + " " : ""}${ssrClassList(props.classList)}"`;
classResolved = true;
} else if (prop !== "value" && Properties.has(prop)) {
if (value) result += prop;else continue;
} else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
continue;
} else if (prop.slice(0, 5) === "bool:") {
if (!value) continue;
result += escape(prop.slice(5));
} else if (prop.slice(0, 5) === "attr:") {
result += `${escape(prop.slice(5))}="${escape(value, true)}"`;
} else {
result += `${Aliases[prop] || escape(prop)}="${escape(value, true)}"`;
}
if (i !== keys.length - 1) result += " ";
}
return result;
}
function notSup() {
throw new Error("Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>.");
}
const isServer = true;
const isDev = false;
function createDynamic(component, props) {
const comp = component(),
t = typeof comp;
if (comp) {
if (t === "function") return comp(props);else if (t === "string") {
return ssrElement(comp, props, undefined, true);
}
}
}
function Dynamic(props) {
const [, others] = splitProps(props, ["component"]);
return createDynamic(() => props.component, others);
}
function Portal(props) {
return "";
}
export { Aliases, Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, HydrationScript, NoHydration, Portal, Properties, RequestContext, SVGElements, SVGNamespace, notSup as addEventListener, notSup as assign, notSup as classList, notSup as className, createDynamic, notSup as delegateEvents, notSup as dynamicProperty, escape, generateHydrationScript, getAssets, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getPropAlias, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isServer, memo, pipeToNodeWritable, pipeToWritable, notSup as render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, useAssets };