🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@solidjs/web

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solidjs/web - npm Package Compare versions

Comparing version
2.0.0-beta.16
to
2.0.0-beta.17
+136
-11
dist/dev.cjs

@@ -512,2 +512,97 @@ 'use strict';

}
const ASSET_REMOVAL_GRACE = 100;
const assetRegistry = new Map();
function assetEntryKey(descriptor) {
if (descriptor.policy === "exclusive") return "x|" + descriptor.key;
return descriptor.type === "inline-style" ? "i|" + descriptor.id : descriptor.type + "|" + descriptor.href;
}
function findAssetElement(selector, attr, value) {
const nodes = document.querySelectorAll(selector);
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].getAttribute(attr) === value) return nodes[i];
}
return null;
}
function mountAssetElement(descriptor) {
let el;
if (descriptor.type === "inline-style") {
el = findAssetElement("style[data-asset]", "data-asset", descriptor.id);
if (!el) {
el = document.createElement("style");
el.setAttribute("data-asset", descriptor.id);
el.textContent = descriptor.content || "";
}
} else {
const rel = descriptor.type === "module" ? "modulepreload" : "stylesheet";
el = findAssetElement(`link[rel="${rel}"]`, "href", descriptor.href);
if (!el) {
el = document.createElement("link");
el.rel = rel;
el.href = descriptor.href;
}
}
if (descriptor.attrs) {
for (const name in descriptor.attrs) el.setAttribute(name, descriptor.attrs[name]);
}
if (!el.isConnected) document.head.appendChild(el);
return el;
}
function acquireAsset(descriptor) {
const key = assetEntryKey(descriptor);
let entry = assetRegistry.get(key);
if (descriptor.policy === "exclusive") {
if (!entry) {
entry = {
original: descriptor.get(),
set: descriptor.set,
writers: []
};
assetRegistry.set(key, entry);
}
const writer = {
value: descriptor.value
};
entry.writers.push(writer);
entry.set(writer.value);
let released = false;
return () => {
if (released) return;
released = true;
const index = entry.writers.indexOf(writer);
const wasTop = index === entry.writers.length - 1;
entry.writers.splice(index, 1);
if (!wasTop) return;
if (entry.writers.length) {
entry.set(entry.writers[entry.writers.length - 1].value);
} else {
entry.set(entry.original);
assetRegistry.delete(key);
}
};
}
if (!entry) {
entry = {
count: 0,
element: null,
timer: null
};
assetRegistry.set(key, entry);
}
if (entry.timer) {
clearTimeout(entry.timer);
entry.timer = null;
}
entry.count++;
if (!entry.element || !entry.element.isConnected) entry.element = mountAssetElement(descriptor);
let released = false;
return () => {
if (released) return;
released = true;
if (--entry.count > 0) return;
entry.timer = setTimeout(() => {
assetRegistry.delete(key);
entry.element && entry.element.remove();
}, ASSET_REMOVAL_GRACE);
};
}
function loadModuleAssets(mapping) {

@@ -517,14 +612,14 @@ const hy = globalThis._$HY;

const pending = [];
for (const moduleUrl in mapping) {
if (hy.modules[moduleUrl]) continue;
const entryUrl = mapping[moduleUrl];
if (!hy.loading[moduleUrl]) {
hy.loading[moduleUrl] = import(entryUrl).then(mod => {
hy.modules[moduleUrl] = mod;
for (const key in mapping) {
if (hy.modules[key]) continue;
const entryUrl = mapping[key];
if (!hy.loading[key]) {
hy.loading[key] = import(entryUrl).then(mod => {
hy.modules[key] = mod;
}, err => {
delete hy.loading[moduleUrl];
delete hy.loading[key];
throw err;
});
}
pending.push(hy.loading[moduleUrl]);
pending.push(hy.loading[key]);
}

@@ -868,3 +963,9 @@ return pending.length ? Promise.all(pending).then(() => {}) : undefined;

parent.firstChild.data = value;
} else parent.textContent = value;
} else {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) parent.textContent = value;else {
removeOwnedChildren(parent, current);
parent.insertBefore(document.createTextNode(value), parent.firstChild);
}
}
} else if (value === undefined) {

@@ -892,3 +993,3 @@ cleanChildren(parent, current, marker);

} else {
current && cleanChildren(parent);
current && cleanChildren(parent, current);
appendNodes(parent, value);

@@ -933,4 +1034,27 @@ }

}
function ownedChildCount(current) {
if (Array.isArray(current)) return current.length;
if (current == null) return -1;
if (current === "") return 0;
return 1;
}
function removeOwnedChildren(parent, current) {
if (Array.isArray(current)) {
for (let i = 0; i < current.length; i++) {
const el = current[i];
if (el.parentNode === parent) el.remove();
}
} else if (current.nodeType) {
if (current.parentNode === parent) current.remove();
} else {
const first = parent.firstChild;
if (first && first.nodeType === 3) first.remove();
}
}
function cleanChildren(parent, current, marker, replacement) {
if (marker === undefined) return parent.textContent = "";
if (marker === undefined) {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) return parent.textContent = "";
return removeOwnedChildren(parent, current);
}
if (current.length) {

@@ -1142,2 +1266,3 @@ let inserted = false;

exports.VoidElements = VoidElements;
exports.acquireAsset = acquireAsset;
exports.addEvent = addEvent;

@@ -1144,0 +1269,0 @@ exports.applyRef = applyRef;

@@ -511,2 +511,97 @@ import { createRenderEffect, createMemo, sharedConfig, untrack, runWithOwner, flatten, createRoot, merge, createComponent, omit, getOwner, createEffect, $DEVCOMP, enableHydration, enforceLoadingBoundary, flush } from 'solid-js';

}
const ASSET_REMOVAL_GRACE = 100;
const assetRegistry = new Map();
function assetEntryKey(descriptor) {
if (descriptor.policy === "exclusive") return "x|" + descriptor.key;
return descriptor.type === "inline-style" ? "i|" + descriptor.id : descriptor.type + "|" + descriptor.href;
}
function findAssetElement(selector, attr, value) {
const nodes = document.querySelectorAll(selector);
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].getAttribute(attr) === value) return nodes[i];
}
return null;
}
function mountAssetElement(descriptor) {
let el;
if (descriptor.type === "inline-style") {
el = findAssetElement("style[data-asset]", "data-asset", descriptor.id);
if (!el) {
el = document.createElement("style");
el.setAttribute("data-asset", descriptor.id);
el.textContent = descriptor.content || "";
}
} else {
const rel = descriptor.type === "module" ? "modulepreload" : "stylesheet";
el = findAssetElement(`link[rel="${rel}"]`, "href", descriptor.href);
if (!el) {
el = document.createElement("link");
el.rel = rel;
el.href = descriptor.href;
}
}
if (descriptor.attrs) {
for (const name in descriptor.attrs) el.setAttribute(name, descriptor.attrs[name]);
}
if (!el.isConnected) document.head.appendChild(el);
return el;
}
function acquireAsset(descriptor) {
const key = assetEntryKey(descriptor);
let entry = assetRegistry.get(key);
if (descriptor.policy === "exclusive") {
if (!entry) {
entry = {
original: descriptor.get(),
set: descriptor.set,
writers: []
};
assetRegistry.set(key, entry);
}
const writer = {
value: descriptor.value
};
entry.writers.push(writer);
entry.set(writer.value);
let released = false;
return () => {
if (released) return;
released = true;
const index = entry.writers.indexOf(writer);
const wasTop = index === entry.writers.length - 1;
entry.writers.splice(index, 1);
if (!wasTop) return;
if (entry.writers.length) {
entry.set(entry.writers[entry.writers.length - 1].value);
} else {
entry.set(entry.original);
assetRegistry.delete(key);
}
};
}
if (!entry) {
entry = {
count: 0,
element: null,
timer: null
};
assetRegistry.set(key, entry);
}
if (entry.timer) {
clearTimeout(entry.timer);
entry.timer = null;
}
entry.count++;
if (!entry.element || !entry.element.isConnected) entry.element = mountAssetElement(descriptor);
let released = false;
return () => {
if (released) return;
released = true;
if (--entry.count > 0) return;
entry.timer = setTimeout(() => {
assetRegistry.delete(key);
entry.element && entry.element.remove();
}, ASSET_REMOVAL_GRACE);
};
}
function loadModuleAssets(mapping) {

@@ -516,14 +611,14 @@ const hy = globalThis._$HY;

const pending = [];
for (const moduleUrl in mapping) {
if (hy.modules[moduleUrl]) continue;
const entryUrl = mapping[moduleUrl];
if (!hy.loading[moduleUrl]) {
hy.loading[moduleUrl] = import(entryUrl).then(mod => {
hy.modules[moduleUrl] = mod;
for (const key in mapping) {
if (hy.modules[key]) continue;
const entryUrl = mapping[key];
if (!hy.loading[key]) {
hy.loading[key] = import(entryUrl).then(mod => {
hy.modules[key] = mod;
}, err => {
delete hy.loading[moduleUrl];
delete hy.loading[key];
throw err;
});
}
pending.push(hy.loading[moduleUrl]);
pending.push(hy.loading[key]);
}

@@ -867,3 +962,9 @@ return pending.length ? Promise.all(pending).then(() => {}) : undefined;

parent.firstChild.data = value;
} else parent.textContent = value;
} else {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) parent.textContent = value;else {
removeOwnedChildren(parent, current);
parent.insertBefore(document.createTextNode(value), parent.firstChild);
}
}
} else if (value === undefined) {

@@ -891,3 +992,3 @@ cleanChildren(parent, current, marker);

} else {
current && cleanChildren(parent);
current && cleanChildren(parent, current);
appendNodes(parent, value);

@@ -932,4 +1033,27 @@ }

}
function ownedChildCount(current) {
if (Array.isArray(current)) return current.length;
if (current == null) return -1;
if (current === "") return 0;
return 1;
}
function removeOwnedChildren(parent, current) {
if (Array.isArray(current)) {
for (let i = 0; i < current.length; i++) {
const el = current[i];
if (el.parentNode === parent) el.remove();
}
} else if (current.nodeType) {
if (current.parentNode === parent) current.remove();
} else {
const first = parent.firstChild;
if (first && first.nodeType === 3) first.remove();
}
}
function cleanChildren(parent, current, marker, replacement) {
if (marker === undefined) return parent.textContent = "";
if (marker === undefined) {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) return parent.textContent = "";
return removeOwnedChildren(parent, current);
}
if (current.length) {

@@ -1075,2 +1199,2 @@ let inserted = false;

export { voidFn as Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, voidFn as HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, addEvent, applyRef, assign, className, delegateEvents, dynamic, dynamicProperty, effect, escape, voidFn as generateHydrationScript, voidFn as getAssets, getDelegatedRoot, getFirstChild, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getNextSibling, voidFn as getRequestEvent, hydrate, insert, isDev, isServer, memo, mergeProps, ref, registerDelegatedContainer, registerDelegatedRoot, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, scope, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrStyle, style, template, unregisterDelegatedContainer, unregisterDelegatedRoot, voidFn as useAssets };
export { voidFn as Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, voidFn as HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, acquireAsset, addEvent, applyRef, assign, className, delegateEvents, dynamic, dynamicProperty, effect, escape, voidFn as generateHydrationScript, voidFn as getAssets, getDelegatedRoot, getFirstChild, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getNextSibling, voidFn as getRequestEvent, hydrate, insert, isDev, isServer, memo, mergeProps, ref, registerDelegatedContainer, registerDelegatedRoot, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, scope, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrStyle, style, template, unregisterDelegatedContainer, unregisterDelegatedRoot, voidFn as useAssets };

@@ -144,2 +144,3 @@ 'use strict';

const emittedAssets = new Set();
const inlineStyles = new Map();
let currentBoundaryId = null;

@@ -150,2 +151,24 @@ return {

emittedAssets,
inlineStyles,
registerInlineStyle(desc) {
let entry = inlineStyles.get(desc.id);
if (!entry) {
entry = {
id: desc.id,
content: desc.content || "",
attrs: desc.attrs,
emitted: false
};
inlineStyles.set(desc.id, entry);
}
if (currentBoundaryId) {
let styles = boundaryStyles.get(currentBoundaryId);
if (!styles) {
styles = new Set();
boundaryStyles.set(currentBoundaryId, styles);
}
styles.add(entry);
}
return entry;
},
get currentBoundaryId() {

@@ -157,3 +180,3 @@ return currentBoundaryId;

},
registerModule(moduleUrl, entryUrl) {
registerModule(key, entryUrl) {
const id = currentBoundaryId || "";

@@ -165,3 +188,3 @@ let map = boundaryModules.get(id);

}
map[moduleUrl] = entryUrl;
map[key] = entryUrl;
},

@@ -227,3 +250,7 @@ getBoundaryModules(id) {

},
registerAsset(type, url) {
registerAsset(type, value) {
if (type === "inline-style") {
tracking.registerInlineStyle(value);
return;
}
if (tracking.currentBoundaryId && type === "style") {

@@ -235,5 +262,5 @@ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);

}
styles.add(url);
styles.add(value);
}
tracking.emittedAssets.add(url);
tracking.emittedAssets.add(value);
}

@@ -254,2 +281,3 @@ };

html = injectPreloadLinks(tracking.emittedAssets, html);
html = injectInlineStyles(tracking.inlineStyles, html, nonce);
if (scripts.length) html = injectScripts(html, scripts, options.nonce);

@@ -365,3 +393,11 @@ return html;

nonce,
registerAsset(type, url) {
registerAsset(type, value) {
if (type === "inline-style") {
const entry = tracking.registerInlineStyle(value);
if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
entry.emitted = true;
buffer.write(renderInlineStyle(entry, nonce));
}
return;
}
if (tracking.currentBoundaryId && type === "style") {

@@ -373,8 +409,8 @@ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);

}
styles.add(url);
styles.add(value);
}
if (!tracking.emittedAssets.has(url)) {
tracking.emittedAssets.add(url);
if (!tracking.emittedAssets.has(value)) {
tracking.emittedAssets.add(value);
if (firstFlushed && type === "module") {
buffer.write(`<link rel="modulepreload" href="${url}">`);
buffer.write(`<link rel="modulepreload" href="${value}">`);
}

@@ -463,6 +499,9 @@ }

const deferActivation = !!revealGroup;
if (styles.length) {
emitTask(`$dfs("${key}",${styles.length},${deferActivation ? 1 : 0})`);
for (let i = 0; i < styles.inline.length; i++) {
buffer.write(renderInlineStyle(styles.inline[i], nonce));
}
if (styles.links.length) {
emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
writeTasks();
for (const url of styles) {
for (const url of styles.links) {
buffer.write(`<link rel="stylesheet" href="${url}" onload="$dfc('${key}')" onerror="$dfc('${key}')">`);

@@ -558,2 +597,3 @@ }

html = injectPreloadLinks(tracking.emittedAssets, html);
html = injectInlineStyles(tracking.inlineStyles, html, nonce);
serializeRootAssets();

@@ -864,6 +904,7 @@ if (tasks.length) html = injectScripts(html, tasks, nonce);

function ssrElement(tag, props, children, needsId) {
const hk = needsId ? ssrHydrationKey() : "";
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 result = `<${tag}${hk} `;
for (let i = 0; i < keys.length; i++) {

@@ -913,3 +954,6 @@ const prop = keys[i];

}
if (attr && t === "boolean") return s;
if (attr) {
if (s == null || t === "boolean" || t === "number") return s;
return escape(String(s), attr);
}
return s;

@@ -1050,11 +1094,45 @@ }

const styles = tracking.getBoundaryStyles(key);
if (!styles) return [];
const result = [];
for (const url of styles) {
if (!headStyles || !headStyles.has(url)) {
result.push(url);
const links = [];
const inline = [];
if (!styles) return {
links,
inline
};
for (const entry of styles) {
if (typeof entry === "string") {
if (!headStyles || !headStyles.has(entry)) links.push(entry);
} else if (!entry.emitted) {
entry.emitted = true;
inline.push(entry);
}
}
return result;
return {
links,
inline
};
}
function escapeStyleContent(content) {
return content.replace(/<\/(style)/gi, "<\\/$1");
}
function renderInlineStyle(entry, nonce) {
let attrs = "";
if (entry.attrs) {
for (const name in entry.attrs) {
attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
}
}
return `<style${nonce ? ` nonce="${nonce}"` : ""} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
}
function injectInlineStyles(inlineStyles, html, nonce) {
if (!inlineStyles.size) return html;
const index = html.indexOf("</head>");
if (index === -1) return html;
let out = "";
for (const entry of inlineStyles.values()) {
if (entry.emitted) continue;
entry.emitted = true;
out += renderInlineStyle(entry, nonce);
}
return out ? html.slice(0, index) + out + html.slice(index) : html;
}
function injectScripts(html, scripts, nonce) {

@@ -1321,2 +1399,3 @@ const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;

exports.VoidElements = VoidElements;
exports.acquireAsset = notSup;
exports.addEvent = notSup;

@@ -1323,0 +1402,0 @@ exports.applyRef = applyRef;

@@ -143,2 +143,3 @@ import { createRenderEffect, createMemo, sharedConfig, createRoot, ssrHandleError, getOwner, runWithOwner, createComponent, omit, getNextChildId, NotReadyError } from 'solid-js';

const emittedAssets = new Set();
const inlineStyles = new Map();
let currentBoundaryId = null;

@@ -149,2 +150,24 @@ return {

emittedAssets,
inlineStyles,
registerInlineStyle(desc) {
let entry = inlineStyles.get(desc.id);
if (!entry) {
entry = {
id: desc.id,
content: desc.content || "",
attrs: desc.attrs,
emitted: false
};
inlineStyles.set(desc.id, entry);
}
if (currentBoundaryId) {
let styles = boundaryStyles.get(currentBoundaryId);
if (!styles) {
styles = new Set();
boundaryStyles.set(currentBoundaryId, styles);
}
styles.add(entry);
}
return entry;
},
get currentBoundaryId() {

@@ -156,3 +179,3 @@ return currentBoundaryId;

},
registerModule(moduleUrl, entryUrl) {
registerModule(key, entryUrl) {
const id = currentBoundaryId || "";

@@ -164,3 +187,3 @@ let map = boundaryModules.get(id);

}
map[moduleUrl] = entryUrl;
map[key] = entryUrl;
},

@@ -226,3 +249,7 @@ getBoundaryModules(id) {

},
registerAsset(type, url) {
registerAsset(type, value) {
if (type === "inline-style") {
tracking.registerInlineStyle(value);
return;
}
if (tracking.currentBoundaryId && type === "style") {

@@ -234,5 +261,5 @@ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);

}
styles.add(url);
styles.add(value);
}
tracking.emittedAssets.add(url);
tracking.emittedAssets.add(value);
}

@@ -253,2 +280,3 @@ };

html = injectPreloadLinks(tracking.emittedAssets, html);
html = injectInlineStyles(tracking.inlineStyles, html, nonce);
if (scripts.length) html = injectScripts(html, scripts, options.nonce);

@@ -364,3 +392,11 @@ return html;

nonce,
registerAsset(type, url) {
registerAsset(type, value) {
if (type === "inline-style") {
const entry = tracking.registerInlineStyle(value);
if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
entry.emitted = true;
buffer.write(renderInlineStyle(entry, nonce));
}
return;
}
if (tracking.currentBoundaryId && type === "style") {

@@ -372,8 +408,8 @@ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);

}
styles.add(url);
styles.add(value);
}
if (!tracking.emittedAssets.has(url)) {
tracking.emittedAssets.add(url);
if (!tracking.emittedAssets.has(value)) {
tracking.emittedAssets.add(value);
if (firstFlushed && type === "module") {
buffer.write(`<link rel="modulepreload" href="${url}">`);
buffer.write(`<link rel="modulepreload" href="${value}">`);
}

@@ -462,6 +498,9 @@ }

const deferActivation = !!revealGroup;
if (styles.length) {
emitTask(`$dfs("${key}",${styles.length},${deferActivation ? 1 : 0})`);
for (let i = 0; i < styles.inline.length; i++) {
buffer.write(renderInlineStyle(styles.inline[i], nonce));
}
if (styles.links.length) {
emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
writeTasks();
for (const url of styles) {
for (const url of styles.links) {
buffer.write(`<link rel="stylesheet" href="${url}" onload="$dfc('${key}')" onerror="$dfc('${key}')">`);

@@ -557,2 +596,3 @@ }

html = injectPreloadLinks(tracking.emittedAssets, html);
html = injectInlineStyles(tracking.inlineStyles, html, nonce);
serializeRootAssets();

@@ -863,6 +903,7 @@ if (tasks.length) html = injectScripts(html, tasks, nonce);

function ssrElement(tag, props, children, needsId) {
const hk = needsId ? ssrHydrationKey() : "";
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 result = `<${tag}${hk} `;
for (let i = 0; i < keys.length; i++) {

@@ -912,3 +953,6 @@ const prop = keys[i];

}
if (attr && t === "boolean") return s;
if (attr) {
if (s == null || t === "boolean" || t === "number") return s;
return escape(String(s), attr);
}
return s;

@@ -1049,11 +1093,45 @@ }

const styles = tracking.getBoundaryStyles(key);
if (!styles) return [];
const result = [];
for (const url of styles) {
if (!headStyles || !headStyles.has(url)) {
result.push(url);
const links = [];
const inline = [];
if (!styles) return {
links,
inline
};
for (const entry of styles) {
if (typeof entry === "string") {
if (!headStyles || !headStyles.has(entry)) links.push(entry);
} else if (!entry.emitted) {
entry.emitted = true;
inline.push(entry);
}
}
return result;
return {
links,
inline
};
}
function escapeStyleContent(content) {
return content.replace(/<\/(style)/gi, "<\\/$1");
}
function renderInlineStyle(entry, nonce) {
let attrs = "";
if (entry.attrs) {
for (const name in entry.attrs) {
attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
}
}
return `<style${nonce ? ` nonce="${nonce}"` : ""} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
}
function injectInlineStyles(inlineStyles, html, nonce) {
if (!inlineStyles.size) return html;
const index = html.indexOf("</head>");
if (index === -1) return html;
let out = "";
for (const entry of inlineStyles.values()) {
if (entry.emitted) continue;
entry.emitted = true;
out += renderInlineStyle(entry, nonce);
}
return out ? html.slice(0, index) + out + html.slice(index) : html;
}
function injectScripts(html, scripts, nonce) {

@@ -1246,2 +1324,2 @@ const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;

export { Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, notSup as addEvent, applyRef, notSup as assign, notSup as className, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, getAssets, notSup as getDelegatedRoot, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isServer, memo, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, notSup as render, renderToStream, renderToString, renderToStringAsync, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useAssets };
export { Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, notSup as acquireAsset, notSup as addEvent, applyRef, notSup as assign, notSup as className, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, getAssets, notSup as getDelegatedRoot, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isServer, memo, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, notSup as render, renderToStream, renderToString, renderToStringAsync, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useAssets };

@@ -507,2 +507,97 @@ 'use strict';

}
const ASSET_REMOVAL_GRACE = 100;
const assetRegistry = new Map();
function assetEntryKey(descriptor) {
if (descriptor.policy === "exclusive") return "x|" + descriptor.key;
return descriptor.type === "inline-style" ? "i|" + descriptor.id : descriptor.type + "|" + descriptor.href;
}
function findAssetElement(selector, attr, value) {
const nodes = document.querySelectorAll(selector);
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].getAttribute(attr) === value) return nodes[i];
}
return null;
}
function mountAssetElement(descriptor) {
let el;
if (descriptor.type === "inline-style") {
el = findAssetElement("style[data-asset]", "data-asset", descriptor.id);
if (!el) {
el = document.createElement("style");
el.setAttribute("data-asset", descriptor.id);
el.textContent = descriptor.content || "";
}
} else {
const rel = descriptor.type === "module" ? "modulepreload" : "stylesheet";
el = findAssetElement(`link[rel="${rel}"]`, "href", descriptor.href);
if (!el) {
el = document.createElement("link");
el.rel = rel;
el.href = descriptor.href;
}
}
if (descriptor.attrs) {
for (const name in descriptor.attrs) el.setAttribute(name, descriptor.attrs[name]);
}
if (!el.isConnected) document.head.appendChild(el);
return el;
}
function acquireAsset(descriptor) {
const key = assetEntryKey(descriptor);
let entry = assetRegistry.get(key);
if (descriptor.policy === "exclusive") {
if (!entry) {
entry = {
original: descriptor.get(),
set: descriptor.set,
writers: []
};
assetRegistry.set(key, entry);
}
const writer = {
value: descriptor.value
};
entry.writers.push(writer);
entry.set(writer.value);
let released = false;
return () => {
if (released) return;
released = true;
const index = entry.writers.indexOf(writer);
const wasTop = index === entry.writers.length - 1;
entry.writers.splice(index, 1);
if (!wasTop) return;
if (entry.writers.length) {
entry.set(entry.writers[entry.writers.length - 1].value);
} else {
entry.set(entry.original);
assetRegistry.delete(key);
}
};
}
if (!entry) {
entry = {
count: 0,
element: null,
timer: null
};
assetRegistry.set(key, entry);
}
if (entry.timer) {
clearTimeout(entry.timer);
entry.timer = null;
}
entry.count++;
if (!entry.element || !entry.element.isConnected) entry.element = mountAssetElement(descriptor);
let released = false;
return () => {
if (released) return;
released = true;
if (--entry.count > 0) return;
entry.timer = setTimeout(() => {
assetRegistry.delete(key);
entry.element && entry.element.remove();
}, ASSET_REMOVAL_GRACE);
};
}
function loadModuleAssets(mapping) {

@@ -512,14 +607,14 @@ const hy = globalThis._$HY;

const pending = [];
for (const moduleUrl in mapping) {
if (hy.modules[moduleUrl]) continue;
const entryUrl = mapping[moduleUrl];
if (!hy.loading[moduleUrl]) {
hy.loading[moduleUrl] = import(entryUrl).then(mod => {
hy.modules[moduleUrl] = mod;
for (const key in mapping) {
if (hy.modules[key]) continue;
const entryUrl = mapping[key];
if (!hy.loading[key]) {
hy.loading[key] = import(entryUrl).then(mod => {
hy.modules[key] = mod;
}, err => {
delete hy.loading[moduleUrl];
delete hy.loading[key];
throw err;
});
}
pending.push(hy.loading[moduleUrl]);
pending.push(hy.loading[key]);
}

@@ -811,3 +906,9 @@ return pending.length ? Promise.all(pending).then(() => {}) : undefined;

parent.firstChild.data = value;
} else parent.textContent = value;
} else {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) parent.textContent = value;else {
removeOwnedChildren(parent, current);
parent.insertBefore(document.createTextNode(value), parent.firstChild);
}
}
} else if (value === undefined) {

@@ -835,3 +936,3 @@ cleanChildren(parent, current, marker);

} else {
current && cleanChildren(parent);
current && cleanChildren(parent, current);
appendNodes(parent, value);

@@ -876,4 +977,27 @@ }

}
function ownedChildCount(current) {
if (Array.isArray(current)) return current.length;
if (current == null) return -1;
if (current === "") return 0;
return 1;
}
function removeOwnedChildren(parent, current) {
if (Array.isArray(current)) {
for (let i = 0; i < current.length; i++) {
const el = current[i];
if (el.parentNode === parent) el.remove();
}
} else if (current.nodeType) {
if (current.parentNode === parent) current.remove();
} else {
const first = parent.firstChild;
if (first && first.nodeType === 3) first.remove();
}
}
function cleanChildren(parent, current, marker, replacement) {
if (marker === undefined) return parent.textContent = "";
if (marker === undefined) {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) return parent.textContent = "";
return removeOwnedChildren(parent, current);
}
if (current.length) {

@@ -1080,2 +1204,3 @@ let inserted = false;

exports.VoidElements = VoidElements;
exports.acquireAsset = acquireAsset;
exports.addEvent = addEvent;

@@ -1082,0 +1207,0 @@ exports.applyRef = applyRef;

@@ -506,2 +506,97 @@ import { createRenderEffect, createMemo, sharedConfig, untrack, runWithOwner, flatten, createRoot, merge, createComponent, omit, getOwner, createEffect, enableHydration, flush } from 'solid-js';

}
const ASSET_REMOVAL_GRACE = 100;
const assetRegistry = new Map();
function assetEntryKey(descriptor) {
if (descriptor.policy === "exclusive") return "x|" + descriptor.key;
return descriptor.type === "inline-style" ? "i|" + descriptor.id : descriptor.type + "|" + descriptor.href;
}
function findAssetElement(selector, attr, value) {
const nodes = document.querySelectorAll(selector);
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].getAttribute(attr) === value) return nodes[i];
}
return null;
}
function mountAssetElement(descriptor) {
let el;
if (descriptor.type === "inline-style") {
el = findAssetElement("style[data-asset]", "data-asset", descriptor.id);
if (!el) {
el = document.createElement("style");
el.setAttribute("data-asset", descriptor.id);
el.textContent = descriptor.content || "";
}
} else {
const rel = descriptor.type === "module" ? "modulepreload" : "stylesheet";
el = findAssetElement(`link[rel="${rel}"]`, "href", descriptor.href);
if (!el) {
el = document.createElement("link");
el.rel = rel;
el.href = descriptor.href;
}
}
if (descriptor.attrs) {
for (const name in descriptor.attrs) el.setAttribute(name, descriptor.attrs[name]);
}
if (!el.isConnected) document.head.appendChild(el);
return el;
}
function acquireAsset(descriptor) {
const key = assetEntryKey(descriptor);
let entry = assetRegistry.get(key);
if (descriptor.policy === "exclusive") {
if (!entry) {
entry = {
original: descriptor.get(),
set: descriptor.set,
writers: []
};
assetRegistry.set(key, entry);
}
const writer = {
value: descriptor.value
};
entry.writers.push(writer);
entry.set(writer.value);
let released = false;
return () => {
if (released) return;
released = true;
const index = entry.writers.indexOf(writer);
const wasTop = index === entry.writers.length - 1;
entry.writers.splice(index, 1);
if (!wasTop) return;
if (entry.writers.length) {
entry.set(entry.writers[entry.writers.length - 1].value);
} else {
entry.set(entry.original);
assetRegistry.delete(key);
}
};
}
if (!entry) {
entry = {
count: 0,
element: null,
timer: null
};
assetRegistry.set(key, entry);
}
if (entry.timer) {
clearTimeout(entry.timer);
entry.timer = null;
}
entry.count++;
if (!entry.element || !entry.element.isConnected) entry.element = mountAssetElement(descriptor);
let released = false;
return () => {
if (released) return;
released = true;
if (--entry.count > 0) return;
entry.timer = setTimeout(() => {
assetRegistry.delete(key);
entry.element && entry.element.remove();
}, ASSET_REMOVAL_GRACE);
};
}
function loadModuleAssets(mapping) {

@@ -511,14 +606,14 @@ const hy = globalThis._$HY;

const pending = [];
for (const moduleUrl in mapping) {
if (hy.modules[moduleUrl]) continue;
const entryUrl = mapping[moduleUrl];
if (!hy.loading[moduleUrl]) {
hy.loading[moduleUrl] = import(entryUrl).then(mod => {
hy.modules[moduleUrl] = mod;
for (const key in mapping) {
if (hy.modules[key]) continue;
const entryUrl = mapping[key];
if (!hy.loading[key]) {
hy.loading[key] = import(entryUrl).then(mod => {
hy.modules[key] = mod;
}, err => {
delete hy.loading[moduleUrl];
delete hy.loading[key];
throw err;
});
}
pending.push(hy.loading[moduleUrl]);
pending.push(hy.loading[key]);
}

@@ -810,3 +905,9 @@ return pending.length ? Promise.all(pending).then(() => {}) : undefined;

parent.firstChild.data = value;
} else parent.textContent = value;
} else {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) parent.textContent = value;else {
removeOwnedChildren(parent, current);
parent.insertBefore(document.createTextNode(value), parent.firstChild);
}
}
} else if (value === undefined) {

@@ -834,3 +935,3 @@ cleanChildren(parent, current, marker);

} else {
current && cleanChildren(parent);
current && cleanChildren(parent, current);
appendNodes(parent, value);

@@ -875,4 +976,27 @@ }

}
function ownedChildCount(current) {
if (Array.isArray(current)) return current.length;
if (current == null) return -1;
if (current === "") return 0;
return 1;
}
function removeOwnedChildren(parent, current) {
if (Array.isArray(current)) {
for (let i = 0; i < current.length; i++) {
const el = current[i];
if (el.parentNode === parent) el.remove();
}
} else if (current.nodeType) {
if (current.parentNode === parent) current.remove();
} else {
const first = parent.firstChild;
if (first && first.nodeType === 3) first.remove();
}
}
function cleanChildren(parent, current, marker, replacement) {
if (marker === undefined) return parent.textContent = "";
if (marker === undefined) {
const owned = ownedChildCount(current);
if (owned === -1 || owned === parent.childNodes.length) return parent.textContent = "";
return removeOwnedChildren(parent, current);
}
if (current.length) {

@@ -1013,2 +1137,2 @@ let inserted = false;

export { voidFn as Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, voidFn as HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, addEvent, applyRef, assign, className, delegateEvents, dynamic, dynamicProperty, effect, escape, voidFn as generateHydrationScript, voidFn as getAssets, getDelegatedRoot, getFirstChild, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getNextSibling, voidFn as getRequestEvent, hydrate, insert, isDev, isServer, memo, mergeProps, ref, registerDelegatedContainer, registerDelegatedRoot, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, scope, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrStyle, style, template, unregisterDelegatedContainer, unregisterDelegatedRoot, voidFn as useAssets };
export { voidFn as Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, voidFn as HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, acquireAsset, addEvent, applyRef, assign, className, delegateEvents, dynamic, dynamicProperty, effect, escape, voidFn as generateHydrationScript, voidFn as getAssets, getDelegatedRoot, getFirstChild, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getNextSibling, voidFn as getRequestEvent, hydrate, insert, isDev, isServer, memo, mergeProps, ref, registerDelegatedContainer, registerDelegatedRoot, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, scope, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrStyle, style, template, unregisterDelegatedContainer, unregisterDelegatedRoot, voidFn as useAssets };
+3
-3
{
"name": "@solidjs/web",
"description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
"version": "2.0.0-beta.16",
"version": "2.0.0-beta.17",
"author": "Ryan Carniato",

@@ -140,6 +140,6 @@ "license": "MIT",

"peerDependencies": {
"solid-js": "^2.0.0-beta.16"
"solid-js": "^2.0.0-beta.17"
},
"devDependencies": {
"solid-js": "2.0.0-beta.16"
"solid-js": "2.0.0-beta.17"
},

@@ -146,0 +146,0 @@ "scripts": {

@@ -106,2 +106,15 @@ import { JSX } from "./jsx.cjs";

export function getAssets(): string;
export type AssetDescriptor =
| { type: "style"; href: string; attrs?: Record<string, string> }
| { type: "inline-style"; id: string; content?: string; attrs?: Record<string, string> }
| { type: "module"; href: string }
| ExclusiveAssetDescriptor<any>;
export interface ExclusiveAssetDescriptor<T> {
policy: "exclusive";
key: string;
value: T;
get(): T;
set(value: T): void;
}
export function acquireAsset(descriptor: AssetDescriptor): () => void;
export function HydrationScript(props?: { nonce?: string; eventNames?: string[] }): JSX.Element;

@@ -108,0 +121,0 @@ export function generateHydrationScript(options?: {

@@ -195,1 +195,3 @@ import { JSX } from "./jsx.cjs";

export function setStyleProperty(node: Element, name: string, value: any): void;
/** @deprecated not supported on the server side — register assets through the render context instead */
export function acquireAsset(descriptor: unknown): () => void;

@@ -106,2 +106,15 @@ import { JSX } from "./jsx.js";

export function getAssets(): string;
export type AssetDescriptor =
| { type: "style"; href: string; attrs?: Record<string, string> }
| { type: "inline-style"; id: string; content?: string; attrs?: Record<string, string> }
| { type: "module"; href: string }
| ExclusiveAssetDescriptor<any>;
export interface ExclusiveAssetDescriptor<T> {
policy: "exclusive";
key: string;
value: T;
get(): T;
set(value: T): void;
}
export function acquireAsset(descriptor: AssetDescriptor): () => void;
export function HydrationScript(props?: { nonce?: string; eventNames?: string[] }): JSX.Element;

@@ -108,0 +121,0 @@ export function generateHydrationScript(options?: {

@@ -195,1 +195,3 @@ import { JSX } from "./jsx.js";

export function setStyleProperty(node: Element, name: string, value: any): void;
/** @deprecated not supported on the server side — register assets through the render context instead */
export function acquireAsset(descriptor: unknown): () => void;
import type { RequestEvent } from "@solidjs/web";
export declare function provideRequestEvent<T extends RequestEvent, U>(init: T, cb: () => U): U;
import type { ArrayElement as SolidArrayElement, Element as SolidElement } from "solid-js";
import type { JSX as DOMJSX } from "dom-expressions/src/jsx.js";
export declare namespace JSX {
type WithSolidChildren<T> = Omit<T, "children"> & {
children?: Element;
};
export type Element = SolidElement;
export interface ArrayElement extends SolidArrayElement {
}
export interface ElementClass extends DOMJSX.ElementClass {
}
export interface ElementAttributesProperty extends DOMJSX.ElementAttributesProperty {
}
export interface ElementChildrenAttribute extends DOMJSX.ElementChildrenAttribute {
}
export interface IntrinsicAttributes extends DOMJSX.IntrinsicAttributes {
}
export type IntrinsicElements = {
[K in keyof DOMJSX.IntrinsicElements]: WithSolidChildren<DOMJSX.IntrinsicElements[K]>;
};
export type HTMLAttributes<T> = WithSolidChildren<DOMJSX.HTMLAttributes<T>>;
export type SVGAttributes<T> = WithSolidChildren<DOMJSX.SVGAttributes<T>>;
export type MathMLAttributes<T> = WithSolidChildren<DOMJSX.MathMLAttributes<T>>;
export interface CustomEvents extends DOMJSX.CustomEvents {
}
export type EventHandler<T, E extends Event> = DOMJSX.EventHandler<T, E>;
export type EventHandlerUnion<T, E extends Event> = DOMJSX.EventHandlerUnion<T, E>;
export {};
}
import type { RequestEvent } from "@solidjs/web";
export declare function provideRequestEvent<T extends RequestEvent, U>(init: T, cb: () => U): U;
import type { ArrayElement as SolidArrayElement, Element as SolidElement } from "solid-js";
import type { JSX as DOMJSX } from "dom-expressions/src/jsx.js";
export declare namespace JSX {
type WithSolidChildren<T> = Omit<T, "children"> & {
children?: Element;
};
export type Element = SolidElement;
export interface ArrayElement extends SolidArrayElement {
}
export interface ElementClass extends DOMJSX.ElementClass {
}
export interface ElementAttributesProperty extends DOMJSX.ElementAttributesProperty {
}
export interface ElementChildrenAttribute extends DOMJSX.ElementChildrenAttribute {
}
export interface IntrinsicAttributes extends DOMJSX.IntrinsicAttributes {
}
export type IntrinsicElements = {
[K in keyof DOMJSX.IntrinsicElements]: WithSolidChildren<DOMJSX.IntrinsicElements[K]>;
};
export type HTMLAttributes<T> = WithSolidChildren<DOMJSX.HTMLAttributes<T>>;
export type SVGAttributes<T> = WithSolidChildren<DOMJSX.SVGAttributes<T>>;
export type MathMLAttributes<T> = WithSolidChildren<DOMJSX.MathMLAttributes<T>>;
export interface CustomEvents extends DOMJSX.CustomEvents {
}
export type EventHandler<T, E extends Event> = DOMJSX.EventHandler<T, E>;
export type EventHandlerUnion<T, E extends Event> = DOMJSX.EventHandlerUnion<T, E>;
export {};
}